forked from evolvingweb/ajax-solr
/
CurrentSearchWidget.q.js
50 lines (43 loc) · 1.25 KB
/
CurrentSearchWidget.q.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
(function ($) {
AjaxSolr.CurrentSearchWidget = AjaxSolr.AbstractWidget.extend({
afterRequest: function () {
var self = this;
var links = [];
var q = this.manager.store.get('q').val();
if (q != '*:*') {
links.push($('<a href="#"/>').text('(x) ' + q).click(function () {
self.manager.store.get('q').val('*:*');
self.manager.doRequest(0);
return false;
}));
}
var fq = this.manager.store.values('fq');
for (var i = 0, l = fq.length; i < l; i++) {
links.push($('<a href="#"/>').text('(x) ' + fq[i]).click(self.removeFacet(fq[i])));
}
if (links.length > 1) {
links.unshift($('<a href="#"/>').text('remove all').click(function () {
self.manager.store.get('q').val('*:*');
self.manager.store.remove('fq');
self.manager.doRequest(0);
return false;
}));
}
if (links.length) {
AjaxSolr.theme('list_items', this.target, links);
}
else {
$(this.target).html('<div>Viewing all documents!</div>');
}
},
removeFacet: function (facet) {
var self = this;
return function () {
if (self.manager.store.removeByValue('fq', facet)) {
self.manager.doRequest(0);
}
return false;
};
}
});
})(jQuery);