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.listen_query(options.query_uuid);
16 $("#clearFilters").click(function () {
17 manifold.raise_event(options.query_uuid, CLEAR_FILTERS);
21 // This should be provided in the API
22 // make_id_from_filter, etc
23 getOperatorLabel: function(op)
25 if (op == "=" || op == "==") {
27 } else if (op == "!=") {
29 } else if (op == ">") {
31 } else if (op == ">=") {
33 } else if (op == "<") {
35 } else if (op == "<=") {
42 // Visual actions on the component
44 clear_filters: function() {
45 $("#clearFilters").hide();
48 on_filter_added: function(filter) {
51 var value = filter[2];
52 var op_str = this.getOperatorLabel(op);
53 var id = 'filter_' + key + "_" + op_str;
55 // Add a button for a filter
56 $('#myActiveFilters').append("<div id='" + id + "' class='filterButton' style='float:left;margin-bottom:10px;'/>");
57 $('#' + id).append(key + op + value);
59 // Add a close button to remove the filter
60 $('#' + id).append("<img id='close-" + id + "' src='/all-static/img/details_close.png' class='closeButton' style='padding-left:3px;'/>");
61 // Add an event on click on the close button, call function removeFilter
62 $('#close-' + id).click(function(event) {
63 manifold.raise_event(options.query_uuid, FILTER_REMOVED, filter);
65 // If there are active filters, then show the clear filters button
66 $("#clearFilters").show();
69 on_filter_removed: function(filter) {
72 var value = filter[2];
73 var op_str = this.getOperatorLabel(op);
74 var id = 'filter_' + key + "_" + op_str;
77 // Count the number of filter _inside_ the current plugin
78 count = $('.filterButton', $('#myActiveFilters')).length;
80 jQuery("#clearFilters").hide();
84 on_filter_clear: function(filter) {
85 $("#clearFilters").hide();
90 $.plugin('ActiveFilters', ActiveFilters);