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);
31 this.listen_query(options.query_lease_uuid, 'leases');
33 /* Setup click handlers */
34 this.elts('list-group-item').click({'instance': this}, this._on_click);
36 this.prev_filter_status = null;
38 /* Initialize tooltips */
39 $("[rel='tooltip']").tooltip();
43 /**************************************************************************
45 **************************************************************************/
47 select_tab: function(tab)
49 this.elts('list-group-item').removeClass('active');
50 this.elmt(tab).addClass('active');
53 /**************************************************************************
55 **************************************************************************/
57 // These functions are here to react on external filters, which we don't
60 on_filter_added: function(filter)
65 on_filter_removed: function(filter)
70 on_leases_field_state_changed: function(data)
72 console.log('leases_field_state_changed');
73 this.on_field_state_changed(data);
75 on_field_state_changed: function(data)
82 /* Get the number of pending / unconfigured resources */
83 /* Let's store it in query_ext */
84 query_ext = manifold.query_store.find_analyzed_query_ext(this.options.query_uuid);
86 $('#badge-pending').text(query_ext.num_pending);
87 if (query_ext.num_pending > 0) {
88 $('#badge-pending').show();
90 $('#badge-pending').hide();
93 $('#badge-unconfigured').text(query_ext.num_unconfigured);
94 if (query_ext.num_unconfigured > 0) {
95 $('#badge-unconfigured').show();
97 $('#badge-unconfigured').hide();
104 /**************************************************************************
106 **************************************************************************/
109 * @brief : Click event handler
111 _on_click: function(e)
116 // A pointer to the plugin instance, since 'this' is overriden here
117 self = e.data.instance;
121 filter_status = this.dataset['status'];
122 self.select_tab(filter_status);
124 // ... and communicate the appropriate filters to the manager
125 // NOTE: we use the manifold namespace for internal filters
126 if (self.prev_filter_status) {
127 var filter = ['manifold:status', '==', self.prev_filter_status];
128 manifold.raise_event(self.options.query_uuid, FILTER_REMOVED, filter);
130 // XXX The datatables will be refreshed twice !
131 if (filter_status != 'all') {
132 // No filter for 'all'
133 var filter = ['manifold:status', '==', filter_status];
134 manifold.raise_event(self.options.query_uuid, FILTER_ADDED, filter);
137 self.prev_filter_status = filter_status;
142 /* Plugin registration */
143 $.plugin('FilterStatusPlugin', FilterStatusPlugin);