summaryrefslogtreecommitdiffstats
path: root/extensions/BugModal/web
diff options
context:
space:
mode:
authorByron Jones <glob@mozilla.com>2015-05-13 04:29:39 +0200
committerByron Jones <glob@mozilla.com>2015-05-13 04:29:39 +0200
commit0622523114252d26a5710684bfad7b5811173d66 (patch)
tree3167411366e99a6d91b3b2bd33048e6b0fd72f62 /extensions/BugModal/web
parent53af86d19c6e75e68e1822cd66b864e509f391d6 (diff)
downloadbugzilla-0622523114252d26a5710684bfad7b5811173d66.tar.gz
bugzilla-0622523114252d26a5710684bfad7b5811173d66.tar.xz
Bug 1163326: implement dirty select tracking in bug-modal to address firefox refresh issue
Diffstat (limited to 'extensions/BugModal/web')
-rw-r--r--extensions/BugModal/web/bug_modal.js45
1 files changed, 45 insertions, 0 deletions
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) {