Revised version of the resource page + related plugins
[myslice.git] / plugins / filter_status / static / js / filter_status.js
1 /**
2  * TestbedsPlugin: List of testbeds plugin
3  * Version:     0.1
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
10  * License:     GPLv3
11  */
12
13 (function($){
14
15     var FilterStatusPlugin = Plugin.extend({
16
17         /** 
18          * @brief Plugin constructor
19          * @param options : an associative array of setting values
20          * @param element : 
21          * @return : a jQuery collection of objects on which the plugin is
22          *     applied, which allows to maintain chainability of calls
23          */
24         init: function(options, element)
25         {
26             // Call the parent constructor, see FAQ when forgotten
27             this._super(options, element);
28
29             /* Setup query and record handlers */
30             this.listen_query(options.query_uuid);
31
32             /* Setup click handlers */
33             this.elts('list-group-item').click({'instance': this}, this._on_click);
34
35             this.prev_filter_status = null;
36         },
37
38     /**************************************************************************
39      *                            GUI MANAGEMENT                              *
40      **************************************************************************/
41
42         select_tab: function(tab)
43         {
44             this.elts('list-group-item').removeClass('active');
45             this.elmt(tab).addClass('active');
46         },
47
48     /**************************************************************************
49      *                            EVENT HANDLERS                              *
50      **************************************************************************/
51
52     // These functions are here to react on external filters, which we don't
53     // use at the moment
54
55     on_filter_added: function(filter) {
56         // XXX
57     },
58
59     on_filter_removed: function(filter) {
60         // XXX
61     },
62
63     /**************************************************************************
64      *                            PRIVATE METHODS                             *
65      **************************************************************************/
66
67         /**
68          * @brief : Click event handler
69          */
70         _on_click: function(e)
71         {
72             var filter_status;
73             var filter;
74
75             // A pointer to the plugin instance, since 'this' is overriden here
76             self = e.data.instance;
77
78
79             // Select the tab...
80             filter_status = this.dataset['status'];
81             self.select_tab(filter_status);
82
83             // ... and communicate the appropriate filters to the manager
84             // NOTE: we use the manifold namespace for internal filters 
85             if (self.prev_filter_status)
86                 manifold.raise_event(self.options.query_uuid, FILTER_REMOVED, self.prev_filter_status);
87
88             // XXX The datatables will be refreshed twice !
89             if (filter_status != 'all') {
90                 // No filter for 'all'
91                 var filter = ['manifold:status', '==', filter_status];
92                 manifold.raise_event(self.options.query_uuid, FILTER_ADDED, filter);
93             }
94
95             self.prev_filter_status = filter_status;
96         },
97
98     });
99
100     /* Plugin registration */
101     $.plugin('FilterStatusPlugin', FilterStatusPlugin);
102
103 })(jQuery);