2 * Description: ActiveFilters plugin
3 * Copyright (c) 2012-2013 UPMC Sorbonne Universite
7 // NOTE: We are not making use of element, but this.elmt() instead...
11 var ActiveFilters = Plugin.extend({
13 init: function(options, element) {
14 this._super(options, element);
16 this.elts('closeButton').click(function() {
17 manifold.raise_event(options.query_uuid, FILTER_REMOVED, filter);
20 this.elmt('clearFilters').click(function () {
21 manifold.raise_event(options.query_uuid, CLEAR_FILTERS);
23 this.check_and_hide_clear_button();
25 this.listen_query(options.query_uuid);
29 // This should be provided in the API
30 // make_id_from_filter, etc
31 getOperatorLabel: function(op)
33 if (op == "=" || op == "==") {
35 } else if (op == "!=") {
37 } else if (op == ">") {
39 } else if (op == ">=") {
41 } else if (op == "<") {
43 } else if (op == "<=") {
50 show_clear_button: function()
52 this.elmt('clearFilters').show();
55 hide_clear_button: function()
57 this.elmt('clearFilters').hide();
60 check_and_hide_clear_button: function()
62 // Count the number of filter _inside_ the current plugin
63 var count = this.elts('filterButton').length;
64 if (count == 1) { // Including the template
65 this.elmt('clearFilters').hide();
69 clear_filters: function()
71 // XXX We need to remove all filter but template
72 this.hide_clear_button();
75 add_filter: function(filter)
77 var template = this.elmt('template').html();
79 id: this.id(this.id_from_filter(filter, false)),
80 span: this.str_from_filter(filter)
82 var output = Mustache.render(template, ctx);
84 this.elmt('myActiveFilters').append(output);
86 // Add an event on click on the close button, call function removeFilter
88 this.elts('closeButton').last().click(function() {
89 manifold.raise_event(self.options.query_uuid, FILTER_REMOVED, filter);
92 this.show_clear_button();
95 remove_filter: function(filter)
97 this.elmt(this.id_from_filter(filter, false)).remove();
98 this.check_and_hide_clear_button();
103 on_filter_added: function(filter) {
104 this.add_filter(filter);
107 on_filter_removed: function(filter) {
108 this.remove_filter(filter);
111 on_filter_clear: function(filter) {
112 this.clear_filters();
116 $.plugin('ActiveFilters', ActiveFilters);