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.classname="active_filters";
15 this._super(options, element);
17 this.elts('closeButton').click(function() {
18 manifold.raise_event(options.query_uuid, FILTER_REMOVED, filter);
21 this.elmt('clearFilters').click(function () {
22 manifold.raise_event(options.query_uuid, CLEAR_FILTERS);
24 this.check_and_hide_clear_button();
26 this.listen_query(options.query_uuid);
30 // This should be provided in the API
31 // make_id_from_filter, etc
32 getOperatorLabel: function(op)
34 if (op == "=" || op == "==") {
36 } else if (op == "!=") {
38 } else if (op == ">") {
40 } else if (op == ">=") {
42 } else if (op == "<") {
44 } else if (op == "<=") {
51 show_clear_button: function()
53 this.elmt('clearFilters').show();
56 hide_clear_button: function()
58 this.elmt('clearFilters').hide();
61 check_and_hide_clear_button: function()
63 // Count the number of filter _inside_ the current plugin
64 var count = this.elts('filterButton').length;
65 if (count == 1) { // Including the template
66 this.elmt('clearFilters').hide();
70 clear_filters: function()
72 // XXX We need to remove all filter but template
73 this.hide_clear_button();
76 add_filter: function(filter)
78 var template = this.elmt('template').html();
80 id: this.id(this.id_from_filter(filter, false)),
81 span: this.str_from_filter(filter)
83 var output = Mustache.render(template, ctx);
85 this.elmt('myActiveFilters').append(output);
87 // Add an event on click on the close button, call function removeFilter
89 this.elts('closeButton').last().click(function() {
90 manifold.raise_event(self.options.query_uuid, FILTER_REMOVED, filter);
93 this.show_clear_button();
96 remove_filter: function(filter)
98 this.elmt(this.id_from_filter(filter, false)).remove();
99 this.check_and_hide_clear_button();
104 on_filter_added: function(filter) {
105 this.add_filter(filter);
108 on_filter_removed: function(filter) {
109 this.remove_filter(filter);
112 on_filter_clear: function(filter) {
113 this.clear_filters();
117 $.plugin('ActiveFilters', ActiveFilters);