diff options
author | Byron Jones <bjones@mozilla.com> | 2012-09-26 01:01:12 +0800 |
---|---|---|
committer | Byron Jones <bjones@mozilla.com> | 2012-09-26 01:01:12 +0800 |
commit | b4c57eb52706fd61f3167dc05eccae1fd7c30513 (patch) | |
tree | 3bdfde89b1e735f968929c944940b419952bc229 | |
parent | Bug 694755: Add Classification API to WebServices (implement Classification.g... (diff) | |
download | bugzilla-b4c57eb52706fd61f3167dc05eccae1fd7c30513.tar.gz bugzilla-b4c57eb52706fd61f3167dc05eccae1fd7c30513.tar.bz2 bugzilla-b4c57eb52706fd61f3167dc05eccae1fd7c30513.zip |
Bug 437212: Make page refreshing under Firefox update fields
r=LpSolit, a=LpSolit
-rw-r--r-- | js/field.js | 48 | ||||
-rw-r--r-- | js/util.js | 21 | ||||
-rw-r--r-- | template/en/default/bug/edit.html.tmpl | 1 | ||||
-rw-r--r-- | template/en/default/bug/field.html.tmpl | 1 | ||||
-rw-r--r-- | template/en/default/bug/show-header.html.tmpl | 3 | ||||
-rw-r--r-- | template/en/default/flag/list.html.tmpl | 1 |
6 files changed, 75 insertions, 0 deletions
diff --git a/js/field.js b/js/field.js index caf13217b..7d47169d4 100644 --- a/js/field.js +++ b/js/field.js @@ -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' : ''; + }); + } +} diff --git a/js/util.js b/js/util.js index 7ecc2a3d8..6d1f88938 100644 --- a/js/util.js +++ b/js/util.js @@ -230,6 +230,27 @@ function bz_selectedOptions(aSelect) { } /** + * 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> * diff --git a/template/en/default/bug/edit.html.tmpl b/template/en/default/bug/edit.html.tmpl index 23a11fc47..0d86f02fa 100644 --- a/template/en/default/bug/edit.html.tmpl +++ b/template/en/default/bug/edit.html.tmpl @@ -1102,6 +1102,7 @@ <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} %] diff --git a/template/en/default/bug/field.html.tmpl b/template/en/default/bug/field.html.tmpl index 88a5adba8..4255b1702 100644 --- a/template/en/default/bug/field.html.tmpl +++ b/template/en/default/bug/field.html.tmpl @@ -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 %] diff --git a/template/en/default/bug/show-header.html.tmpl b/template/en/default/bug/show-header.html.tmpl index 6d4e2d595..93ddc94f1 100644 --- a/template/en/default/bug/show-header.html.tmpl +++ b/template/en/default/bug/show-header.html.tmpl @@ -37,6 +37,9 @@ history.replaceState(null, "[% unfiltered_title FILTER js %]", href); } } + YAHOO.util.Event.onDOMReady(function() { + initDirtyFieldTracking(); + }); [% javascript FILTER none %] [% END %] [% END %] diff --git a/template/en/default/flag/list.html.tmpl b/template/en/default/flag/list.html.tmpl index 9eb6b4441..88486c7f6 100644 --- a/template/en/default/flag/list.html.tmpl +++ b/template/en/default/flag/list.html.tmpl @@ -107,6 +107,7 @@ [%- 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);" |