]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 674416: Custom searches in query.cgi are lost when clicking the "Back" button...
authorMax Kanat-Alexander <mkanat@bugzilla.org>
Sat, 15 Oct 2011 13:02:36 +0000 (15:02 +0200)
committerFrédéric Buclin <LpSolit@gmail.com>
Sat, 15 Oct 2011 13:02:36 +0000 (15:02 +0200)
r=glob a=mkanat

js/custom-search.js
template/en/default/search/boolean-charts.html.tmpl

index 80015044083a2010faadeaefb8038515c1616e09..394e0eb32629d382fd06fd77382a54d8e4b522c9 100644 (file)
@@ -32,6 +32,8 @@ var ANY_ALL_SELECT_CLASS = 'any_all_select';
 function custom_search_not_changed(id) {
     var container = document.getElementById('custom_search_not_container_' + id);
     YAHOO.util.Dom.removeClass(container, 'custom_search_advanced');
+
+    fix_query_string(container);
 }
 
 function custom_search_new_row() {
@@ -53,6 +55,7 @@ function custom_search_new_row() {
     // Always make sure there's only one row with this id.
     row.id = null;
     row.parentNode.appendChild(clone);
+    fix_query_string(row);
     return clone;
 }
 
@@ -100,6 +103,8 @@ function custom_search_open_paren() {
     var new_margin = parseInt(int_match[0]) + PAREN_INDENT_EM;
     YAHOO.util.Dom.setStyle(row, 'margin-left', new_margin + 'em');
     YAHOO.util.Dom.removeClass('cp_container', 'bz_default_hidden');
+
+    fix_query_string(any_all_container);
 }
 
 function custom_search_close_paren() {
@@ -124,6 +129,23 @@ function custom_search_close_paren() {
     if (new_margin == 0) {
         YAHOO.util.Dom.addClass('cp_container', 'bz_default_hidden');
     }
+
+    fix_query_string(new_row);
+}
+
+// When a user goes Back in their browser after searching, some browsers
+// (Chrome, as of September 2011) do not remember the DOM that was created
+// by the Custom Search JS. (In other words, their whole entered Custom
+// Search disappears.) The solution is to update the History object,
+// using the query string, which query.cgi can read to re-create the page
+// exactly as the user had it before.
+function fix_query_string(form_member) {
+    if (!(window.history && window.history.replaceState))
+        return;
+
+    var form = YAHOO.util.Dom.getAncestorByTagName(form_member, 'form');
+    var query = YAHOO.util.Connect.setForm(form);
+    window.history.replaceState(null, document.title, '?' + query);
 }
 
 
index b90f5f1b6ea4213d1803d5152e4cfca1eb85ce7c..b5ff909088a0f7d97c641a7b5f81c53b005d6318 100644 (file)
     [% ELSE %]
       <select name="f[% cond_num FILTER html %]" title="Field"
               id="f[% cond_num FILTER html %]"
+              onchange="fix_query_string(this)"
               class="custom_search_form_field">
         [% FOREACH field = fields %]
           <option value="[% field.name FILTER html %]"
     
       <input name="v[% cond_num FILTER html %]" title="Value"
              class="custom_search_form_field"
+             onchange="fix_query_string(this)"
              value="[% condition.v FILTER html %]">
     [% END %]
     
 
 [% BLOCK any_all_select %]
   <div class="any_all_select">
-    <select name="[% name FILTER html %]" id="[% name FILTER html %]">
+    <select name="[% name FILTER html %]" id="[% name FILTER html %]"
+            onchange="fix_query_string(this)">
       <option value="AND">Match ALL of the following:</option>
       <option value="OR" [% ' selected="selected"' IF selected == "OR" %]>
         Match ANY of the following:</option>