Add a buildQueryParameters method, called just before a search request
is dispatched.
Showing
1 changed file
with
43 additions
and
0 deletions
... | @@ -101,6 +101,48 @@ define(function(require) { | ... | @@ -101,6 +101,48 @@ define(function(require) { |
101 | this.set(pagination, skipOptions); | 101 | this.set(pagination, skipOptions); |
102 | } | 102 | } |
103 | }, | 103 | }, |
104 | buildQueryParameters: function() { | ||
105 | var result = {}; | ||
106 | _.each(this.get('formNameMap'), function(impl, key) { | ||
107 | if (impl instanceof QueryTextField) { | ||
108 | var query = impl.get('query'); | ||
109 | if (query) { | ||
110 | result[key] = query; | ||
111 | } | ||
112 | } else if (impl.facetType === 'field' || impl.facetType === 'year') { | ||
113 | var min = impl.get('queryMin'); | ||
114 | var max = impl.get('queryMax'); | ||
115 | if (min !== undefined) { | ||
116 | result[key + '.min'] = min; | ||
117 | } | ||
118 | if (max !== undefined) { | ||
119 | result[key + '.min'] = max; | ||
120 | } | ||
121 | var checkedItems = []; | ||
122 | impl.get('items').each(function(item) { | ||
123 | if (item.get('checked')) { | ||
124 | checkedItems.push(item.get('key')); | ||
125 | } | ||
126 | }); | ||
127 | if (checkedItems.length) { | ||
128 | result[key + '.items'] = checkedItems; | ||
129 | } | ||
130 | } | ||
131 | }); | ||
132 | result['p'] = this.get('currentPage'); | ||
133 | result['sz'] = this.get('pageSize'); | ||
134 | var serializedQuery = _.map(result, function(value, key) { | ||
135 | if (_.isArray(value)) { | ||
136 | return _.map(value, function(item, index) { | ||
137 | return key + '=' + item; | ||
138 | }).join('&'); | ||
139 | } else { | ||
140 | return key + '=' + value; | ||
141 | } | ||
142 | }).join('&'); | ||
143 | this.set('serializedQuery', serializedQuery); | ||
144 | return this; | ||
145 | }, | ||
104 | initialize: function(data, options) { | 146 | initialize: function(data, options) { |
105 | options = (options || {}); | 147 | options = (options || {}); |
106 | this.set('options', new Backbone.Model({ | 148 | this.set('options', new Backbone.Model({ |
... | @@ -109,6 +151,7 @@ define(function(require) { | ... | @@ -109,6 +151,7 @@ define(function(require) { |
109 | showAll: !!options.showAll, | 151 | showAll: !!options.showAll, |
110 | })); | 152 | })); |
111 | this._doSearchImmediately = _.bind(function(options) { | 153 | this._doSearchImmediately = _.bind(function(options) { |
154 | this.buildQueryParameters(); | ||
112 | this.fetch(_.extend({}, options, { | 155 | this.fetch(_.extend({}, options, { |
113 | data: this.toJSON(), | 156 | data: this.toJSON(), |
114 | merge: false, | 157 | merge: false, | ... | ... |
-
Please register or sign in to post a comment