aboutsummaryrefslogtreecommitdiffstats
path: root/web/js
diff options
context:
space:
mode:
authorDave Arter <davea@mysociety.org>2016-08-25 17:04:42 +0100
committerMatthew Somerville <matthew-github@dracos.co.uk>2016-08-26 14:22:26 +0100
commit4f7664c2b0e79fdfe57028e966642acd8c846568 (patch)
tree8d2a1707b65b3e13284f40c97dcad41c4567ec79 /web/js
parent0e2e741fc8380fbd1d0b7b5ed16050d6f4dc27e2 (diff)
Make sure moderation works on AJAX-loaded report.
This refactors the moderation JS into a fixmystreet.set_up function, and ensures the button handlers are attached when a new report is loaded over AJAX. A side effect of bringing it into fixmystreet.js instead of its own moderate.js file is the few extra kb each user will have to download, but hopefully gzip and caching will help ameliorate this.
Diffstat (limited to 'web/js')
-rw-r--r--web/js/moderate.js51
1 files changed, 0 insertions, 51 deletions
diff --git a/web/js/moderate.js b/web/js/moderate.js
deleted file mode 100644
index 53277d9d9..000000000
--- a/web/js/moderate.js
+++ /dev/null
@@ -1,51 +0,0 @@
-function toggle_original ($input, revert) {
- $input.prop('disabled', revert);
- if (revert) {
- $input.data('currentValue', $input.val());
- }
- $input.val($input.data(revert ? 'originalValue' : 'currentValue'));
-}
-
-function setup_moderation (elem, word) {
-
- elem.each( function () {
- var $elem = $(this);
- $elem.find('.moderate').click( function () {
- $elem.find('.moderate-display').hide();
- $elem.find('.moderate-edit').show();
- });
-
- $elem.find('.revert-title').change( function () {
- toggle_original($elem.find('input[name=problem_title]'), $(this).prop('checked'));
- });
-
- $elem.find('.revert-textarea').change( function () {
- toggle_original($elem.find('textarea'), $(this).prop('checked'));
- });
-
- var hide_document = $elem.find('.hide-document');
- hide_document.change( function () {
- $elem.find('input[name=problem_title]').prop('disabled', $(this).prop('checked'));
- $elem.find('textarea').prop('disabled', $(this).prop('checked'));
- $elem.find('input[type=checkbox]').prop('disabled', $(this).prop('checked'));
- $(this).prop('disabled', false); // in case disabled above
- });
-
- $elem.find('.cancel').click( function () {
- $elem.find('.moderate-display').show();
- $elem.find('.moderate-edit').hide();
- });
-
- $elem.find('form').submit( function () {
- if (hide_document.prop('checked')) {
- return confirm('This will hide the ' + word + ' completely! (You will not be able to undo this without contacting support.)');
- }
- return true;
- });
- });
-}
-
-$(function () {
- setup_moderation( $('.problem-header'), 'problem' );
- setup_moderation( $('.item-list__item--updates'), 'update' );
-});