diff options
-rw-r--r-- | CHANGELOG.md | 3 | ||||
-rw-r--r-- | web/cobrands/fixmystreet/fixmystreet.js | 16 | ||||
-rw-r--r-- | web/cobrands/fixmystreet/staff.js | 22 | ||||
-rw-r--r-- | web/js/map-OpenLayers.js | 4 |
4 files changed, 27 insertions, 18 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index b5a996bea..cd2b3e11e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,8 @@ - Allow moderation to potentially change state. #2381 - Spot moderation conflicts and raise an error. #2384 - Allow searching for <email> in admin. - - Bugfixes + - Make staff JavaScript more self-contained. + - Bugfixes: - Check cached reports do still have photos before being shown. #2374 - Delete cache photos upon photo moderation. #2374 - Remove any use of `my $x if $foo`. #2377 diff --git a/web/cobrands/fixmystreet/fixmystreet.js b/web/cobrands/fixmystreet/fixmystreet.js index 2406b65e3..5efc0d878 100644 --- a/web/cobrands/fixmystreet/fixmystreet.js +++ b/web/cobrands/fixmystreet/fixmystreet.js @@ -216,14 +216,6 @@ fixmystreet.update_list_item_buttons = function($list) { $list.children(':last-child').find('[name="shortlist-down"]').prop('disabled', true); }; -// A tiny helper to call a function only if it exists (so we can -// call this with staff-only functions and they won't error). -fixmystreet.run = function(fn) { - if (fn) { - fn.call(this); - } -}; - fixmystreet.set_up = fixmystreet.set_up || {}; $.extend(fixmystreet.set_up, { basics: function() { @@ -1186,7 +1178,7 @@ fixmystreet.update_pin = function(lonlat, savePushState) { if (category_select.val() != '-- Pick a category --') { category_select.change(); } - fixmystreet.run(fixmystreet.set_up.category_groups); + fixmystreet.set_up.category_groups(); if (category_group !== '-- Pick a category --' && category_select.val() == '-- Pick a category --') { $('#category_group').val(category_group).change(); } @@ -1343,9 +1335,6 @@ fixmystreet.display = { if ($twoColReport.length) { $twoColReport.appendTo('#map_sidebar'); $('body').addClass('with-actions'); - fixmystreet.run(fixmystreet.set_up.report_page_inspect); - fixmystreet.run(fixmystreet.set_up.manage_duplicates); - fixmystreet.run(fixmystreet.set_up.action_scheduled_raise_defect); } else { $sideReport.appendTo('#map_sidebar'); } @@ -1403,8 +1392,7 @@ fixmystreet.display = { fixmystreet.set_up.form_section_previews(); fixmystreet.set_up.fancybox_images(); fixmystreet.set_up.dropzone($sideReport); - fixmystreet.run(fixmystreet.set_up.moderation); - fixmystreet.run(fixmystreet.set_up.response_templates); + $(fixmystreet).trigger('display:report'); fixmystreet.update_report_a_problem_btn(); diff --git a/web/cobrands/fixmystreet/staff.js b/web/cobrands/fixmystreet/staff.js index 013115427..fadf18356 100644 --- a/web/cobrands/fixmystreet/staff.js +++ b/web/cobrands/fixmystreet/staff.js @@ -1,4 +1,4 @@ -$.extend(fixmystreet.set_up, { +fixmystreet.staff_set_up = { manage_duplicates: function() { // Deal with changes to report state by inspector/other staff, specifically // displaying nearby reports if it's changed to 'duplicate'. @@ -450,6 +450,22 @@ $.extend(fixmystreet.set_up, { }); } +}; + +$(function() { + $.each(fixmystreet.staff_set_up, function(setup_name, setup_func) { + setup_func(); + }); +}); + +$(fixmystreet).on('display:report', function() { + fixmystreet.staff_set_up.moderation(); + fixmystreet.staff_set_up.response_templates(); + if ($("#report_inspect_form").length) { + fixmystreet.staff_set_up.report_page_inspect(); + fixmystreet.staff_set_up.manage_duplicates(); + fixmystreet.staff_set_up.action_scheduled_raise_defect(); + } }); $(fixmystreet).on('report_new:category_change', function(evt, $this) { @@ -530,6 +546,10 @@ $.extend(fixmystreet.maps, { } }); +$(fixmystreet).on('map:zoomend', function() { + fixmystreet.maps.show_shortlist_control(); +}); + fixmystreet.utils = fixmystreet.utils || {}; $.extend(fixmystreet.utils, { diff --git a/web/js/map-OpenLayers.js b/web/js/map-OpenLayers.js index 2a9897e5b..27e89df1d 100644 --- a/web/js/map-OpenLayers.js +++ b/web/js/map-OpenLayers.js @@ -720,9 +720,9 @@ $.extend(fixmystreet.utils, { ); fixmystreet.map.addControl( fixmystreet.select_feature ); fixmystreet.select_feature.activate(); - fixmystreet.map.events.register( 'zoomend', null, fixmystreet.maps.markers_resize ); fixmystreet.map.events.register( 'zoomend', null, function() { - fixmystreet.run(fixmystreet.maps.show_shortlist_control); + fixmystreet.maps.markers_resize(); + $(fixmystreet).trigger('map:zoomend'); }); // Set up the event handlers to populate the filters and react to them changing |