79aef93f by Adam Heath

Improve the api, by having applyQueryParameters() call resetParameters,

instead of resetSearch.
1 parent 14fb6444
...@@ -210,6 +210,12 @@ define(function(require) { ...@@ -210,6 +210,12 @@ define(function(require) {
210 } 210 }
211 return Facet.__super__.initialize.apply(this, arguments); 211 return Facet.__super__.initialize.apply(this, arguments);
212 }, 212 },
213 resetSearch: function(options) {
214 this.get('items').invoke('reset', null, options);
215 },
216 resetParameters: function(options) {
217 this.get('items').invoke('set', {checked: false}, options);
218 },
213 applyFacetResults: function(facetName, data, options) { 219 applyFacetResults: function(facetName, data, options) {
214 options = options || {}; 220 options = options || {};
215 var facetCounts = Util.getField(data, 'facet_counts'); 221 var facetCounts = Util.getField(data, 'facet_counts');
......
...@@ -46,9 +46,10 @@ define(function(require) { ...@@ -46,9 +46,10 @@ define(function(require) {
46 return Facets.__super__.initialize.apply(this, arguments); 46 return Facets.__super__.initialize.apply(this, arguments);
47 }, 47 },
48 resetSearch: function(options) { 48 resetSearch: function(options) {
49 _.each(this.values(), function(facet) { 49 _.invoke(this.values(), 'resetSearch', options);
50 facet.get('items').reset(null, options); 50 },
51 }); 51 resetParameters: function(options) {
52 _.invoke(this.values(), 'resetParameters', options);
52 }, 53 },
53 applyFacetResults: function(data, options) { 54 applyFacetResults: function(data, options) {
54 options = options || {}; 55 options = options || {};
......
...@@ -10,6 +10,9 @@ define(function(require) { ...@@ -10,6 +10,9 @@ define(function(require) {
10 fields: null, 10 fields: null,
11 multi: false 11 multi: false
12 }, 12 },
13 resetParameters: function(options) {
14 this.set({query: null, queries: []}, options);
15 },
13 }); 16 });
14 return QueryTextField; 17 return QueryTextField;
15 }); 18 });
......
...@@ -11,6 +11,13 @@ define(function(require) { ...@@ -11,6 +11,13 @@ define(function(require) {
11 11
12 //var module = require('module'); 12 //var module = require('module');
13 13
14 var QueryTextFields = Backbone.Model.extend({
15 initialize: function(data, options) {
16 },
17 resetParameters: function(options) {
18 _.invoke(this.values(), 'resetParameters', options);
19 },
20 });
14 var Solr = Pagination.extend({ 21 var Solr = Pagination.extend({
15 url: function url() { 22 url: function url() {
16 return this.constructor.selectUrl; 23 return this.constructor.selectUrl;
...@@ -25,7 +32,7 @@ define(function(require) { ...@@ -25,7 +32,7 @@ define(function(require) {
25 formNameMap[formName] = facet; 32 formNameMap[formName] = facet;
26 } 33 }
27 }); 34 });
28 var queryFields = new Backbone.Model(); 35 var queryFields = new QueryTextFields();
29 _.each(constructor.queryTextFields, function(definition, queryName) { 36 _.each(constructor.queryTextFields, function(definition, queryName) {
30 var qtf = new QueryTextField({formName: definition.formName, name: queryName, queries: [], fields: definition.fields, multi: !!definition.multi}); 37 var qtf = new QueryTextField({formName: definition.formName, name: queryName, queries: [], fields: definition.fields, multi: !!definition.multi});
31 var formName = qtf.get('formName'); 38 var formName = qtf.get('formName');
...@@ -49,13 +56,8 @@ define(function(require) { ...@@ -49,13 +56,8 @@ define(function(require) {
49 var skipOptions = {skipSearch: true}; 56 var skipOptions = {skipSearch: true};
50 var parts = document.location.href.match(/.*\?(.*)/); 57 var parts = document.location.href.match(/.*\?(.*)/);
51 var facets = this.get('facets'); 58 var facets = this.get('facets');
52 facets.resetSearch(); 59 facets.resetParameters(skipOptions);
53 _.each(this.get('queryFields').values(), function(qtf) { 60 this.get('queryFields').resetParameters(skipOptions);
54 qtf.set({
55 query: null,
56 queries: [],
57 }, skipOptions);
58 });
59 61
60 if (parts) { 62 if (parts) {
61 var formNameMap = this.get('formNameMap'); 63 var formNameMap = this.get('formNameMap');
......