aboutsummaryrefslogtreecommitdiffstats
path: root/web/cobrands
diff options
context:
space:
mode:
authorDave Arter <davea@mysociety.org>2016-12-01 16:54:20 +0000
committerDave Arter <davea@mysociety.org>2017-01-10 11:13:33 +0000
commitaa26b2bb569c657db3452eeac21df8cd415d77e7 (patch)
treeb2e70d00c8c5552f38de34d5a3262697be7dd47c /web/cobrands
parent7416881f07d2a02ce0c98718e0ca5790a39518d7 (diff)
Prefill update field based on problem state
If there’s a response template matching the problem’s new state, it’s selected and the update field prefilled accordingly. The exception to this is if the user has manually entered text into the update field already.
Diffstat (limited to 'web/cobrands')
-rw-r--r--web/cobrands/fixmystreet/fixmystreet.js23
1 files changed, 21 insertions, 2 deletions
diff --git a/web/cobrands/fixmystreet/fixmystreet.js b/web/cobrands/fixmystreet/fixmystreet.js
index dd9167185..35a655c86 100644
--- a/web/cobrands/fixmystreet/fixmystreet.js
+++ b/web/cobrands/fixmystreet/fixmystreet.js
@@ -675,13 +675,21 @@ $.extend(fixmystreet.set_up, {
// The inspect form submit button can change depending on the selected state
$("#report_inspect_form [name=state]").change(function(){
var state = $(this).val();
- var $submit = $("#report_inspect_form input[type=submit]");
+ var $inspect_form = $("#report_inspect_form");
+ var $submit = $inspect_form.find("input[type=submit]");
var value = $submit.attr('data-value-'+state);
if (value !== undefined) {
$submit.val(value);
} else {
$submit.val($submit.data('valueOriginal'));
}
+
+ // We might also have a response template to preselect for the new state
+ var $select = $inspect_form.find("select.js-template-name");
+ var $option = $select.find("option[data-problem-state='"+state+"']").first();
+ if ($option.length) {
+ $select.val($option.val()).change();
+ }
}).change();
$('.js-toggle-public-update').each(function() {
@@ -1001,9 +1009,20 @@ $.extend(fixmystreet.set_up, {
},
response_templates: function() {
+ // If the user has manually edited the contents of an update field,
+ // mark it as dirty so it doesn't get clobbered if we select another
+ // response template. If the field is empty, it's not considered dirty.
+ $('.js-template-name').each(function() {
+ var $input = $('#' + $(this).data('for'));
+ $input.change(function() { $(this).data('dirty', !/^\s*$/.test($(this).val())); });
+ });
+
$('.js-template-name').change(function() {
var $this = $(this);
- $('#' + $this.data('for')).val($this.val());
+ var $input = $('#' + $this.data('for'));
+ if (!$input.data('dirty')) {
+ $input.val($this.val());
+ }
});
}
});