diff options
Diffstat (limited to 'extensions')
4 files changed, 49 insertions, 0 deletions
diff --git a/extensions/BugModal/template/en/default/bug_modal/field.html.tmpl b/extensions/BugModal/template/en/default/bug_modal/field.html.tmpl index 9327069da..8317a059f 100644 --- a/extensions/BugModal/template/en/default/bug_modal/field.html.tmpl +++ b/extensions/BugModal/template/en/default/bug_modal/field.html.tmpl @@ -157,6 +157,7 @@ END; [% CASE constants.FIELD_TYPE_SINGLE_SELECT %] [%# single value select %] + <input type="hidden" id="[% name FILTER html %]-dirty"> <select name="[% name FILTER html %]" id="[% name FILTER html %]"> [% IF values.defined %] [% FOREACH v IN values %] @@ -173,6 +174,7 @@ END; [% CASE constants.FIELD_TYPE_MULTI_SELECT %] [%# multi value select %] + <input type="hidden" id="[% name FILTER html %]-dirty"> <select name="[% name FILTER html %]" id="[% name FILTER html %]" multiple size="5"> [% IF values.defined %] [%# not implemented %] diff --git a/extensions/BugModal/template/en/default/bug_modal/flags.html.tmpl b/extensions/BugModal/template/en/default/bug_modal/flags.html.tmpl index 77e04b882..d86a8c8cf 100644 --- a/extensions/BugModal/template/en/default/bug_modal/flags.html.tmpl +++ b/extensions/BugModal/template/en/default/bug_modal/flags.html.tmpl @@ -112,6 +112,7 @@ </td> <td class="flag-value"> + <input type="hidden" id="[% flag_id FILTER html %]-dirty"> <select id="[% flag_id FILTER html %]" name="[% flag_id FILTER html %]" title="[% t.description FILTER html %]" [% UNLESS (t.is_requestable && user.can_request_flag(t)) || user.can_set_flag(t) %] diff --git a/extensions/BugModal/template/en/default/bug_modal/tracking_flags.html.tmpl b/extensions/BugModal/template/en/default/bug_modal/tracking_flags.html.tmpl index 5f22338cd..d6f7d6f89 100644 --- a/extensions/BugModal/template/en/default/bug_modal/tracking_flags.html.tmpl +++ b/extensions/BugModal/template/en/default/bug_modal/tracking_flags.html.tmpl @@ -77,6 +77,7 @@ [% BLOCK tf_select %] [% RETURN UNLESS flag %] + <input type="hidden" id="[% flag.name FILTER html %]-dirty"> <select id="[% flag.name FILTER html %]" name="[% flag.name FILTER html %]"> [% flag_bug_value = flag.bug_flag(bug_id).value; diff --git a/extensions/BugModal/web/bug_modal.js b/extensions/BugModal/web/bug_modal.js index 419ac1e84..87324f2f5 100644 --- a/extensions/BugModal/web/bug_modal.js +++ b/extensions/BugModal/web/bug_modal.js @@ -246,6 +246,26 @@ $(function() { if (BUGZILLA.user.id === 0) return; + // dirty field tracking + $('#changeform select').each(function() { + var that = $(this); + var dirty = $('#' + that.attr('id') + '-dirty'); + if (!dirty) return; + var isMultiple = that.attr('multiple'); + + // store the option that had the selected attribute when we + // initially loaded + var value = that.find('option[selected]').map(function() { return this.value; }).toArray(); + if (value.length === 0 && !that.attr('multiple')) + value = that.find('option:first').map(function() { return this.value; }).toArray(); + that.data('preselected', value); + + // if the user hasn't touched a field, override the browser's choice + // with bugzilla's + if (!dirty.val()) + that.val(value); + }); + // edit/save mode button $('#mode-btn') .click(function(event) { @@ -963,6 +983,31 @@ $(function() { ); last_comment_text = comment.val(); }); + + // dirty field tracking + $('#changeform select') + .change(function() { + var that = $(this); + var dirty = $('#' + that.attr('id') + '-dirty'); + if (!dirty) return; + if (that.attr('multiple')) { + var preselected = that.data('preselected'); + var selected = that.val(); + var isDirty = preselected.length != selected.length; + if (!isDirty) { + for (var i = 0, l = preselected.length; i < l; i++) { + if (selected[i] != preselected[i]) { + isDirty = true; + break; + } + } + } + dirty.val(isDirty ? '1' : ''); + } + else { + dirty.val(that.val() === that.data('preselected')[0] ? '' : '1'); + } + }); }); function confirmUnsafeURL(url) { |