Statistics
| Branch: | Tag: | Revision:

root / ui / templates / list.html @ 190e3256

History | View | Annotate | Download (9.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
                </th>
30
                <th id="os">OS</th> 
31
                <th id="name">Name</th> 
32
                <th id="ip">IP</th> 
33
                <th id="group">Group</th>
34
                <th id="status">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="#">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
</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
        return false;        
64
});
65

66
// select none from drop down menu
67
$("ul.dropdown-selector li.select-none a").live('click', function() {
68
        $(":checkbox").attr("checked", false);
69
        return false;        
70
});
71

72
// select group from drop down menu
73
$("ul.dropdown-selector li.select-group a").live('click', function() {
74
        $(":checkbox").attr("checked", true);
75
        return false;
76
});
77

78
// menu toggle, running menu
79
$("table.list-machines thead tr th#selection .expand-icon").click( function (obj) {
80
        $(".dropdown-selector").slideToggle('medium');
81
    return false;
82
});
83

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

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

104
$("div.confirm_multiple button").click(function() {
105
    $(".selected").removeClass('selected');
106
});
107

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

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

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

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

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

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

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

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

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

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

    
276
</script>