vigigraph / vigigraph / public / js / toolbar.js @ a128e1c2
History | View | Annotate | Download (8.83 KB)
1 |
Jx.Button.SelectorFlyout = new Class({
|
---|---|
2 |
Extends: Jx.Button.Flyout,
|
3 |
|
4 |
initialize: function (options, url, hostid) { |
5 |
this.idselection = null; |
6 |
this.tree = new TreeGroup({ |
7 |
title: this.options.label, |
8 |
url: url,
|
9 |
hostid: hostid
|
10 |
}); |
11 |
options.content = this.tree.container;
|
12 |
this.parent(options);
|
13 |
this.tree.addEvent('select', this.selectItem.bind(this)); |
14 |
|
15 |
// On adapte la fenêtre popup aux dépliements de l'arbre
|
16 |
var adaptPopup = function(e) { |
17 |
if (!this.options.active) return; |
18 |
// On évite le scrolling dans le menu popup
|
19 |
var size_x = this.content.getSize().x; |
20 |
var scroll_size_x = this.content.getScrollSize().x; |
21 |
if (scroll_size_x > size_x) {
|
22 |
this.content.setStyle("width", scroll_size_x + 10); |
23 |
// 10: padding-right du div
|
24 |
} |
25 |
// On adapte la bordure ombrée
|
26 |
this.contentContainer.setContentBoxSize(
|
27 |
$(this.content).getMarginBoxSize()); |
28 |
}; |
29 |
this.tree.addEvent("branchloaded", adaptPopup.bind(this)); |
30 |
this.tree.addEvent("nodedisclosed", adaptPopup.bind(this)); |
31 |
|
32 |
}, |
33 |
|
34 |
setItem: function (idselection, label) { |
35 |
this.idselection = idselection;
|
36 |
this.setLabel(label);
|
37 |
this.fireEvent("select", [idselection, label]); |
38 |
}, |
39 |
|
40 |
selectItem: function (item) { |
41 |
this.setItem(item.options.data, item.options.label);
|
42 |
this.hide();
|
43 |
}, |
44 |
|
45 |
//clicked: function (e) {
|
46 |
// if (!this.options.enabled)
|
47 |
// return;
|
48 |
// this.tree.selectGroup();
|
49 |
//},
|
50 |
|
51 |
redraw: function() { |
52 |
this.tree.redraw();
|
53 |
} |
54 |
}); |
55 |
|
56 |
var Toolbar = new Class({ |
57 |
initialize: function () { |
58 |
this.jxtoolbar = new Jx.Toolbar({ |
59 |
parent: $('toolbar') |
60 |
}); |
61 |
|
62 |
this.global_refresh = new Jx.Button({ |
63 |
label: _('Refresh'), |
64 |
tooltip: _('Globally change auto-refresh setting'), |
65 |
//image: app_path + 'images/refresh-all.png',
|
66 |
image: app_path + 'images/refresh.png', |
67 |
toggle: true, |
68 |
onDown: function () { |
69 |
window.graphs.each(function (graph) {
|
70 |
graph.refresh_button.setActive(1);
|
71 |
}, this.global_refresh);
|
72 |
}.bind(this),
|
73 |
onUp: function () { |
74 |
window.graphs.each(function (graph) {
|
75 |
graph.refresh_button.setActive(0);
|
76 |
}, this.global_refresh);
|
77 |
}.bind(this)
|
78 |
}); |
79 |
|
80 |
this.host_label = new Jx.Toolbar.Item(this.createLabel(_('Host:'))); |
81 |
|
82 |
this.host_picker = new Jx.Button.SelectorFlyout({ |
83 |
label: _('Select a host'), |
84 |
tooltip: _('Click me to select another host'), |
85 |
}, |
86 |
app_path + 'rpc/hosttree',
|
87 |
null
|
88 |
); |
89 |
|
90 |
this.host_picker.addEvent("select", function() { |
91 |
var idselection = this.host_picker.idselection; |
92 |
if (this.graph_picker.tree.options.hostid != idselection) { |
93 |
this.graph_picker.tree.options.hostid = idselection;
|
94 |
this.graph_picker.tree.redraw();
|
95 |
this.graph_picker.setItem(null, this.graph_picker.options.label); |
96 |
} |
97 |
this.show_nagios.setEnabled(1); |
98 |
this.graph_picker.setEnabled(1); |
99 |
}.bind(this));
|
100 |
|
101 |
this.show_nagios = new Jx.Button({ |
102 |
label: _('Nagios page'), |
103 |
tooltip: _('Display Nagios page for the selected host'), |
104 |
image: app_path + 'images/nagios-16.png', |
105 |
toggle: false, |
106 |
enabled: false, |
107 |
onClick: function () { |
108 |
var uri = new URI( |
109 |
app_path + 'nagios/' +
|
110 |
encodeURIComponent(this.host_picker.getLabel()) +
|
111 |
'/cgi-bin/status.cgi'
|
112 |
); |
113 |
uri.setData({ |
114 |
host: this.host_picker.getLabel(), |
115 |
style: 'detail', |
116 |
supNav: 1 |
117 |
}); |
118 |
window.open(uri.toString()); |
119 |
}.bind(this)
|
120 |
}) |
121 |
|
122 |
this.graph_label = new Jx.Toolbar.Item(this.createLabel(_('Graph:'))); |
123 |
|
124 |
this.graph_picker = new Jx.Button.SelectorFlyout({ |
125 |
label: _('Select a graph'), |
126 |
tooltip: _('Click me to select another graph'), |
127 |
enabled: false |
128 |
}, |
129 |
app_path + 'rpc/graphtree',
|
130 |
null
|
131 |
); |
132 |
|
133 |
this.graph_picker.addEvent("select", function (idselection, label) { |
134 |
if (idselection !== null) { |
135 |
//this.show_graph.setEnabled(1);
|
136 |
new Graph(
|
137 |
{autoRefresh: this.global_refresh.isActive() ? 1 : 0}, |
138 |
this.host_picker.getLabel(),
|
139 |
this.graph_picker.getLabel()
|
140 |
); |
141 |
} |
142 |
}.bind(this));
|
143 |
|
144 |
this.show_graph = new Jx.Button({ |
145 |
label: _('Graph'), |
146 |
tooltip: _('Display the contents of the selected graph'), |
147 |
toggle: false, |
148 |
enabled: false, |
149 |
onClick: function () { |
150 |
new Graph(
|
151 |
{autoRefresh: this.global_refresh.isActive() ? 1 : 0}, |
152 |
this.host_picker.getLabel(),
|
153 |
this.graph_picker.getLabel()
|
154 |
); |
155 |
}.bind(this)
|
156 |
}) |
157 |
|
158 |
// Remplissage de la barre d'outils
|
159 |
this.jxtoolbar.add(this.global_refresh); |
160 |
this.jxtoolbar.add(this.show_nagios); |
161 |
this.jxtoolbar.add(new Jx.Toolbar.Separator()); |
162 |
this.jxtoolbar.add(this.host_label); // à supprimer ? |
163 |
this.jxtoolbar.add(this.host_picker); |
164 |
this.jxtoolbar.add(new Jx.Toolbar.Separator()); |
165 |
this.jxtoolbar.add(this.graph_label); // à supprimer ? |
166 |
this.jxtoolbar.add(this.graph_picker); |
167 |
//this.jxtoolbar.add(this.show_graph);
|
168 |
|
169 |
// Vérification de la date de dernière modification en base, et
|
170 |
// rechargement des arbres le cas échéant
|
171 |
this.loadtime = new Date(); |
172 |
this.req_expiration = new Request.JSON({ |
173 |
method: "get", |
174 |
url: app_path + "rpc/dbmtime", |
175 |
onSuccess: function(result){ |
176 |
if (!result) return; |
177 |
var mtime = Date.parse(result.mtime);
|
178 |
if ((toolbar.loadtime - mtime) >= 0) return; |
179 |
// la base a changé, on recharge les arbres
|
180 |
toolbar.host_picker.tree.redraw(); |
181 |
toolbar.graph_picker.tree.redraw(); |
182 |
// @todo: En théorie on devrait aussi vérifier que l'élément
|
183 |
// sélectionné existe dans l'arbre, mais c'est un peu compliqué
|
184 |
// avec le chargement dynamique. Il faudrait faire une requête
|
185 |
// spécifique
|
186 |
toolbar.loadtime = new Date();
|
187 |
} |
188 |
}); |
189 |
this.req_expiration.send.periodical(30 * 1000, this.req_expiration); |
190 |
}, |
191 |
|
192 |
// Retourne un objet opaque qui possède un label,
|
193 |
// et peut être ajouté à une Jx.Toolbar via Jx.Toolbar.Item.
|
194 |
createLabel: function (label) { |
195 |
var container, content, span;
|
196 |
|
197 |
container = new Element('div', {'class': 'jxButtonContainer'}); |
198 |
content = new Element('span', {'class': 'jxButtonContent'}); |
199 |
span = new Element('span', { |
200 |
'class': 'jxButtonLabel', |
201 |
text: label
|
202 |
}); |
203 |
span.setStyles({cursor: 'default'}); |
204 |
|
205 |
span.inject(content); |
206 |
content.inject(container); |
207 |
|
208 |
return container;
|
209 |
}, |
210 |
|
211 |
// Vérifie si la base a changé, et recharge les sélecteurs en conséquence
|
212 |
checkExpiration: function() { |
213 |
if (!this.req_expiration) { // ne creer qu'une instance |
214 |
this.req_expiration = new Request.JSON({ |
215 |
method: "get", |
216 |
url: app_path + "rpc/dbmtime", |
217 |
onSuccess: function(result){ |
218 |
if (!result) return; |
219 |
var mtime = Date.parse(result.mtime);
|
220 |
if ((toolbar.loadtime - mtime) >= 0) return; |
221 |
// la base a changé, on recharge les arbres
|
222 |
if (toolbar.host_picker.idselection) {
|
223 |
toolbar.host_picker.tree.redraw(); |
224 |
} |
225 |
if (toolbar.graph_picker.idselection) {
|
226 |
toolbar.graph_picker.tree.redraw(); |
227 |
} |
228 |
// @todo: En théorie on devrait aussi vérifier que
|
229 |
// l'élément sélectionné existe dans l'arbre, mais c'est un
|
230 |
// peu compliqué avec le chargement dynamique. Il faudrait
|
231 |
// faire une requête spécifique
|
232 |
toolbar.loadtime = new Date();
|
233 |
} |
234 |
}); |
235 |
} |
236 |
this.req_expiration.send();
|
237 |
} |
238 |
}); |
239 |
|
240 |
toolbar = null;
|
241 |
window.addEvent('load', function () { |
242 |
window.toolbar = new Toolbar();
|
243 |
}); |