Statistics
| Branch: | Tag: | Revision:

root / ui / templates / list.html @ c53d09e2

History | View | Annotate | Download (9.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
                    <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

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
});
58

59
// select all/none/group from drop down menu
60
$("table thead tr th#selection ul li").live('click', function() {
61
    // all or none?
62
    if ( $(this).attr("class") == "select-all" || $(this).attr("class") == "select-none") {
63
        var all = ($(this).attr("class") == "select-all");
64
        // toggle checkboxes
65
        $(":checkbox").attr("checked", all);
66
    } else if ($(this).attr("class") == "select-group"){
67
        // TODO: This shoud select only the vms in the selected group
68
        // right now the folowing has the functionality of select-all        
69
        $(":checkbox").attr("checked", true);
70
    }
71
    // update actions
72
        updateActions();
73
        return false;
74
});
75

76
// menu toggle, running menu
77
$("table.list-machines thead tr th#selection div.expand-icon").live('click', function () {
78
        $("table.list-machines thead tr th#selection ul").slideToggle('medium');
79
    return false;
80
});
81

82
$("table.list-machines thead tr th#selection ul").live('click', function () {
83
        $("table.list-machines thead tr th#selection ul").slideToggle('medium');
84
    return false;
85
});
86

87
// TODO: This should be populated with more rules for all available states
88
var actions = { 'reboot':                ['ACTIVE', 'REBOOT', 'multiple'],
89
                                'shutdown':                ['ACTIVE', 'REBOOT', 'multiple'],
90
                                'connect':                ['ACTIVE', ],
91
                                'disconnect':        ['ACTIVE', 'network'],
92
                                'band':                        ['ACTIVE', 'REBOOT'],
93
                                'details':                ['ACTIVE', 'REBOOT', 'STOPPED'],
94
                                'start':                 ['STOPPED', 'multiple'],
95
                                'destroy':                ['ACTIVE', 'STOPPED', 'REBOOT', 'ERROR', 'multiple'],
96
                                'group':                ['ACTIVE', 'STOPPED', 'REBOOT','multiple'],
97
                           };
98

99
// on checkbox click, update the actions
100
$("tbody input[type='checkbox']").live('change', function() { 
101
    updateActions();
102
    pending_actions = [];
103
    $(".selected").removeClass('selected');
104
    update_confirmations(); 
105
});
106

107
$("div.confirm_multiple button").click(function() {
108
    $(".selected").removeClass('selected');
109
});
110

111
// destroy action
112
$("a.enabled#action-destroy").live('click', function() {
113
        var checked = $("table.list-machines tbody input[type='checkbox']:checked");
114
    $(".selected").removeClass('selected');
115
    $(this).addClass('selected');
116
        pending_actions = []; // reset pending actions
117
        checked.each(function(i,c) {
118
                serverID=c.id;
119
                serverName = $('#'+serverID+' span.name').text();
120
                pending_actions.push([destroy, serverID]);
121
        });
122
        update_confirmations();
123
        return false;
124
});
125

126
$("a.enabled#action-reboot").live('click', function() {
127
        var checked = $("table.list-machines tbody input[type='checkbox']:checked");
128
    $(".selected").removeClass('selected');
129
    $(this).addClass('selected');
130
        pending_actions = []; // reset pending actions
131
        checked.each(function(i,c) {
132
                serverID=c.id;
133
                serverName = $('#'+serverID+' span.name').text();
134
                pending_actions.push([reboot, serverID]);
135
        });
136
        update_confirmations();
137
        return false;
138
});
139

140
$("a.enabled#action-start").live('click', function() {
141
        var checked = $("table.list-machines tbody input[type='checkbox']:checked");
142
    $(".selected").removeClass('selected');
143
    $(this).addClass('selected');
144
        pending_actions = []; // reset pending actions
145
        checked.each(function(i,c) {
146
                serverID=c.id;
147
                serverName = $('#'+serverID+' span.name').text();
148
                pending_actions.push([start, serverID]);
149
        });
150
        update_confirmations();
151
        return false;
152
});
153

154
$("a.enabled#action-shutdown").live('click', function() {
155
        var checked = $("table.list-machines tbody input[type='checkbox']:checked");
156
    $(".selected").removeClass('selected');
157
    $(this).addClass('selected');
158
        pending_actions = []; // reset pending actions
159
        checked.each(function(i,c) {
160
                serverID=c.id;
161
                serverName = $('#'+serverID+' span.name').text();
162
                pending_actions.push([shutdown, serverID]);
163
        });
164
        update_confirmations();
165
        return false;
166
});
167

168
function update_machines_view(data){
169
    /* 
170
    Go through the servers in the input data. Update existing entries, add
171
    new ones to the list
172
    */
173
        tableData = vmTable.fnGetData();
174
    $.each(data.servers, function(i,server){        
175
        current = -1;
176
        // check server status to select the appropriate OS icon
177
        osTag = image_tags[server.imageRef]
178
        var osIcon = osTag + ".png";
179

180
                // check if the server already exists in the datatable
181
                tableData.forEach(function(row,index){
182
                        
183
                        if (row[0].split(' ')[2].replace('id=','') == server.id){
184
                                current = index;
185
                        } 
186
                });
187
        
188
        if (current != -1){ // if it's there, simply update the values
189
                        try {
190
                                console.info(server.name + ' from ' 
191
                                                        + tableData[current][5] + ' to ' + STATUS_MESSAGES[server.status]);
192
                        } catch(err) {}
193
                        if (server.status == "DELETED") {
194
                                vmTable.fnDeleteRow(current);        
195
                        } else {
196
                                // update status
197
                                tableData[current][0] = "<input class="+server.status+" id="+server.id+" type=checkbox>";
198
                // check server status to select the appropriate OS icon
199
                if (['ERROR', 'STOPPED'].indexOf(server.status) >= 0) {
200
                    osIcon = osTag + "-off.png";
201
                }
202
                tableData[current][1] = "<span class=imagetag>" + osTag + 
203
                                        "</span><img class=list-logo src=static/os_logos/" + osIcon +
204
                                        " title=" + osTag + " height=16 width=16>";
205
                                tableData[current][5] = "<span class=status>" + STATUS_MESSAGES[server.status] + "</span>";
206
                                // TODO: update name & ip
207
                                vmTable.fnUpdate(tableData[current],current);
208
                        }
209
                        updateActions();
210
        } else if (server.status != "DELETED") { // does not exist, we should create it
211
            // check server status to select the appropriate OS icon
212
            if (['ERROR', 'STOPPED'].indexOf(server.status) >= 0) {
213
                osIcon = osTag + "-off.png";
214
            }
215
            // add new row to the table
216
            vmTable.fnAddData([
217
                "<input class=" + server.status + " id=" + server.id + " type=checkbox>",
218
                "<span class=imagetag>" + osTag + "</span><img class=list-logo src=static/os_logos/" + osIcon +
219
                    " title=" + osTag + " height=16 width=16>",
220
                "<a class=name><span class=name>" + server.name + "</span></a>",
221
                "<a class=ip><span class=public>"+ server.addresses.public.ip.addr + "</span></a>",
222
                "group",
223
                "<span class=status>" + STATUS_MESSAGES[server.status] + "</span>"
224
            ]);
225
        }
226
    });
227
        updateActions();
228
        $("#spinner").hide();        
229
    // in case there are no data, leave the page empty
230
    if ($("div.list table.list-machines tbody").length > 0) {
231
        $("div.list div.dataTables_filter").show();
232
        $("div.list div.dataTables_filter input").show();
233
        $("div.list table.list-machines").show();
234
        $("div.list div.actions").show();
235
    }
236
}
237

238
function display_success(serverID) {
239
        //TODO
240
    $('#'+serverID).parent().parent().find('.list-logo').attr('src','static/wave.gif');
241
}
242

243
// indicate that the requested action was not completed
244
function display_failure(serverID, status, action) {
245
        osIcon = $('#'+serverID).parent().parent().find('.list-logo');
246
        osIcon.attr('src',osIcon.attr('os'));
247
    ajax_error(status);
248
}
249

250
var vmTable = $("div.list table.list-machines").dataTable({
251
    "bInfo": false,
252
    "bRetrieve": true,
253
    "bPaginate": false,
254
    "bAutoWidth": false,
255
    "bSort": true,    
256
    "bStateSave": true,
257
    "sScrollY": "270px",
258
    "sScrollX": "515px",
259
    "sScrollXInner": "500px",
260
    "aoColumnDefs": [
261
        { "bSortable": false, "aTargets": [ 0 ] }
262
    ]
263
});
264

265
if (images.length == 0) {
266
    // populate image list
267
    update_images();
268
}
269
if (flavors.length == 0) {
270
    // configure flavors
271
    update_flavors(); 
272
}
273
// set the label of the multiple buttons 
274
$('div.confirm_multiple button.yes').text('Confirm');
275
$('div.confirm_multiple button.no').text('Cancel');
276
// start updating vm list
277
update_vms(UPDATE_INTERVAL);
278

    
279
</script>