[PATCH 2/2] filters: Pre-populate delegate, submitter filters

Stephen Finucane stephen at that.guru
Fri Sep 28 04:26:01 AEST 2018


This appears to have got lost in the transition to 'selectize.js'. In
brief, this will ensure that a previously selected delegate or submitter
is still enabled post-filtering. For more information, see [1].

[1] https://stackoverflow.com/a/45124779

Signed-off-by: Stephen Finucane <stephen at that.guru>
Cc: Thomas Monjalon <thomas at monjalon.net>
Closes: #78
---
 patchwork/templates/patchwork/filters.html | 40 ++++++++++++++++------
 1 file changed, 29 insertions(+), 11 deletions(-)

diff --git a/patchwork/templates/patchwork/filters.html b/patchwork/templates/patchwork/filters.html
index e760310b..7040287c 100644
--- a/patchwork/templates/patchwork/filters.html
+++ b/patchwork/templates/patchwork/filters.html
@@ -16,8 +16,6 @@ function filter_click()
         form.style['display'] = 'block';
         filterform_displayed = true;
     }
-
-
 }
 
 Selectize.define('enter_key_submit', function (options) {
@@ -65,13 +63,25 @@ $(document).ready(function() {
                 return '<div>' + escape(item.email) + '</div>';
             }
         },
+{% if "submitter" in filters.applied_filters %}
+{% with submitter=filters.applied_filters.submitter.person %}
+        options: [
+            {
+                pk: {{ submitter.id }},
+                name: "{{ submitter.name }}",
+                email: "{{ submitter.email }}"
+            }
+        ],
+        items: [{{ submitter.id }} ],
+{% endwith %}
+{% endif %}
         load: function(query, callback) {
             if (query.length < 4)
                 return callback();
 
             req = $.ajax({
-                url: '{% url 'api-submitters' %}?q=' +
-                      encodeURIComponent(query) + '&l=10',
+                url: "{% url 'api-submitters' %}",
+                data: {q: encodeURIComponent(query), l: 10},
                 error: function() {
                     callback();
                 },
@@ -81,10 +91,7 @@ $(document).ready(function() {
             });
         }
     });
-});
-
 
-$(document).ready(function() {
     $('#delegate_input').selectize({
         valueField: 'pk',
         labelField: 'name',
@@ -110,10 +117,23 @@ $(document).ready(function() {
                 return '<div>' + escape(item.name) + '</div>';
             }
         },
+{% if "delegate" in filters.applied_filters %}
+{% with delegate=filters.applied_filters.delegate.delegate %}
+        options: [
+            {
+                pk: {{ delegate.id }},
+                name: "{{ delegate.profile.name }}",
+                email: "{{ delegate.email }}"
+            }
+        ],
+        items: [{{ delegate.id }} ],
+{% endwith %}
+{% endif %}
+        items: [{{ filters.params.delegate }}],
         load: function(query, callback) {
             req = $.ajax({
-                url: '{% url 'api-delegates' %}?q=' +
-                      encodeURIComponent(query) + '&l=10',
+                url: "{% url 'api-delegates' %}",
+                data: {q: encodeURIComponent(query), l: 10},
                 error: function() {
                     callback();
                 },
@@ -167,5 +187,3 @@ $(document).ready(function() {
   </form>
  </div>
 </div>
-
-
-- 
2.17.1



More information about the Patchwork mailing list