root / ui / templates / list.html @ 008b3ae8
History | View | Annotate | Download (6.1 kB)
1 |
<div id="machinesview" class="list"> |
---|---|
2 |
<div id="spinner"></div> |
3 |
<div class="actions"> |
4 |
<a id="action-start">Start</a> |
5 |
<a id="action-reboot">Reboot</a> |
6 |
<a id="action-shutdown">Shutdown</a> |
7 |
<br /> |
8 |
<a id="action-destroy">Destroy</a> |
9 |
<br /> |
10 |
<a id="action-details">Show Details</a> |
11 |
<a id="action-group">Add to group</a> |
12 |
<br /> |
13 |
<a id="action-band">Out of band</a> |
14 |
<br /> |
15 |
<a id="action-attach">Attach disk</a> |
16 |
<a id="action-detach">Detach disk</a> |
17 |
<br /> |
18 |
<a id="action-connect">Connect to network</a> |
19 |
<a id="action-disconnect">Disconnect from net</a> |
20 |
</div>
|
21 |
<table class="list-template" style="display: none"> |
22 |
<tr id="machine-template"> |
23 |
<td><input type="checkbox" id="node-id" /></td> |
24 |
<td><span class="imagetag"></span><img class="list-logo" src="" width="16" height="16" /></td> |
25 |
<td><a class="name"><span class="name">node.name</span></a></td> |
26 |
<td><a class="ip"><span class="public">node.public_ip</span></a></td> |
27 |
<td>group</td> |
28 |
<td class="status">Running</td> |
29 |
</tr>
|
30 |
</table>
|
31 |
<table class="list-machines" style="display: none"> |
32 |
<thead>
|
33 |
<tr>
|
34 |
<th id="selection" class="select-running"> |
35 |
<input type="checkbox"/> |
36 |
<div class="expand-icon"></div> |
37 |
<ul style="display: none"> |
38 |
<li class="select-all" ><a href="#">all</a></li> |
39 |
<li class="select-none"><a href="#">none</a></li> |
40 |
<li class="select-group"><a href="#">group</a></li> |
41 |
</ul>
|
42 |
</th>
|
43 |
<th id="os">OS</th> |
44 |
<th id="name">Name</th> |
45 |
<th id="ip">IP</th> |
46 |
<th id="group">Group</th> |
47 |
<th id="status">Status</th> |
48 |
</tr>
|
49 |
</thead>
|
50 |
<tbody class="running terminated"></tbody> |
51 |
</table>
|
52 |
</div>
|
53 |
|
54 |
<script>
|
55 |
// select/deselect all from checkbox widget of table headers
|
56 |
$("table thead tr th#selection :checkbox").live('change', function() {
|
57 |
if ( $(this).is(":checked") ) {
|
58 |
$(":checkbox").attr("checked", true);
|
59 |
}
|
60 |
else {
|
61 |
$(":checkbox").attr("checked", false);
|
62 |
}
|
63 |
updateActions();
|
64 |
});
|
65 |
|
66 |
// select all/none/group from drop down menu
|
67 |
$("table thead tr th#selection ul li").live('click', function() {
|
68 |
// all or none?
|
69 |
if ( $(this).attr("class") == "select-all" || $(this).attr("class") == "select-none") {
|
70 |
var all = ($(this).attr("class") == "select-all");
|
71 |
// toggle checkboxes
|
72 |
$(":checkbox").attr("checked", all);
|
73 |
} else if ($(this).attr("class") == "select-group"){
|
74 |
// TODO: This shoud select only the vms in the selected group
|
75 |
// right now the folowing has the functionality of select-all
|
76 |
$(":checkbox").attr("checked", true);
|
77 |
}
|
78 |
// update actions
|
79 |
updateActions();
|
80 |
});
|
81 |
|
82 |
// menu toggle, running menu
|
83 |
$("table.list-machines thead tr th#selection div.expand-icon").live('click', function () {
|
84 |
$("table.list-machines thead tr th#selection ul").slideToggle('medium');
|
85 |
return false;
|
86 |
});
|
87 |
|
88 |
$("table.list-machines thead tr th#selection ul").live('click', function () {
|
89 |
$("table.list-machines thead tr th#selection ul").slideToggle('medium');
|
90 |
return false;
|
91 |
});
|
92 |
|
93 |
// TODO: This should be populated with more rules for all available states
|
94 |
var actions = { 'reboot': ['ACTIVE', 'REBOOT', 'multiple'],
|
95 |
'shutdown': ['ACTIVE', 'REBOOT', 'multiple'],
|
96 |
'connect': ['ACTIVE', ],
|
97 |
'disconnect': ['ACTIVE', 'network'],
|
98 |
'band': ['ACTIVE', 'REBOOT'],
|
99 |
'details': ['ACTIVE', 'REBOOT', 'STOPPED'],
|
100 |
'start': ['STOPPED', 'multiple'],
|
101 |
'destroy': ['ACTIVE', 'STOPPED', 'REBOOT', 'multiple'],
|
102 |
'group': ['ACTIVE', 'STOPPED', 'REBOOT','multiple'],
|
103 |
};
|
104 |
|
105 |
// on checkbox click, update the actions
|
106 |
$("tbody input[type='checkbox']").live('change', function() { updateActions(); });
|
107 |
|
108 |
function updateActions() {
|
109 |
var states = [];
|
110 |
var on = [];
|
111 |
var checked = $("table tbody input[type='checkbox']:checked").toArray();
|
112 |
|
113 |
// disable all actions to begin with
|
114 |
for (action in actions) {
|
115 |
$("#action-" + action).removeClass('enabled');
|
116 |
}
|
117 |
|
118 |
// are there multiple machines selected?
|
119 |
if (checked.length>1)
|
120 |
states[0] = 'multiple';
|
121 |
|
122 |
// check the states of selected machines
|
123 |
checked.forEach(function(checkbox) {
|
124 |
states[states.length] = checkbox.className;
|
125 |
var ip = $("#" + checkbox.id.replace('input-','') + ".ip span.public").text();
|
126 |
if (ip.replace('undefined','').length)
|
127 |
states[states.length] = 'network';
|
128 |
});
|
129 |
|
130 |
// decide which actions should be enabled
|
131 |
for (a in actions) {
|
132 |
var enabled = false;
|
133 |
for (s in states) {
|
134 |
if (actions[a].indexOf(states[s]) != -1 ) {
|
135 |
enabled = true;
|
136 |
} else {
|
137 |
enabled = false;
|
138 |
break;
|
139 |
}
|
140 |
}
|
141 |
if (enabled)
|
142 |
on[on.length]=a;
|
143 |
}
|
144 |
// enable those actions
|
145 |
for (action in on) {
|
146 |
$("#action-" + on[action]).addClass('enabled');
|
147 |
}
|
148 |
}
|
149 |
|
150 |
// destroy action
|
151 |
$("a.enabled#action-destroy").live('click', function() {
|
152 |
var checked = $("tbody input[type='checkbox']:checked").toArray();
|
153 |
for (c in checked) {
|
154 |
$.ajax({
|
155 |
url: '/api/v1.0/servers/' + checked[c].id.replace('input-',''),
|
156 |
type: "DELETE",
|
157 |
dataType: "json",
|
158 |
success: function() {}
|
159 |
});
|
160 |
}
|
161 |
});
|
162 |
|
163 |
// reboot action
|
164 |
$("a.enabled#action-reboot").live('click', function() {
|
165 |
var checked = $("tbody input[type='checkbox']:checked").toArray();
|
166 |
for (c in checked) {
|
167 |
$.ajax({
|
168 |
url: '/api/v1.0/servers/' + checked[c].id.replace('input-','') + '/action',
|
169 |
type: "POST",
|
170 |
data: {
|
171 |
"reboot": '{"type" : "HARD"}'
|
172 |
},
|
173 |
dataType: "json",
|
174 |
success: function() {}
|
175 |
});
|
176 |
}
|
177 |
});
|
178 |
|
179 |
// shutdown action. Not implemented by rackspace API atm
|
180 |
$("a.enabled#action-shutdown").live('click', function() {
|
181 |
var checked = $("tbody input[type='checkbox']:checked").toArray();
|
182 |
for (c in checked) {
|
183 |
$.ajax({
|
184 |
url: '/api/v1.0/servers/' + checked[c].id.replace('input-','') + '/action',
|
185 |
type: "POST",
|
186 |
data: {
|
187 |
"shutdown": '{"timeout" : "5"}'
|
188 |
},
|
189 |
dataType: "json",
|
190 |
success: function() {}
|
191 |
});
|
192 |
}
|
193 |
});
|
194 |
|
195 |
</script>
|