diff options
Diffstat (limited to 'web/js')
-rw-r--r-- | web/js/fixmystreet-admin.js | 31 |
1 files changed, 24 insertions, 7 deletions
diff --git a/web/js/fixmystreet-admin.js b/web/js/fixmystreet-admin.js index 6f4580feb..0323b1742 100644 --- a/web/js/fixmystreet-admin.js +++ b/web/js/fixmystreet-admin.js @@ -2,12 +2,13 @@ $(function(){ // available for admin pages // hide the open311_only section and reveal it only when send_method is relevant - var $open311_only = $('.admin-open311-only'); + function hide_or_show_open311(e, hide_fast) { + var $form = $(this).closest("form"); + var $open311_only = $form.find('.admin-open311-only'); - function hide_or_show_open311(hide_fast) { - var send_method = $('#send_method').val(); + var send_method = $(this).val(); var show_open311 = false; - if ($('#endpoint').val()) { + if ($form.find('[name=endpoint]').val()) { show_open311 = true; // always show the form if there is an endpoint value } else if (send_method && !send_method.match(/^(email|noop|refused)$/i)) { show_open311 = true; @@ -23,11 +24,20 @@ $(function(){ } } - if ($open311_only) { - $('#send_method').on('change', hide_or_show_open311); - hide_or_show_open311(true); + if ($('.admin-open311-only').length) { + // Add handler to send_method dropdowns and set initial visibility + $('[name=send_method]').on('change', hide_or_show_open311).each(function() { + hide_or_show_open311.call(this, null, true); + }); } + // 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(){ @@ -83,10 +93,17 @@ $(function(){ // On category edit page, hide the reputation input if inspection isn't required $("form#category_edit #inspection_required").change(function() { var $p = $("form#category_edit #reputation_threshold").closest("p"); + var $hint = $p.prevUntil().first(); if (this.checked) { $p.removeClass("hidden"); + if ($hint.length) { + $hint.removeClass("hidden"); + } } else { $p.addClass("hidden"); + if ($hint.length) { + $hint.addClass("hidden"); + } } }); }); |