2 * Description: ActiveFilters plugin
3 * Copyright (c) 2012-2013 UPMC Sorbonne Universite
9 var ActiveFilters = Plugin.extend({
11 init: function(options, element) {
12 this._super(options, element);
14 this.els('closeButton').click(function() {
15 manifold.raise_event(options.query_uuid, FILTER_REMOVED, filter);
18 this.el('clearFilters').click(function () {
19 manifold.raise_event(options.query_uuid, CLEAR_FILTERS);
21 this.check_and_hide_clear_button();
23 this.listen_query(options.query_uuid);
27 // This should be provided in the API
28 // make_id_from_filter, etc
29 getOperatorLabel: function(op)
31 if (op == "=" || op == "==") {
33 } else if (op == "!=") {
35 } else if (op == ">") {
37 } else if (op == ">=") {
39 } else if (op == "<") {
41 } else if (op == "<=") {
48 show_clear_button: function()
50 this.el('clearFilters').show();
53 hide_clear_button: function()
55 this.el('clearFilters').hide();
58 check_and_hide_clear_button: function()
60 // Count the number of filter _inside_ the current plugin
61 var count = this.els('filterButton').length;
62 if (count == 1) { // Including the template
63 jQuery("#clearFilters").hide();
67 clear_filters: function()
69 // XXX We need to remove all filter but template
70 this.hide_clear_button();
73 add_filter: function(filter)
75 var template = this.el('template').html();
77 id: this.id(this.id_from_filter(filter, false)),
78 span: this.str_from_filter(filter)
80 var output = Mustache.render(template, ctx);
82 this.el('myActiveFilters').append(output);
84 // Add an event on click on the close button, call function removeFilter
86 this.els('closeButton').last().click(function() {
87 manifold.raise_event(self.options.query_uuid, FILTER_REMOVED, filter);
90 this.show_clear_button();
93 remove_filter = function(filter)
95 this.el(this.id_from_filter(filter, false)).remove();
96 this.check_and_hide_clear_button();
101 on_filter_added: function(filter) {
102 this.add_filter(filter);
105 on_filter_removed: function(filter) {
106 this.remove_filter(filter);
109 on_filter_clear: function(filter) {
110 this.clear_filters();
114 $.plugin('ActiveFilters', ActiveFilters);