root / ui / templates / list.html @ 42f67a2a
History | View | Annotate | Download (6.7 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-template" style="display: none"> |
24 |
<tr id="machine-template"> |
25 |
<td><input type="checkbox" id="node-id" /></td> |
26 |
<td><span class="imagetag"></span><img class="list-logo" src="" width="16" height="16" /></td> |
27 |
<td><a class="name"><span class="name">node.name</span></a></td> |
28 |
<td><a class="ip"><span class="public">node.public_ip</span></a></td> |
29 |
<td>group</td> |
30 |
<td class="status">Running</td> |
31 |
</tr>
|
32 |
</table>
|
33 |
<table class="list-machines" style="display: none"> |
34 |
<thead>
|
35 |
<tr>
|
36 |
<th id="selection" class="select-running"> |
37 |
<input type="checkbox"/> |
38 |
<div class="expand-icon"></div> |
39 |
<ul 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 |
</th>
|
45 |
<th id="os">OS</th> |
46 |
<th id="name">Name</th> |
47 |
<th id="ip">IP</th> |
48 |
<th id="group">Group</th> |
49 |
<th id="status">Status</th> |
50 |
</tr>
|
51 |
</thead>
|
52 |
<tbody class="running terminated"></tbody> |
53 |
</table>
|
54 |
</div>
|
55 |
|
56 |
<script>
|
57 |
// select/deselect all from checkbox widget of table headers
|
58 |
$("table thead tr th#selection :checkbox").live('change', function() {
|
59 |
if ( $(this).is(":checked") ) {
|
60 |
$(":checkbox").attr("checked", true);
|
61 |
}
|
62 |
else {
|
63 |
$(":checkbox").attr("checked", false);
|
64 |
}
|
65 |
updateActions();
|
66 |
});
|
67 |
|
68 |
// select all/none/group from drop down menu
|
69 |
$("table thead tr th#selection ul li").live('click', function() {
|
70 |
// all or none?
|
71 |
if ( $(this).attr("class") == "select-all" || $(this).attr("class") == "select-none") {
|
72 |
var all = ($(this).attr("class") == "select-all");
|
73 |
// toggle checkboxes
|
74 |
$(":checkbox").attr("checked", all);
|
75 |
} else if ($(this).attr("class") == "select-group"){
|
76 |
// TODO: This shoud select only the vms in the selected group
|
77 |
// right now the folowing has the functionality of select-all
|
78 |
$(":checkbox").attr("checked", true);
|
79 |
}
|
80 |
// update actions
|
81 |
updateActions();
|
82 |
return false;
|
83 |
});
|
84 |
|
85 |
// menu toggle, running menu
|
86 |
$("table.list-machines thead tr th#selection div.expand-icon").live('click', function () {
|
87 |
$("table.list-machines thead tr th#selection ul").slideToggle('medium');
|
88 |
return false;
|
89 |
});
|
90 |
|
91 |
$("table.list-machines thead tr th#selection ul").live('click', function () {
|
92 |
$("table.list-machines thead tr th#selection ul").slideToggle('medium');
|
93 |
return false;
|
94 |
});
|
95 |
|
96 |
// TODO: This should be populated with more rules for all available states
|
97 |
var actions = { 'reboot': ['ACTIVE', 'REBOOT', 'multiple'],
|
98 |
'shutdown': ['ACTIVE', 'REBOOT', 'multiple'],
|
99 |
'connect': ['ACTIVE', ],
|
100 |
'disconnect': ['ACTIVE', 'network'],
|
101 |
'band': ['ACTIVE', 'REBOOT'],
|
102 |
'details': ['ACTIVE', 'REBOOT', 'STOPPED'],
|
103 |
'start': ['STOPPED', 'multiple'],
|
104 |
'destroy': ['ACTIVE', 'STOPPED', 'REBOOT', 'multiple'],
|
105 |
'group': ['ACTIVE', 'STOPPED', 'REBOOT','multiple'],
|
106 |
};
|
107 |
|
108 |
// on checkbox click, update the actions
|
109 |
$("tbody input[type='checkbox']").live('change', function() { updateActions(); });
|
110 |
|
111 |
function updateActions() {
|
112 |
var states = [];
|
113 |
var on = [];
|
114 |
var checked = $("table.list-machines tbody input[type='checkbox']:checked");
|
115 |
// disable all actions to begin with
|
116 |
for (action in actions) {
|
117 |
$("#action-" + action).removeClass('enabled');
|
118 |
}
|
119 |
|
120 |
// are there multiple machines selected?
|
121 |
if (checked.length>1)
|
122 |
states[0] = 'multiple';
|
123 |
|
124 |
// check the states of selected machines
|
125 |
checked.each(function(i,checkbox) {
|
126 |
states[states.length] = checkbox.className;
|
127 |
var ip = $("#" + checkbox.id.replace('input-','') + ".ip span.public").text();
|
128 |
if (ip.replace('undefined','').length)
|
129 |
states[states.length] = 'network';
|
130 |
});
|
131 |
|
132 |
// decide which actions should be enabled
|
133 |
for (a in actions) {
|
134 |
var enabled = false;
|
135 |
for (var s =0; s<states.length; s++) {
|
136 |
if (actions[a].indexOf(states[s]) != -1 ) {
|
137 |
enabled = true;
|
138 |
} else {
|
139 |
enabled = false;
|
140 |
break;
|
141 |
}
|
142 |
}
|
143 |
if (enabled)
|
144 |
on[on.length]=a;
|
145 |
}
|
146 |
// enable those actions
|
147 |
for (action in on) {
|
148 |
$("#action-" + on[action]).addClass('enabled');
|
149 |
}
|
150 |
}
|
151 |
|
152 |
// destroy action
|
153 |
$("a.enabled#action-destroy").live('click', function() {
|
154 |
var checked = $("table.list-machines tbody input[type='checkbox']:checked");
|
155 |
var serverIDs = [], serverNames=[];
|
156 |
checked.each(function(i,c) {
|
157 |
serverID=c.id.replace('input-','');
|
158 |
serverIDs.push(serverID);
|
159 |
serverNames.push($('tr#'+serverID+' span.name').text());
|
160 |
});
|
161 |
confirm_action('destroy', destroy, serverIDs, serverNames);
|
162 |
return false;
|
163 |
});
|
164 |
|
165 |
|
166 |
$("a.enabled#action-reboot").live('click', function() {
|
167 |
var checked = $("table.list-machines tbody input[type='checkbox']:checked");
|
168 |
var serverIDs = [], serverNames=[];
|
169 |
checked.each(function(i,c) {
|
170 |
serverID=c.id.replace('input-','');
|
171 |
serverIDs.push(serverID);
|
172 |
serverNames.push($('tr#'+serverID+' span.name').text());
|
173 |
});
|
174 |
confirm_action('reboot', reboot, serverIDs, serverNames);
|
175 |
return false;
|
176 |
});
|
177 |
|
178 |
|
179 |
$("a.enabled#action-start").live('click', function() {
|
180 |
var checked = $("table.list-machines tbody input[type='checkbox']:checked");
|
181 |
var serverIDs = [], serverNames=[];
|
182 |
checked.each(function(i,c) {
|
183 |
serverID=c.id.replace('input-','');
|
184 |
serverIDs.push(serverID);
|
185 |
serverNames.push($('tr#'+serverID+' span.name').text());
|
186 |
});
|
187 |
confirm_action('start', start, serverIDs, serverNames);
|
188 |
return false;
|
189 |
});
|
190 |
|
191 |
|
192 |
$("a.enabled#action-shutdown").live('click', function() {
|
193 |
var checked = $("table.list-machines tbody input[type='checkbox']:checked");
|
194 |
var serverIDs = [], serverNames=[];
|
195 |
checked.each(function(i,c) {
|
196 |
serverID=c.id.replace('input-','');
|
197 |
serverIDs.push(serverID);
|
198 |
serverNames.push($('tr#'+serverID+' span.name').text());
|
199 |
});
|
200 |
confirm_action('shutdown', shutdown, serverIDs, serverNames);
|
201 |
return false;
|
202 |
});
|
203 |
|
204 |
update_vms();
|
205 |
|
206 |
</script>
|