06223e05 by Adam Heath

Add a buildQueryParameters method, called just before a search request

is dispatched.
1 parent 471a6435
......@@ -101,6 +101,48 @@ define(function(require) {
this.set(pagination, skipOptions);
}
},
buildQueryParameters: function() {
var result = {};
_.each(this.get('formNameMap'), function(impl, key) {
if (impl instanceof QueryTextField) {
var query = impl.get('query');
if (query) {
result[key] = query;
}
} else if (impl.facetType === 'field' || impl.facetType === 'year') {
var min = impl.get('queryMin');
var max = impl.get('queryMax');
if (min !== undefined) {
result[key + '.min'] = min;
}
if (max !== undefined) {
result[key + '.min'] = max;
}
var checkedItems = [];
impl.get('items').each(function(item) {
if (item.get('checked')) {
checkedItems.push(item.get('key'));
}
});
if (checkedItems.length) {
result[key + '.items'] = checkedItems;
}
}
});
result['p'] = this.get('currentPage');
result['sz'] = this.get('pageSize');
var serializedQuery = _.map(result, function(value, key) {
if (_.isArray(value)) {
return _.map(value, function(item, index) {
return key + '=' + item;
}).join('&');
} else {
return key + '=' + value;
}
}).join('&');
this.set('serializedQuery', serializedQuery);
return this;
},
initialize: function(data, options) {
options = (options || {});
this.set('options', new Backbone.Model({
......@@ -109,6 +151,7 @@ define(function(require) {
showAll: !!options.showAll,
}));
this._doSearchImmediately = _.bind(function(options) {
this.buildQueryParameters();
this.fetch(_.extend({}, options, {
data: this.toJSON(),
merge: false,
......