2 * TestbedsPlugin: List of testbeds plugin
4 * Description: TODO -> generalize to a list of possible filters
5 * This file is part of the Manifold project
6 * Requires: js/plugin.js
7 * URL: http://www.myslice.info
8 * Author: Loïc Baron <loic.baron@lip6.fr>
9 * Copyright: Copyright 2012-2013 UPMC Sorbonne Universités
15 var FilterStatusPlugin = Plugin.extend({
18 * @brief Plugin constructor
19 * @param options : an associative array of setting values
21 * @return : a jQuery collection of objects on which the plugin is
22 * applied, which allows to maintain chainability of calls
24 init: function(options, element)
26 // Call the parent constructor, see FAQ when forgotten
27 this._super(options, element);
29 /* Setup query and record handlers */
30 this.listen_query(options.query_uuid);
32 /* Setup click handlers */
33 this.elts('list-group-item').click({'instance': this}, this._on_click);
35 this.prev_filter_status = null;
37 /* Initialize tooltips */
38 $("[rel='tooltip']").tooltip();
42 /**************************************************************************
44 **************************************************************************/
46 select_tab: function(tab)
48 this.elts('list-group-item').removeClass('active');
49 this.elmt(tab).addClass('active');
52 /**************************************************************************
54 **************************************************************************/
56 // These functions are here to react on external filters, which we don't
59 on_filter_added: function(filter)
64 on_filter_removed: function(filter)
69 on_field_state_changed: function(data)
73 switch (data.status) {
75 /* Get the number of pending / unconfigured resources */
76 /* Let's store it in query_ext */
77 query_ext = manifold.query_store.find_analyzed_query_ext(this.options.query_uuid);
79 $('#badge-pending').text(query_ext.num_pending);
80 if (query_ext.num_pending > 0) {
81 $('#badge-pending').show();
83 $('#badge-pending').hide();
86 $('#badge-unconfigured').text(query_ext.num_unconfigured);
87 if (query_ext.num_unconfigured > 0) {
88 $('#badge-unconfigured').show();
90 $('#badge-unconfigured').hide();
97 /**************************************************************************
99 **************************************************************************/
102 * @brief : Click event handler
104 _on_click: function(e)
109 // A pointer to the plugin instance, since 'this' is overriden here
110 self = e.data.instance;
114 filter_status = this.dataset['status'];
115 self.select_tab(filter_status);
117 // ... and communicate the appropriate filters to the manager
118 // NOTE: we use the manifold namespace for internal filters
119 if (self.prev_filter_status)
120 manifold.raise_event(self.options.query_uuid, FILTER_REMOVED, self.prev_filter_status);
122 // XXX The datatables will be refreshed twice !
123 if (filter_status != 'all') {
124 // No filter for 'all'
125 var filter = ['manifold:status', '==', filter_status];
126 manifold.raise_event(self.options.query_uuid, FILTER_ADDED, filter);
129 self.prev_filter_status = filter_status;
134 /* Plugin registration */
135 $.plugin('FilterStatusPlugin', FilterStatusPlugin);