]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 437212: Make page refreshing under Firefox update fields
authorByron Jones <bjones@mozilla.com>
Tue, 25 Sep 2012 17:01:12 +0000 (01:01 +0800)
committerByron Jones <bjones@mozilla.com>
Tue, 25 Sep 2012 17:01:12 +0000 (01:01 +0800)
r=LpSolit, a=LpSolit

js/field.js
js/util.js
template/en/default/bug/edit.html.tmpl
template/en/default/bug/field.html.tmpl
template/en/default/bug/show-header.html.tmpl
template/en/default/flag/list.html.tmpl

index caf13217bc9b0ff4d646598ed2ddb28670eddcab..7d47169d4bc58cf11df0a30dbce089bc8c0d63cc 100644 (file)
@@ -927,3 +927,51 @@ function userDisabledTextOnChange(disabledtext) {
         disable_mail.checked = true;
     }
 }
+
+/**
+ * Force the browser to honour the selected option when a page is refreshed,
+ * but only if the user hasn't explicitly selected a different option.
+ */
+function initDirtyFieldTracking() {
+    // old IE versions don't provide the information we need to make this fix work
+    // however they aren't affected by this issue, so it's ok to ignore them
+    if (YAHOO.env.ua.ie > 0 && YAHOO.env.ua.ie <= 8) return;
+    var selects = document.getElementById('changeform').getElementsByTagName('select');
+    for (var i = 0, l = selects.length; i < l; i++) {
+        var el = selects[i];
+        var el_dirty = document.getElementById(el.name + '_dirty');
+        if (!el_dirty) continue;
+        if (!el_dirty.value) {
+            var preSelected = bz_preselectedOptions(el);
+            if (!el.multiple) {
+                preSelected.selected = true;
+            } else {
+                el.selectedIndex = -1;
+                for (var j = 0, m = preSelected.length; j < m; j++) {
+                    preSelected[j].selected = true;
+                }
+            }
+        }
+        YAHOO.util.Event.on(el, "change", function(e) {
+            var el = e.target || e.srcElement;
+            var preSelected = bz_preselectedOptions(el);
+            var currentSelected = bz_selectedOptions(el);
+            var isDirty = false;
+            if (!el.multiple) {
+                isDirty = preSelected.index != currentSelected.index;
+            } else {
+                if (preSelected.length != currentSelected.length) {
+                    isDirty = true;
+                } else {
+                    for (var i = 0, l = preSelected.length; i < l; i++) {
+                        if (currentSelected[i].index != preSelected[i].index) {
+                            isDirty = true;
+                            break;
+                        }
+                    }
+                }
+            }
+            document.getElementById(el.name + '_dirty').value = isDirty ? '1' : '';
+        });
+    }
+}
index 7ecc2a3d8395fc7d3b0bec3ebbef16208fb839d5..6d1f88938eece5380eb3c82dbd28f5e158be0a6d 100644 (file)
@@ -229,6 +229,27 @@ function bz_selectedOptions(aSelect) {
     return selected;
 }
 
+/**
+ * Returns all Option elements that have the "selected" attribute, as an array.
+ * Returns an empty array if nothing is selected.
+ *
+ * @param aSelect The select you want the pre-selected values of.
+ */
+function bz_preselectedOptions(aSelect) {
+    var options = aSelect.options;
+    var selected = new Array();
+    for (var i = 0, l = options.length; i < l; i++) {
+        var attributes = options[i].attributes;
+        for (var j = 0, m = attributes.length; j < m; j++) {
+            if (attributes[j].name == 'selected') {
+                if (!aSelect.multiple) return options[i];
+                selected.push(options[i]);
+            }
+        }
+    }
+    return selected;
+}
+
 /**
  * Tells you where (what index) in a <select> a particular option is.
  * Returns -1 if the value is not in the <select>
index 23a11fc470708191f8ed3c4df2cdd2637c491fee..0d86f02fa679dbda60301353d2ba497e8ddbd8ee 100644 (file)
   <td>
     [% IF bug.check_can_change_field(selname, 0, 1) 
           AND bug.choices.${selname}.size > 1 %]
+      <input type="hidden" id="[% selname %]_dirty">
       <select id="[% selname %]" name="[% selname %]">
         [% FOREACH x = bug.choices.${selname} %]
           [% NEXT IF NOT x.is_active AND x.name != bug.${selname} %]
index 88a5adba8ef7f0f24c24bca887e42d3f2a863ff5..4255b1702144168f7f8f3c27fff6b31eebe367b5 100644 (file)
@@ -82,6 +82,7 @@
         </script>
     [% CASE [ constants.FIELD_TYPE_SINGLE_SELECT 
               constants.FIELD_TYPE_MULTI_SELECT ] %]
+        <input type="hidden" id="[% field.name FILTER html %]_dirty">
         <select id="[% field.name FILTER html %]" 
                 name="[% field.name FILTER html %]" 
                 [% IF field.type == constants.FIELD_TYPE_MULTI_SELECT %]
index 6d4e2d595ac11b03c38c66e2c3b3e02b018b92d2..93ddc94f146048efc9ef715b0dfc309de8b1b856 100644 (file)
@@ -37,6 +37,9 @@
         history.replaceState(null, "[% unfiltered_title FILTER js %]", href);
       }
     }
+    YAHOO.util.Event.onDOMReady(function() {
+      initDirtyFieldTracking();
+    });
     [% javascript FILTER none %]
   [% END %]
 [% END %]
index 9eb6b44413fda9b53d1393e01445bb2a1aa44ebd..88486c7f67f943fa5b49356cbd86dd40e0a09054 100644 (file)
           [%- type.name FILTER html FILTER no_break -%]</label>
       </td>
       <td>
+        <input type="hidden" id="[% fid FILTER html %]_dirty">
         <select id="[% fid FILTER html %]" name="[% fid FILTER html %]"
                 title="[% type.description FILTER html %]"
                 onchange="toggleRequesteeField(this);"