root / ui / templates / list.html @ 038383b1
History | View | Annotate | Download (10.5 kB)
1 |
{% load i18n %} |
---|---|
2 |
|
3 |
<div id="machinesview" class="list"> |
4 |
<div id="spinner"></div> |
5 |
<div class="actions"> |
6 |
<a id="action-start">Start</a> |
7 |
<a id="action-reboot">Reboot</a> |
8 |
<a id="action-shutdown">Shutdown</a> |
9 |
<br /> |
10 |
<a id="action-destroy">Destroy</a> |
11 |
<br /> |
12 |
<a id="action-details">Show Details</a> |
13 |
<a id="action-group">Add to group</a> |
14 |
<br /> |
15 |
<a id="action-band">Out of band</a> |
16 |
<br /> |
17 |
<a id="action-attach">Attach disk</a> |
18 |
<a id="action-detach">Detach disk</a> |
19 |
<br /> |
20 |
<a id="action-connect">Connect to network</a> |
21 |
<a id="action-disconnect">Disconnect from net</a> |
22 |
</div>
|
23 |
<table class="list-machines" style="display: none"> |
24 |
<thead>
|
25 |
<tr>
|
26 |
<th id="selection" class="select-running"> |
27 |
<input type="checkbox"/> |
28 |
<div class="expand-icon"></div> |
29 |
</th>
|
30 |
<th id="os">OS</th> |
31 |
<th id="name">Name</th> |
32 |
<th id="ip">IP</th> |
33 |
<th id="group">Group</th> |
34 |
<th id="status">Status</th> |
35 |
</tr>
|
36 |
</thead>
|
37 |
<tbody class="machines"></tbody> |
38 |
</table>
|
39 |
<ul class="dropdown-selector" style="display: none"> |
40 |
<li class="select-all" ><a href="#">all</a></li> |
41 |
<li class="select-none"><a href="#">none</a></li> |
42 |
<li class="select-group"><a href="#">group</a></li> |
43 |
</ul>
|
44 |
</div>
|
45 |
|
46 |
<script>
|
47 |
|
48 |
// select/deselect all from checkbox widget of table headers
|
49 |
$("table thead tr th#selection :checkbox").live('change', function() {
|
50 |
if ( $(this).is(":checked") ) {
|
51 |
$(":checkbox").attr("checked", true);
|
52 |
}
|
53 |
else {
|
54 |
$(":checkbox").attr("checked", false);
|
55 |
}
|
56 |
updateActions();
|
57 |
return false;
|
58 |
});
|
59 |
|
60 |
// select all from drop down menu
|
61 |
$("ul.dropdown-selector li.select-all a").live('click', function() {
|
62 |
$(":checkbox").attr("checked", true);
|
63 |
$(".dropdown-selector").slideToggle('medium');
|
64 |
updateActions();
|
65 |
return false;
|
66 |
});
|
67 |
|
68 |
// select none from drop down menu
|
69 |
$("ul.dropdown-selector li.select-none a").live('click', function() {
|
70 |
$(":checkbox").attr("checked", false);
|
71 |
$(".dropdown-selector").slideToggle('medium');
|
72 |
updateActions();
|
73 |
return false;
|
74 |
});
|
75 |
|
76 |
// select group from drop down menu
|
77 |
$("ul.dropdown-selector li.select-group a").live('click', function() {
|
78 |
$(":checkbox").attr("checked", true);
|
79 |
$(".dropdown-selector").slideToggle('medium');
|
80 |
updateActions();
|
81 |
return false;
|
82 |
});
|
83 |
|
84 |
// menu toggle, running menu
|
85 |
$("table.list-machines thead tr th#selection .expand-icon").click( function (obj) {
|
86 |
$(".dropdown-selector").slideToggle('medium');
|
87 |
return false;
|
88 |
});
|
89 |
|
90 |
// TODO: This should be populated with more rules for all available states
|
91 |
var actions = { 'reboot': ['ACTIVE', 'REBOOT', 'multiple'],
|
92 |
'shutdown': ['ACTIVE', 'REBOOT', 'multiple'],
|
93 |
'connect': ['ACTIVE', ],
|
94 |
'disconnect': ['ACTIVE', 'network'],
|
95 |
'band': ['ACTIVE', 'REBOOT'],
|
96 |
'details': ['ACTIVE', 'REBOOT', 'STOPPED'],
|
97 |
'start': ['STOPPED', 'multiple'],
|
98 |
'destroy': ['ACTIVE', 'STOPPED', 'REBOOT', 'ERROR', 'multiple'],
|
99 |
'group': ['ACTIVE', 'STOPPED', 'REBOOT','multiple'],
|
100 |
};
|
101 |
|
102 |
// on checkbox click, update the actions
|
103 |
$("tbody input[type='checkbox']").live('change', function() {
|
104 |
updateActions();
|
105 |
pending_actions = [];
|
106 |
$(".selected").removeClass('selected');
|
107 |
update_confirmations();
|
108 |
});
|
109 |
|
110 |
$("div.confirm_multiple button").click(function() {
|
111 |
$(".selected").removeClass('selected');
|
112 |
});
|
113 |
|
114 |
// destroy action
|
115 |
$("a.enabled#action-destroy").live('click', function() {
|
116 |
var checked = $("table.list-machines tbody input[type='checkbox']:checked");
|
117 |
$(".selected").removeClass('selected');
|
118 |
$(this).addClass('selected');
|
119 |
pending_actions = []; // reset pending actions
|
120 |
checked.each(function(i,c) {
|
121 |
serverID=c.id;
|
122 |
serverName = $('#'+serverID+' span.name').text();
|
123 |
pending_actions.push([destroy, serverID]);
|
124 |
});
|
125 |
update_confirmations();
|
126 |
return false;
|
127 |
});
|
128 |
|
129 |
$("a.enabled#action-reboot").live('click', function() {
|
130 |
var checked = $("table.list-machines tbody input[type='checkbox']:checked");
|
131 |
$(".selected").removeClass('selected');
|
132 |
$(this).addClass('selected');
|
133 |
pending_actions = []; // reset pending actions
|
134 |
checked.each(function(i,c) {
|
135 |
serverID=c.id;
|
136 |
serverName = $('#'+serverID+' span.name').text();
|
137 |
pending_actions.push([reboot, serverID]);
|
138 |
});
|
139 |
update_confirmations();
|
140 |
return false;
|
141 |
});
|
142 |
|
143 |
$("a.enabled#action-start").live('click', function() {
|
144 |
var checked = $("table.list-machines tbody input[type='checkbox']:checked");
|
145 |
$(".selected").removeClass('selected');
|
146 |
$(this).addClass('selected');
|
147 |
pending_actions = []; // reset pending actions
|
148 |
checked.each(function(i,c) {
|
149 |
serverID=c.id;
|
150 |
serverName = $('#'+serverID+' span.name').text();
|
151 |
pending_actions.push([start, serverID]);
|
152 |
});
|
153 |
update_confirmations();
|
154 |
return false;
|
155 |
});
|
156 |
|
157 |
$("a.enabled#action-shutdown").live('click', function() {
|
158 |
var checked = $("table.list-machines tbody input[type='checkbox']:checked");
|
159 |
$(".selected").removeClass('selected');
|
160 |
$(this).addClass('selected');
|
161 |
pending_actions = []; // reset pending actions
|
162 |
checked.each(function(i,c) {
|
163 |
serverID=c.id;
|
164 |
serverName = $('#'+serverID+' span.name').text();
|
165 |
pending_actions.push([shutdown, serverID]);
|
166 |
});
|
167 |
update_confirmations();
|
168 |
return false;
|
169 |
});
|
170 |
|
171 |
function update_machines_view(data){
|
172 |
/*
|
173 |
Go through the servers in the input data. Update existing entries, add
|
174 |
new ones to the list
|
175 |
*/
|
176 |
tableData = vmTable.fnGetData();
|
177 |
$.each(data.servers, function(i,server){
|
178 |
current = -1;
|
179 |
// check server status to select the appropriate OS icon
|
180 |
osTag = image_tags[server.imageRef]
|
181 |
var osIcon = osTag + ".png", imgStr, imgSrc;
|
182 |
|
183 |
// check if the server already exists in the datatable
|
184 |
tableData.forEach(function(row,index){
|
185 |
|
186 |
if (row[0].split(' ')[2].replace('id=','') == server.id){
|
187 |
current = index;
|
188 |
}
|
189 |
});
|
190 |
|
191 |
if (current != -1){ // if it's there, simply update the values
|
192 |
try {
|
193 |
console.info(server.name + ' from '
|
194 |
+ tableData[current][5] + ' to ' + STATUS_MESSAGES[server.status]);
|
195 |
} catch(err) {}
|
196 |
if (server.status == "DELETED") {
|
197 |
vmTable.fnDeleteRow(current);
|
198 |
} else { // server exists and should not be deleted
|
199 |
// check server status to select the appropriate OS icon
|
200 |
if (['ERROR', 'STOPPED'].indexOf(server.status) >= 0) {
|
201 |
osIcon = osTag + "-off.png";
|
202 |
}
|
203 |
// if the new state does not differ from the previous one
|
204 |
if (tableData[current][5].indexOf(STATUS_MESSAGES[server.status]) > -1){
|
205 |
// do nothing
|
206 |
} else { // state has changed
|
207 |
//$('#'+server.id).parent().parent().find('.list-logo').attr('src').indexOf('wave')>-1){
|
208 |
|
209 |
imgSrc = "static/wave.gif";
|
210 |
tableData[current][0] = "<input class="+server.status+" id="+server.id+" type=checkbox>";
|
211 |
imgStr = "<img class=list-logo src=" + imgSrc + " title=" + osTag + " height=16 width=16 />";
|
212 |
tableData[current][1] = "<span class=imagetag>" + osTag + "</span>" + imgStr;
|
213 |
tableData[current][2] = "<a class=name><span class=name>" + server.name + "</span></a>";
|
214 |
tableData[current][3] = "<a class=ip><span class=public>"+ server.addresses.public.ip.addr + "</span></a>";
|
215 |
//tableData[current][4] = "group"; //TODO
|
216 |
tableData[current][5] = "<span class=status>" + STATUS_MESSAGES[server.status] + "</span>";
|
217 |
vmTable.fnUpdate(tableData[current],current);
|
218 |
|
219 |
//try{console.info('vm ' + server.id + ' from ' + tableData[current][5] + ' to ' + STATUS_MESSAGES[server.status])} catch(err) {}
|
220 |
setTimeout("$('#"+server.id+"').parent().parent().find('.list-logo').attr('src','static/os_logos/" + osIcon+"')", 2000);
|
221 |
}
|
222 |
}
|
223 |
updateActions();
|
224 |
} else if (server.status != "DELETED") { // does not exist, we should create it
|
225 |
// check server status to select the appropriate OS icon
|
226 |
if (['ERROR', 'STOPPED'].indexOf(server.status) >= 0) {
|
227 |
osIcon = osTag + "-off.png";
|
228 |
}
|
229 |
// add new row to the table
|
230 |
vmTable.fnAddData([
|
231 |
"<input class=" + server.status + " id=" + server.id + " type=checkbox>",
|
232 |
"<span class=imagetag>" + osTag + "</span><img class=list-logo src=static/os_logos/" + osIcon +
|
233 |
" title=" + osTag + " height=16 width=16>",
|
234 |
"<a class=name><span class=name>" + server.name + "</span></a>",
|
235 |
"<a class=ip><span class=public>"+ server.addresses.public.ip.addr + "</span></a>",
|
236 |
"group",
|
237 |
"<span class=status>" + STATUS_MESSAGES[server.status] + "</span>"
|
238 |
]);
|
239 |
}
|
240 |
});
|
241 |
updateActions();
|
242 |
$("#spinner").hide();
|
243 |
// in case there are no data, leave the page empty
|
244 |
if ($("div.list table.list-machines tbody").length > 0) {
|
245 |
$("div.list div.dataTables_filter").show();
|
246 |
$("div.list div.dataTables_filter input").show();
|
247 |
$("div.list table.list-machines").show();
|
248 |
$("div.list div.actions").show();
|
249 |
}
|
250 |
|
251 |
// set confirm box position
|
252 |
if (window.innerHeight - 200 < $('#machinesview').height())
|
253 |
$('.confirm_multiple').addClass('fixed');
|
254 |
else
|
255 |
$('.confirm_multiple').removeClass('fixed');
|
256 |
}
|
257 |
|
258 |
function display_success(serverID) {
|
259 |
// do nothing
|
260 |
}
|
261 |
|
262 |
// indicate that the requested action was not completed
|
263 |
function display_failure(status, serverID, action, responseText) {
|
264 |
osIcon = $('#'+serverID).parent().parent().find('.list-logo');
|
265 |
osIcon.attr('src',osIcon.attr('os'));
|
266 |
ajax_error(status, serverID, action, responseText);
|
267 |
}
|
268 |
|
269 |
var vmTable = $("div.list table.list-machines").dataTable({
|
270 |
"bInfo": false,
|
271 |
"bRetrieve": true,
|
272 |
"bPaginate": false,
|
273 |
"bAutoWidth": false,
|
274 |
"bSort": true,
|
275 |
"bStateSave": true,
|
276 |
"sScrollY": "270px",
|
277 |
"sScrollX": "515px",
|
278 |
"sScrollXInner": "500px",
|
279 |
"aoColumnDefs": [
|
280 |
{ "bSortable": false, "aTargets": [ 0 ] }
|
281 |
]
|
282 |
});
|
283 |
|
284 |
if (images.length == 0) {
|
285 |
// populate image list
|
286 |
update_images();
|
287 |
}
|
288 |
if (flavors.length == 0) {
|
289 |
// configure flavors
|
290 |
update_flavors();
|
291 |
}
|
292 |
// set the label of the multiple buttons
|
293 |
$('div.confirm_multiple button.yes').text('Confirm');
|
294 |
$('div.confirm_multiple button.no').text('Cancel');
|
295 |
|
296 |
// reposition multiple confirmation box on window resize
|
297 |
$(window).resize(function(){
|
298 |
if (this.innerHeight - 200 < $('#machinesview').height())
|
299 |
$('.confirm_multiple').addClass('fixed');
|
300 |
else
|
301 |
$('.confirm_multiple').removeClass('fixed');
|
302 |
});
|
303 |
|
304 |
// start updating vm list
|
305 |
update_vms(UPDATE_INTERVAL);
|
306 |
|
307 |
</script>
|