Statistics
| Branch: | Tag: | Revision:

root / ui / templates / list.html @ 146b6003

History | View | Annotate | Download (8.6 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
// select/deselect all from checkbox widget of table headers
48
$("table thead tr th#selection :checkbox").live('change', function() {
49
    if ( $(this).is(":checked") ) {
50
        $(":checkbox").attr("checked", true);
51
    }
52
    else {
53
        $(":checkbox").attr("checked", false);
54
    }
55
        updateActions();
56
});
57

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

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

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

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

98
// on checkbox click, update the actions
99
$("tbody input[type='checkbox']").live('change', function() { updateActions(); });
100

101
// destroy action
102
$("a.enabled#action-destroy").live('click', function() {
103
        var checked = $("table.list-machines tbody input[type='checkbox']:checked");
104
        var serverIDs = [], serverNames=[];
105
        checked.each(function(i,c) {
106
                serverID=c.id;
107
                serverIDs.push(serverID);
108
                serverNames.push($('#'+serverID+' span.name').text());
109
        });
110
        confirm_action('destroy', destroy, serverIDs, serverNames);
111
        return false;
112
});
113

114

115
$("a.enabled#action-reboot").live('click', function() {
116
        var checked = $("table.list-machines tbody input[type='checkbox']:checked");
117
        var serverIDs = [], serverNames=[];
118
        checked.each(function(i,c) {
119
                serverID=c.id;
120
                serverIDs.push(serverID);
121
                serverNames.push($('#'+serverID+' span.name').text());
122
        });
123
        confirm_action('reboot', reboot, serverIDs, serverNames);
124
        return false;
125
});
126

127

128
$("a.enabled#action-start").live('click', function() {
129
        var checked = $("table.list-machines tbody input[type='checkbox']:checked");
130
        var serverIDs = [], serverNames=[];
131
        checked.each(function(i,c) {
132
                serverID=c.id;
133
                serverIDs.push(serverID);
134
                serverNames.push($('#'+serverID+' span.name').text());
135
        });
136
//        confirm_action('start', start, serverIDs, serverNames);
137
    start(serverIDs);
138
        return false;
139
});
140

141

142
$("a.enabled#action-shutdown").live('click', function() {
143
        var checked = $("table.list-machines tbody input[type='checkbox']:checked");
144
        var serverIDs = [], serverNames=[];
145
        checked.each(function(i,c) {
146
                serverID=c.id;
147
                serverIDs.push(serverID);
148
                serverNames.push($('#'+serverID+' span.name').text());
149
        });
150
        confirm_action('shutdown', shutdown, serverIDs, serverNames);
151
        return false;
152
});
153

154
function update_machines_view(data){
155
    /*
156
    Go through the already displayed servers and remove those not in
157
    the data or those marked as deleted.
158
    */
159
    $('.machines tr td input').each(function(i,entry) {
160
        var deleted = true;
161
        $.each(data.servers, function(j,server) {
162
            if (server.id == entry.id && ['BUILD', 'ACTIVE', 'STOPPED', 'ERROR'].indexOf(server.status) >= 0) {
163
                deleted = false;
164
            }
165
        });
166
        if (deleted) {
167
            vmTable.fnDeleteRow(entry);
168
        }
169
    });
170
    /* 
171
    Then go through the servers in the input data. Update existing entries, add
172
    new ones to the list
173
    */    
174
    $.each(data.servers, function(i,server){
175
        // if the machine is deleted it should not be included in any list
176
        if (server.status == 'DELETED') {
177
            return;
178
        }
179
        
180
        existing = $('#' + server.id).parent().parent();  
181
        
182
        if (existing.length){ // simply update the values
183
            // If the machine already exists in the DOM then simply update it
184
            if (existing.find(".status").text() != STATUS_MESSAGES[server.status]) {
185
                try {
186
                    console.info(existing.find("a.name span.name").text() + ' from ' 
187
                                + existing.find(".status").text() + ' to ' + STATUS_MESSAGES[server.status]);
188
                } catch(err) {}
189
                existing.find(".status").text(STATUS_MESSAGES[server.status]);
190
            }
191
            existing.find("a.name span.name").text(server.name);
192
            existing.find("a.ip span.public").text(String(server.addresses.public.ip.addr).replace(',',' '));
193
        } else { // does not exist, we should create it
194
            // check server status to select the appropriate OS icon
195
            osTag = image_tags[server.imageRef]
196
            var osIcon = osTag + ".png";
197
            if (['ERROR', 'STOPPED'].indexOf(server.status) >= 0) {
198
                osIcon = osTag + "-off.png";
199
            }
200
            // add new row to the table
201
            vmTable.fnAddData([
202
                "<input class=" + server.status + " id=" + server.id + " type=checkbox>",
203
                "<span class=imagetag>" + osTag + "</span><img class=list-logo src=static/os_logos/" + osIcon +
204
                    " title=" + osTag + " height=16 width=16>",
205
                "<a class=name><span class=name>" + server.name + "</span></a>",
206
                "<a class=ip><span class=public>"+ server.addresses.public.ip.addr + "</span></a>",
207
                "group",
208
                "<span class=status>" + STATUS_MESSAGES[server.status] + "</span>"
209
            ]);
210
        }
211
    });
212
        $("#spinner").hide();        
213
    // in case there are no data, leave the page empty
214
    if ($("div.list table.list-machines tbody").length > 0) {
215
        $("div.list div.dataTables_filter").show();
216
        $("div.list div.dataTables_filter input").show();
217
        $("div.list table.list-machines").show();
218
        $("div.list div.actions").show();
219
    }
220
}
221

222
var vmTable = $("div.list table.list-machines").dataTable({
223
    "bInfo": false,
224
    "bRetrieve": true,
225
    "bPaginate": false,
226
    "bAutoWidth": false,
227
    "bSort": true,    
228
    "bStateSave": true,
229
    "sScrollY": "270px",
230
    "sScrollX": "515px",
231
    "sScrollXInner": "500px",
232
    "aoColumnDefs": [
233
        { "bSortable": false, "aTargets": [ 0 ] }
234
    ]
235
});
236

237

238
if (images.length == 0) {
239
    // populate image list
240
    update_images();
241
}
242
if (flavors.length == 0) {
243
    // configure flavors
244
    update_flavors(); 
245
}
246
update_vms(UPDATE_INTERVAL);
247

    
248
</script>