slicestat plugin: stats on the sliceview, top 10 nodes
[myslice.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             // Call the parent constructor, see FAQ when forgotten
27             this._super(options, element);                       
28                         
29                         
30             /* Member variables */
31
32             /* Plugin events */
33
34             /* Setup query and record handlers */
35
36             // Explain this will allow query events to be handled
37             // What happens when we don't define some events ?
38             // Some can be less efficient
39             this.listen_query(options.query_uuid);
40                         
41             /* GUI setup and event binding */
42             // call function
43                         if (typeof options.slicename != 'undefined') {
44                         options.slicename = options.slicename.replace("ple.","").replace(".","_");
45                 }
46                 if (typeof options.o == 'undefined') {
47                         //options.o = 'cpu';
48                 }
49                 
50                 this.elmt().on('show', options, this.on_show);
51         },
52
53         /* PLUGIN EVENTS */
54         // on_show like in hazelnut
55
56
57         /* GUI EVENTS */
58
59         // a function to bind events here: click change
60         // how to raise manifold events
61
62
63         /* GUI MANIPULATION */
64
65         // We advise you to write function to change behaviour of the GUI
66         // Will use naming helpers to access content _inside_ the plugin
67         // always refer to these functions in the remaining of the code
68
69         show_hide_button: function() 
70         {
71             // this.id, this.el, this.cl, this.elts
72             // same output as a jquery selector with some guarantees
73         },
74                 
75                 on_show: function(ev) 
76                 {
77                         $('iframe#' + ev.target.id + '-iframe').attr('src','http://plestats.planet-lab.eu/nodes.php?slice='+ev.data.slicename+'&order='+ev.data.o);
78                 },
79         /* TEMPLATES */
80
81         // see in the html template
82         // How to load a template, use of mustache
83
84         /* QUERY HANDLERS */
85
86         // How to make sure the plugin is not desynchronized
87         // He should manifest its interest in filters, fields or records
88         // functions triggered only if the proper listen is done
89
90         // no prefix
91
92         on_filter_added: function(filter)
93         {
94
95         },
96
97         // ... be sure to list all events here
98
99         /* RECORD HANDLERS */
100         on_new_record: function(record)
101         {
102                 $('iframe#' + this.elmt().attr('id') + '-iframe').attr('src','http://plestats.planet-lab.eu/node.php?node='+record.hostname);            
103         },
104
105         /* INTERNAL FUNCTIONS */
106         _dummy: function() {
107             // only convention, not strictly enforced at the moment
108         },
109
110     });
111
112     /* Plugin registration */
113     $.plugin('Slicestat', Slicestat);
114
115     // TODO Here use cases for instanciating plugins in different ways like in the pastie.
116
117 })(jQuery);