Statistics
| Branch: | Tag: | Revision:

root / ui / templates / list.html @ 66edd851

History | View | Annotate | Download (11.2 kB)

1
{% load i18n %}
2

    
3
<div id="machinesview_wrapper" class="list">
4
    <div id="spinner"></div>
5
    <div class="actions">
6
        <a id="action-start">{% trans "Start" %}</a>
7
        <a id="action-reboot">{% trans "Reboot" %}</a>
8
        <a id="action-shutdown">{% trans "Shutdown" %}</a>
9
        <br />
10
        <a id="action-destroy">{% trans "Destroy" %}</a>
11
        <br />
12
        <a id="action-details">{% trans "Show Details" %}</a>
13
        <a id="action-group">{% trans "Add to group" %}</a>
14
        <br />
15
        <a id="action-band">{% trans "Out of band" %}</a>
16
        <br />
17
        <a id="action-attach">{% trans "Attach disk" %}</a>
18
        <a id="action-detach">{% trans "Detach disk" %}</a>
19
        <br />
20
        <a id="action-connect">{% trans "Connect to network" %}</a>
21
        <a id="action-disconnect">{% trans "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">{% trans "OS" %}</th> 
31
                <th id="name">{% trans "Name" %}</th> 
32
                <th id="flavor">{% trans "Flavor" %}</th> 
33
                <th id="group">{% trans "Group" %}</th>
34
                <th id="status">{% trans "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="#">{% trans "all" %}</a></li>
41
                <li class="select-none"><a href="#">{% trans "none" %}</a></li>
42
                <li class="select-group"><a href="#">{% trans "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.values, function(i,server){        
178
        current = -1;
179
        // check server status to select the appropriate OS icon
180
        osTag = os_icon(server.metadata);
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
            var currentStatus = tableData[current][5].replace('<span class=status>', '').replace('</span>', '');
193
                        try {
194
                                console.info(server.name + ' from ' + currentStatus + ' 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 (currentStatus.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
                                        imgSrc = "static/wave.gif";
209
                                        tableData[current][0] = "<input class="+server.status+" id="+server.id+" type=checkbox>";
210
                                        imgStr = "<img class=list-logo src=" + imgSrc + " title=" + osTag + " height=16 width=16 />";
211
                                        tableData[current][1] = "<span class=imagetag>" + osTag + "</span>" + imgStr;
212
                                        tableData[current][2] = "<a class=name><span class=name>" + server.name + "</span></a>";
213
                                        //tableData[current][4] = "group"; //TODO
214
                                        tableData[current][5] = "<span class=status>" + STATUS_MESSAGES[server.status] + "</span>";
215
                                        vmTable.fnUpdate(tableData[current],current);                                
216
                                        setTimeout("$('#"+server.id+"').parent().parent().find('.list-logo').attr('src','static/os_logos/" + osIcon+"')", 2000);                                        
217
                                }
218
                        }
219
                        updateActions();
220
        } else if (server.status != "DELETED") { // does not exist, we should create it
221
            // check server status to select the appropriate OS icon
222
            if (['ERROR', 'STOPPED'].indexOf(server.status) >= 0) {
223
                osIcon = osTag + "-off.png";
224
            }
225
            // find flavor parameters
226
            flavorData = get_flavor(server.flavorRef);
227
            flavorLabel = '';
228
            if (flavorData['cpu'] == '1') {
229
                flavorLabel = '1 CPU, ';
230
            } else {
231
                flavorLabel = flavorData['cpu'] + ' CPUs, ';
232
            }
233
            flavorLabel = flavorLabel + flavorData['ram'] + 'MB, ' + flavorData['disk'] + 'GB'; 
234

235
            // add new row to the table
236
            vmTable.fnAddData([
237
                "<input class=" + server.status + " id=" + server.id + " type=checkbox>",
238
                "<span class=imagetag>" + osTag + "</span><img class=list-logo src=static/os_logos/" + osIcon +
239
                    " title=" + osTag + " height=16 width=16>",
240
                "<a class=name><span class=name>" + server.name + "</span></a>",
241
                "<a class=flavor><span>"+ flavorLabel + "</span></a>",
242
                "group",
243
                "<span class=status>" + STATUS_MESSAGES[server.status] + "</span>"
244
            ]);
245
        }
246
    });
247
        updateActions();
248
        $("#spinner").hide();        
249
    // in case there are no data, leave the page empty
250
    if ($("div.list table.list-machines tbody").length > 0) {
251
        $("div.list div.dataTables_filter").show();
252
        $("div.list div.dataTables_filter input").show();
253
        $("div.list table.list-machines").show();
254
        $("div.list div.actions").show();
255
    }
256

257
    // show message in case user has no servers!
258
    if (servers.length == 0) {
259
        showWelcome()
260
    } else {
261
        hideWelcome()
262
        $("#machinesview_wrapper").fadeIn("fast")
263
    }      
264
        
265
        // set confirm box position
266
    if (window.innerHeight - 200 < $('#machinesview').height())
267
        $('.confirm_multiple').addClass('fixed');
268
    else
269
        $('.confirm_multiple').removeClass('fixed');
270
}
271

272
function display_success(serverID) {
273
        // do nothing
274
}
275

276
// indicate that the requested action was not completed
277
function display_failure(status, serverID, action, responseText) {
278
        osIcon = $('#'+serverID).parent().parent().find('.list-logo');
279
        osIcon.attr('src',osIcon.attr('os'));
280
    ajax_error(status, serverID, action, responseText);
281
}
282

283
var vmTable = $("div.list table.list-machines").dataTable({
284
    "bInfo": false,
285
    "bRetrieve": true,
286
    "bPaginate": false,
287
    "bAutoWidth": false,
288
    "bSort": true,    
289
    "bStateSave": true,
290
    "sScrollY": "270px",
291
    "sScrollX": "515px",
292
    "sScrollXInner": "500px",
293
    "aoColumnDefs": [
294
        { "bSortable": false, "aTargets": [ 0 ] }
295
    ]
296
});
297

298
if (images.length == 0) {
299
    // populate image list
300
    update_images();
301
}
302
if (flavors.length == 0) {
303
    // configure flavors
304
    update_flavors(); 
305
}
306
// set the label of the multiple buttons 
307
$('div.confirm_multiple button.yes').text('Confirm');
308
$('div.confirm_multiple button.no').text('Cancel');
309

310
// reposition multiple confirmation box on window resize
311
$(window).resize(function(){
312
    if (this.innerHeight - 200 < $('#machinesview').height())
313
        $('.confirm_multiple').addClass('fixed');
314
    else
315
        $('.confirm_multiple').removeClass('fixed');
316
});
317

318
// start updating vm list
319
update_vms(UPDATE_INTERVAL);
320

    
321
</script>