a55a79732f91d4c064f3667b74ed84301d83bd6a
[unfold.git] / plugins / slicestat / static / js / slicestat.js
1 /**
2  * MyPlugin:    demonstration plugin
3  * Version:     0.1
4  * Description: Template for writing new plugins and illustrating the different
5  *              possibilities of the plugin API.
6  *              This file is part of the Manifold project 
7  * Requires:    js/plugin.js
8  * URL:         http://www.myslice.info
9  * Author:      Jordan AugĂ© <jordan.auge@lip6.fr>
10  * Copyright:   Copyright 2012-2013 UPMC Sorbonne UniversitĂ©s
11  * License:     GPLv3
12  */
13
14 (function($){
15
16     var SliceStat = Plugin.extend({
17
18         /** XXX to check
19          * @brief Plugin constructor
20          * @param options : an associative array of setting values
21          * @param element : 
22          * @return : a jQuery collection of objects on which the plugin is
23          *     applied, which allows to maintain chainability of calls
24          */
25         init: function(options, element) {
26             this.classname="slicestat";
27             // Call the parent constructor, see FAQ when forgotten
28             this._super(options, element);                       
29                         
30                         
31             /* Member variables */
32
33             /* Plugin events */
34
35             /* Setup query and record handlers */
36
37             // Explain this will allow query events to be handled
38             // What happens when we don't define some events ?
39             // Some can be less efficient
40             this.listen_query(options.query_uuid);
41                         
42             /* GUI setup and event binding */
43             // call function
44                         if (typeof options.slicename != 'undefined') {
45                         options.slicename = options.slicename.replace("ple.","").replace(".","_");
46                 }
47                 if (typeof options.o == 'undefined') {
48                         //options.o = 'cpu';
49                 }
50                 
51                 this.elmt().on('show', options, this.on_show);
52         },
53
54         /* PLUGIN EVENTS */
55         // on_show like in querytable
56
57
58         /* GUI EVENTS */
59
60         // a function to bind events here: click change
61         // how to raise manifold events
62
63
64         /* GUI MANIPULATION */
65
66         // We advise you to write function to change behaviour of the GUI
67         // Will use naming helpers to access content _inside_ the plugin
68         // always refer to these functions in the remaining of the code
69
70         show_hide_button: function() 
71         {
72             // this.id, this.el, this.cl, this.elts
73             // same output as a jquery selector with some guarantees
74         },
75                 
76                 on_show: function(ev) 
77                 {
78                         $('iframe#' + ev.target.id + '-iframe').attr('src','http://plestats.planet-lab.eu/nodes.php?slice='+ev.data.slicename+'&order='+ev.data.o);
79                 },
80         /* TEMPLATES */
81
82         // see in the html template
83         // How to load a template, use of mustache
84
85         /* QUERY HANDLERS */
86
87         // How to make sure the plugin is not desynchronized
88         // He should manifest its interest in filters, fields or records
89         // functions triggered only if the proper listen is done
90
91         // no prefix
92
93         on_filter_added: function(filter)
94         {
95
96         },
97
98         // ... be sure to list all events here
99
100         /* RECORD HANDLERS */
101         on_new_record: function(record)
102         {
103                 $('iframe#' + this.elmt().attr('id') + '-iframe').attr('src','http://plestats.planet-lab.eu/node.php?node='+record.hostname);            
104         },
105
106         /* INTERNAL FUNCTIONS */
107         _dummy: function() {
108             // only convention, not strictly enforced at the moment
109         },
110
111     });
112
113     /* Plugin registration */
114     $.plugin('SliceStat', SliceStat);
115
116     // TODO Here use cases for instanciating plugins in different ways like in the pastie.
117
118 })(jQuery);