aboutsummaryrefslogtreecommitdiffstats
path: root/web
diff options
context:
space:
mode:
authorStruan Donald <struan@exo.org.uk>2018-05-16 14:35:57 +0100
committerMatthew Somerville <matthew-github@dracos.co.uk>2018-08-06 09:39:42 +0100
commitcc3e8bd6e93fd293934d8697e0daea58494ad28f (patch)
tree6ef5483d04e678407f3889d9f09fbd27bbe5b217 /web
parent18e74eeb512c2824ca43c54fead5ba63d04f361b (diff)
allow front end to not send to specific body
add a do_not_send parameter to reports which allows the front end to specify a comma separated list of bodies that reports should not be sent to even if there is a valid contact match. This enables asset layers to override backend body processing, e.g. if a body only accepts reports that are on a road this allows the front end to specify that.
Diffstat (limited to 'web')
-rw-r--r--web/cobrands/bromley/assets.js4
-rw-r--r--web/cobrands/buckinghamshire/assets.js4
-rw-r--r--web/cobrands/fixmystreet/assets.js63
-rw-r--r--web/cobrands/fixmystreet/fixmystreet.js13
4 files changed, 74 insertions, 10 deletions
diff --git a/web/cobrands/bromley/assets.js b/web/cobrands/bromley/assets.js
index 6d05e0084..959148e5d 100644
--- a/web/cobrands/bromley/assets.js
+++ b/web/cobrands/bromley/assets.js
@@ -82,11 +82,11 @@ fixmystreet.assets.add($.extend(true, {}, defaults, {
actions: {
found: function(layer, feature) {
if (!fixmystreet.assets.selectedFeature()) {
- $('#single_body_only').val('TfL');
+ fixmystreet.body_overrides.only_send('TfL');
}
},
not_found: function(layer) {
- $('#single_body_only').val('');
+ fixmystreet.body_overrides.remove_only_send();
}
}
}));
diff --git a/web/cobrands/buckinghamshire/assets.js b/web/cobrands/buckinghamshire/assets.js
index 9b392daba..82301c4f2 100644
--- a/web/cobrands/buckinghamshire/assets.js
+++ b/web/cobrands/buckinghamshire/assets.js
@@ -172,6 +172,7 @@ fixmystreet.assets.add($.extend(true, {}, defaults, {
all_categories: true,
actions: {
found: function(layer, feature) {
+ fixmystreet.body_overrides.allow_send(layer.fixmystreet.body);
if (fixmystreet.assets.selectedFeature()) {
hide_responsibility_errors();
enable_report_form();
@@ -180,6 +181,7 @@ fixmystreet.assets.add($.extend(true, {}, defaults, {
enable_report_form();
} else if (is_only_body(layer.fixmystreet.body)) {
// User has clicked a road that Bucks don't maintain.
+ fixmystreet.body_overrides.do_not_send(layer.fixmystreet.body);
show_responsibility_error("#js-not-council-road");
disable_report_form();
}
@@ -189,7 +191,9 @@ fixmystreet.assets.add($.extend(true, {}, defaults, {
// If a feature wasn't found at the location they've clicked, it's
// probably a field or something. Show an error to that effect,
// unless an asset is selected.
+ fixmystreet.body_overrides.do_not_send(layer.fixmystreet.body);
if (fixmystreet.assets.selectedFeature()) {
+ fixmystreet.body_overrides.allow_send(layer.fixmystreet.body);
hide_responsibility_errors();
enable_report_form();
} else if (is_only_body(layer.fixmystreet.body)){
diff --git a/web/cobrands/fixmystreet/assets.js b/web/cobrands/fixmystreet/assets.js
index 11ea1c80e..cd1e202e5 100644
--- a/web/cobrands/fixmystreet/assets.js
+++ b/web/cobrands/fixmystreet/assets.js
@@ -136,7 +136,7 @@ OpenLayers.Layer.VectorNearest = OpenLayers.Class(OpenLayers.Layer.VectorAsset,
if (this.fixmystreet.actions) {
this.fixmystreet.actions.found(this, this.selected_feature);
} else if (!fixmystreet.assets.selectedFeature()) {
- $('#single_body_only').val(this.fixmystreet.body);
+ fixmystreet.body_overrides.only_send(this.fixmystreet.body);
}
},
@@ -144,7 +144,7 @@ OpenLayers.Layer.VectorNearest = OpenLayers.Class(OpenLayers.Layer.VectorAsset,
if (this.fixmystreet.actions) {
this.fixmystreet.actions.not_found(this);
} else {
- $('#single_body_only').val('');
+ fixmystreet.body_overrides.remove_only_send();
}
},
@@ -742,3 +742,62 @@ OpenLayers.Request.XMLHttpRequest.prototype.setRequestHeader = function(sName, s
return this._object.setRequestHeader(sName, sValue);
};
})();
+
+/* Handling of body override functionality */
+
+fixmystreet.body_overrides = (function(){
+
+var do_not_send = [];
+var only_send = '';
+
+function update() {
+ $('#do_not_send').val(fixmystreet.utils.array_to_csv_line(do_not_send));
+ $('#single_body_only').val(only_send);
+ $(fixmystreet).trigger('body_overrides:change');
+}
+
+return {
+ clear: function() {
+ do_not_send = [];
+ update();
+ },
+ only_send: function(body) {
+ only_send = body;
+ update();
+ },
+ remove_only_send: function() {
+ only_send = '';
+ update();
+ },
+ do_not_send: function(body) {
+ do_not_send.push(body);
+ update();
+ },
+ allow_send: function(body) {
+ do_not_send = $.grep(do_not_send, function(a) { return a !== body; });
+ update();
+ }
+};
+
+})();
+
+$(fixmystreet).on('body_overrides:change', function() {
+ var councils_text = $('#js-councils_text').html();
+
+ var single_body_only = $('#single_body_only').val();
+ if (single_body_only) {
+ councils_text = councils_text.replace(/<strong>.*<\/strong>/, '<strong>' + single_body_only + '</strong>');
+ }
+
+ var do_not_send = $('#do_not_send').val();
+ if (do_not_send) {
+ do_not_send = fixmystreet.utils.csv_to_array(do_not_send);
+ for (var i=0; i<do_not_send.length; i++) {
+ // XXX Translations
+ councils_text = councils_text.replace(new RegExp('or <strong>' + do_not_send[i] + '</strong>'), '');
+ councils_text = councils_text.replace(new RegExp('<strong>' + do_not_send[i] + '</strong> or '), '');
+ }
+ }
+
+ $('#js-councils_text').html(councils_text);
+});
diff --git a/web/cobrands/fixmystreet/fixmystreet.js b/web/cobrands/fixmystreet/fixmystreet.js
index 5f9dd9699..1b863625f 100644
--- a/web/cobrands/fixmystreet/fixmystreet.js
+++ b/web/cobrands/fixmystreet/fixmystreet.js
@@ -410,6 +410,9 @@ $.extend(fixmystreet.set_up, {
$category_meta.empty();
}
fixmystreet.bodies = data.bodies || [];
+ if (fixmystreet.body_overrides) {
+ fixmystreet.body_overrides.clear();
+ }
$(fixmystreet).trigger('report_new:category_change:extras_received');
});
@@ -889,14 +892,9 @@ $.extend(fixmystreet.set_up, {
});
fixmystreet.update_councils_text = function(data) {
- var single_body_only = $('#single_body_only').val();
- if (single_body_only) {
- data.councils_text = data.councils_text.replace(/<strong>.*<\/strong>/, '<strong>' + single_body_only + '</strong>');
- }
-
$('#js-councils_text').html(data.councils_text);
$('#js-councils_text_private').html(data.councils_text_private);
-
+ $(fixmystreet).trigger('body_overrides:change');
};
// The new location will be saved to a history state unless
@@ -942,6 +940,9 @@ fixmystreet.update_pin = function(lonlat, savePushState) {
}
fixmystreet.bodies = data.bodies || [];
+ if (fixmystreet.body_overrides) {
+ fixmystreet.body_overrides.clear();
+ }
// If the category filter appears on the map and the user has selected
// something from it, then pre-fill the category field in the report,