root / ui / templates / list.html @ a1a31201
History | View | Annotate | Download (8.1 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 |
<ul style="display: none"> |
30 |
<li class="select-all" ><a href="#">all</a></li> |
31 |
<li class="select-none"><a href="#">none</a></li> |
32 |
<li class="select-group"><a href="#">group</a></li> |
33 |
</ul>
|
34 |
</th>
|
35 |
<th id="os">OS</th> |
36 |
<th id="name">Name</th> |
37 |
<th id="ip">IP</th> |
38 |
<th id="group">Group</th> |
39 |
<th id="status">Status</th> |
40 |
</tr>
|
41 |
</thead>
|
42 |
<tbody class="machines"></tbody> |
43 |
</table>
|
44 |
</div>
|
45 |
|
46 |
<script>
|
47 |
// select/deselect all from checkbox widget of table headers
|
48 |
$("table thead tr th#selection :checkbox").live('change', function() {
|
49 |
if ( $(this).is(":checked") ) {
|
50 |
$(":checkbox").attr("checked", true);
|
51 |
}
|
52 |
else {
|
53 |
$(":checkbox").attr("checked", false);
|
54 |
}
|
55 |
updateActions();
|
56 |
});
|
57 |
|
58 |
// select all/none/group from drop down menu
|
59 |
$("table thead tr th#selection ul li").live('click', function() {
|
60 |
// all or none?
|
61 |
if ( $(this).attr("class") == "select-all" || $(this).attr("class") == "select-none") {
|
62 |
var all = ($(this).attr("class") == "select-all");
|
63 |
// toggle checkboxes
|
64 |
$(":checkbox").attr("checked", all);
|
65 |
} else if ($(this).attr("class") == "select-group"){
|
66 |
// TODO: This shoud select only the vms in the selected group
|
67 |
// right now the folowing has the functionality of select-all
|
68 |
$(":checkbox").attr("checked", true);
|
69 |
}
|
70 |
// update actions
|
71 |
updateActions();
|
72 |
return false;
|
73 |
});
|
74 |
|
75 |
// menu toggle, running menu
|
76 |
$("table.list-machines thead tr th#selection div.expand-icon").live('click', function () {
|
77 |
$("table.list-machines thead tr th#selection ul").slideToggle('medium');
|
78 |
return false;
|
79 |
});
|
80 |
|
81 |
$("table.list-machines thead tr th#selection ul").live('click', function () {
|
82 |
$("table.list-machines thead tr th#selection ul").slideToggle('medium');
|
83 |
return false;
|
84 |
});
|
85 |
|
86 |
// TODO: This should be populated with more rules for all available states
|
87 |
var actions = { 'reboot': ['ACTIVE', 'REBOOT', 'multiple'],
|
88 |
'shutdown': ['ACTIVE', 'REBOOT', 'multiple'],
|
89 |
'connect': ['ACTIVE', ],
|
90 |
'disconnect': ['ACTIVE', 'network'],
|
91 |
'band': ['ACTIVE', 'REBOOT'],
|
92 |
'details': ['ACTIVE', 'REBOOT', 'STOPPED'],
|
93 |
'start': ['STOPPED', 'multiple'],
|
94 |
'destroy': ['ACTIVE', 'STOPPED', 'REBOOT', 'ERROR', 'multiple'],
|
95 |
'group': ['ACTIVE', 'STOPPED', 'REBOOT','multiple'],
|
96 |
};
|
97 |
|
98 |
// on checkbox click, update the actions
|
99 |
$("tbody input[type='checkbox']").live('change', function() { updateActions(); });
|
100 |
|
101 |
// destroy action
|
102 |
$("a.enabled#action-destroy").live('click', function() {
|
103 |
var checked = $("table.list-machines tbody input[type='checkbox']:checked");
|
104 |
var serverIDs = [], serverNames=[];
|
105 |
checked.each(function(i,c) {
|
106 |
serverID=c.id;
|
107 |
serverIDs.push(serverID);
|
108 |
serverNames.push($('#'+serverID+' span.name').text());
|
109 |
});
|
110 |
confirm_action('destroy', destroy, serverIDs, serverNames);
|
111 |
return false;
|
112 |
});
|
113 |
|
114 |
|
115 |
$("a.enabled#action-reboot").live('click', function() {
|
116 |
var checked = $("table.list-machines tbody input[type='checkbox']:checked");
|
117 |
var serverIDs = [], serverNames=[];
|
118 |
checked.each(function(i,c) {
|
119 |
serverID=c.id;
|
120 |
serverIDs.push(serverID);
|
121 |
serverNames.push($('#'+serverID+' span.name').text());
|
122 |
});
|
123 |
confirm_action('reboot', reboot, serverIDs, serverNames);
|
124 |
return false;
|
125 |
});
|
126 |
|
127 |
|
128 |
$("a.enabled#action-start").live('click', function() {
|
129 |
var checked = $("table.list-machines tbody input[type='checkbox']:checked");
|
130 |
var serverIDs = [], serverNames=[];
|
131 |
checked.each(function(i,c) {
|
132 |
serverID=c.id;
|
133 |
serverIDs.push(serverID);
|
134 |
serverNames.push($('#'+serverID+' span.name').text());
|
135 |
});
|
136 |
// confirm_action('start', start, serverIDs, serverNames);
|
137 |
start(serverIDs);
|
138 |
return false;
|
139 |
});
|
140 |
|
141 |
|
142 |
$("a.enabled#action-shutdown").live('click', function() {
|
143 |
var checked = $("table.list-machines tbody input[type='checkbox']:checked");
|
144 |
var serverIDs = [], serverNames=[];
|
145 |
checked.each(function(i,c) {
|
146 |
serverID=c.id;
|
147 |
serverIDs.push(serverID);
|
148 |
serverNames.push($('#'+serverID+' span.name').text());
|
149 |
});
|
150 |
confirm_action('shutdown', shutdown, serverIDs, serverNames);
|
151 |
return false;
|
152 |
});
|
153 |
|
154 |
function update_machines_view(data){
|
155 |
/*
|
156 |
Go through the servers in the input data. Update existing entries, add
|
157 |
new ones to the list
|
158 |
*/
|
159 |
tableData = vmTable.fnGetData();
|
160 |
$.each(data.servers, function(i,server){
|
161 |
current = -1;
|
162 |
|
163 |
// check if the server already exists in the datatable
|
164 |
tableData.forEach(function(row,index){
|
165 |
|
166 |
if (row[0].split(' ')[2].replace('id=','') == server.id){
|
167 |
current = index;
|
168 |
}
|
169 |
});
|
170 |
|
171 |
if (current != -1){ // if it's there, simply update the values
|
172 |
try {
|
173 |
console.info(server.name + ' from '
|
174 |
+ tableData[current][5] + ' to ' + STATUS_MESSAGES[server.status]);
|
175 |
} catch(err) {}
|
176 |
if (server.status == "DELETED") {
|
177 |
vmTable.fnDeleteRow(current);
|
178 |
} else {
|
179 |
// update status
|
180 |
tableData[current][0] = "<input class="+server.status+" id="+server.id+" type=checkbox>";
|
181 |
tableData[current][5] = "<span class=status>" + STATUS_MESSAGES[server.status] + "</span>";
|
182 |
// TODO: update name & ip
|
183 |
vmTable.fnUpdate(tableData[current],current);
|
184 |
}
|
185 |
updateActions();
|
186 |
} else if (server.status != "DELETED") { // does not exist, we should create it
|
187 |
// check server status to select the appropriate OS icon
|
188 |
osTag = image_tags[server.imageRef]
|
189 |
var osIcon = osTag + ".png";
|
190 |
if (['ERROR', 'STOPPED'].indexOf(server.status) >= 0) {
|
191 |
osIcon = osTag + "-off.png";
|
192 |
}
|
193 |
// add new row to the table
|
194 |
vmTable.fnAddData([
|
195 |
"<input class=" + server.status + " id=" + server.id + " type=checkbox>",
|
196 |
"<span class=imagetag>" + osTag + "</span><img class=list-logo src=static/os_logos/" + osIcon +
|
197 |
" title=" + osTag + " height=16 width=16>",
|
198 |
"<a class=name><span class=name>" + server.name + "</span></a>",
|
199 |
"<a class=ip><span class=public>"+ server.addresses.public.ip.addr + "</span></a>",
|
200 |
"group",
|
201 |
"<span class=status>" + STATUS_MESSAGES[server.status] + "</span>"
|
202 |
]);
|
203 |
}
|
204 |
});
|
205 |
updateActions();
|
206 |
$("#spinner").hide();
|
207 |
// in case there are no data, leave the page empty
|
208 |
if ($("div.list table.list-machines tbody").length > 0) {
|
209 |
$("div.list div.dataTables_filter").show();
|
210 |
$("div.list div.dataTables_filter input").show();
|
211 |
$("div.list table.list-machines").show();
|
212 |
$("div.list div.actions").show();
|
213 |
}
|
214 |
}
|
215 |
|
216 |
function display_success(serverID) {
|
217 |
//TODO
|
218 |
return false;
|
219 |
}
|
220 |
|
221 |
var vmTable = $("div.list table.list-machines").dataTable({
|
222 |
"bInfo": false,
|
223 |
"bRetrieve": true,
|
224 |
"bPaginate": false,
|
225 |
"bAutoWidth": false,
|
226 |
"bSort": true,
|
227 |
"bStateSave": true,
|
228 |
"sScrollY": "270px",
|
229 |
"sScrollX": "515px",
|
230 |
"sScrollXInner": "500px",
|
231 |
"aoColumnDefs": [
|
232 |
{ "bSortable": false, "aTargets": [ 0 ] }
|
233 |
]
|
234 |
});
|
235 |
|
236 |
|
237 |
if (images.length == 0) {
|
238 |
// populate image list
|
239 |
update_images();
|
240 |
}
|
241 |
if (flavors.length == 0) {
|
242 |
// configure flavors
|
243 |
update_flavors();
|
244 |
}
|
245 |
update_vms(UPDATE_INTERVAL);
|
246 |
|
247 |
</script>
|