diff options
author | Dave Arter <davea@mysociety.org> | 2016-10-18 15:35:44 +0100 |
---|---|---|
committer | Dave Arter <davea@mysociety.org> | 2016-10-19 14:45:41 +0100 |
commit | 255d42b042d06c2a4da39e1a1a73c331862a1c62 (patch) | |
tree | d71e979fdf7b8b43f57565588fbc51cebb9f65c5 | |
parent | 58684be7a9b8fec8c90e6f94ecea0c21c3ae5e59 (diff) |
Refactor template/priority category checkboxes into own template
- Also adds add select all/none UI
- Adds admin hint for empty category list behaviour
-rw-r--r-- | templates/web/base/admin/category-checkboxes.html | 18 | ||||
-rw-r--r-- | templates/web/base/admin/responsepriorities/edit.html | 21 | ||||
-rw-r--r-- | templates/web/base/admin/template_edit.html | 21 | ||||
-rw-r--r-- | web/js/fixmystreet-admin.js | 7 |
4 files changed, 41 insertions, 26 deletions
diff --git a/templates/web/base/admin/category-checkboxes.html b/templates/web/base/admin/category-checkboxes.html new file mode 100644 index 000000000..63acd4112 --- /dev/null +++ b/templates/web/base/admin/category-checkboxes.html @@ -0,0 +1,18 @@ + <p> + <strong>[% loc('Categories:') %]</strong> + </p> + <ul> + <li> + [% loc('Select:') %] + <a href="#" data-select-all>[% loc('all') %]</a> / + <a href="#" data-select-none>[% loc('none') %]</a> + </li> + [% FOR contact IN contacts %] + <li> + <label> + <input type="checkbox" name="contacts[[% contact.id %]]" [% 'checked' IF contact.active %]/> + [% contact.category %] + </label> + </li> + [% END %] + </ul> diff --git a/templates/web/base/admin/responsepriorities/edit.html b/templates/web/base/admin/responsepriorities/edit.html index 93b050a20..4d838eed2 100644 --- a/templates/web/base/admin/responsepriorities/edit.html +++ b/templates/web/base/admin/responsepriorities/edit.html @@ -17,19 +17,14 @@ <strong>[% loc('Description:') %] </strong> <input type="text" name="description" class="form-control" size="30" value="[% rp.description | html %]"> </p> - <p> - <strong>[% loc('Categories:') %]</strong> - <ul> - [% FOR contact IN contacts %] - <li> - <label> - <input type="checkbox" name="contacts[[% contact.id %]]" [% 'checked' IF contact.active %]/> - [% contact.category %] - </label> - </li> - [% END %] - </ul> - </p> + + <div class="admin-hint"> + <p> + [% loc('If you only want this priority to be an option for specific categories, pick them here. By default they will show for all categories.') %] + </p> + </div> + [% INCLUDE 'admin/category-checkboxes.html' %] + <p> <label> <input type="checkbox" name="deleted" id="deleted" value="1"[% ' checked' IF rp.deleted %]> diff --git a/templates/web/base/admin/template_edit.html b/templates/web/base/admin/template_edit.html index 8ce3c28dd..b2e734756 100644 --- a/templates/web/base/admin/template_edit.html +++ b/templates/web/base/admin/template_edit.html @@ -23,19 +23,14 @@ <input type="checkbox" name="auto_response" [% 'checked' IF rt.auto_response %] /> </label> </p> - <p> - <strong>[% loc('Categories:') %]</strong> - <ul> - [% FOR contact IN contacts %] - <li> - <label> - <input type="checkbox" name="contacts[[% contact.id %]]" [% 'checked' IF contact.active %]/> - [% contact.category %] - </label> - </li> - [% END %] - </ul> - </p> + + <div class="admin-hint"> + <p> + [% loc('If you only want this template to be an option for specific categories, pick them here. By default they will show for all categories.') %] + </p> + </div> + [% INCLUDE 'admin/category-checkboxes.html' %] + <p> <input type="hidden" name="token" value="[% csrf_token %]" > <input type="submit" class="btn" name="Edit templates" value="[% rt.id ? loc('Save changes') : loc('Create template') %]" > diff --git a/web/js/fixmystreet-admin.js b/web/js/fixmystreet-admin.js index 8191fc254..0323b1742 100644 --- a/web/js/fixmystreet-admin.js +++ b/web/js/fixmystreet-admin.js @@ -31,6 +31,13 @@ $(function(){ }); } + // Some lists of checkboxes have 'select all/none' links at the top + $("a[data-select-none], a[data-select-all]").click(function(e) { + e.preventDefault(); + var checked = $(this).filter('[data-select-all]').length > 0; + $(this).closest("ul").find('input[type=checkbox]').prop('checked', checked); + }); + // admin hints: maybe better implemented as tooltips? $(".admin-hint").on('click', function(){ |