Statistics
| Branch: | Tag: | Revision:

root / ui / templates / standard.html @ 339712cb

History | View | Annotate | Download (17.5 kB)

1
{% load i18n %}
2

    
3
<!-- the standard view -->
4
<div id="machinesview" class="standard">
5
    <div id="spinner"></div>
6
    <div class="machine" id="machine-template" style="display:none">
7
        <div class="actions">
8
            <a href="#" class="action-start">{% trans "Start" %}</a>
9
            <a href="#" class="action-reboot">{% trans "Reboot" %}</a>
10
            <a href="#" class="action-shutdown">{% trans "Shutdown" %}</a>
11
            <a href="#" class="action-destroy">{% trans "Destroy" %}</a>
12
        </div>        
13
        <div class="state">
14
            <div class="status">{% trans "Running" %}</div>
15
            <div class="indicator"></div>
16
            <div class="indicator"></div>
17
            <div class="indicator"></div>
18
            <div class="indicator"></div>
19
            <img class="spinner" style="display:none" src="/static/progress.gif" />
20
            <img class="wave" style="display:none" src="/static/wave.gif" />
21
        </div>
22
        <img class="logo" src="" />
23
        <a href="#" class="name">
24
            <h5>{% trans "Name: " %}<span class="name">node.name</span><span class="rename"></span></h5>
25
        </a>
26
        <a href="#" class="ip">
27
            <h5>{% trans "IP: " %}<span class="public">node.public_ip</span></h5>
28
        </a>
29
        <h5 class="settings">
30
            {% trans "Show:" %} 
31
            <a href="#">{% trans "disks" %}</a> | 
32
            <a href="#">{% trans "networks" %}</a> | 
33
            <a href="#">{% trans "group" %}</a> | 
34
            <a class="show-metadata" href="#">{% trans "metadata" %}</a>
35
        </h5>
36
        <div class="confirm_single">
37
            <button class="yes">{% trans "Confirm" %}</button>
38
            <button class="no">{% trans "Cancel" %}</button>
39
        </div>
40
        <div class="action_error" align="center">
41
            {% trans "<span class='orange'>Error</span> on" %} <span class="action">{% trans "error action" %}</span>
42
            <span class="code"></span>            
43
            <span class="message"></span>
44
            <button class="details">{% trans "Details" %}</button>
45
        </div>
46
        <div class="separator"></div>
47
    </div>
48
    <div class="running"></div>
49
    <div id="mini" class="separator"></div>
50
    <div class="terminated"></div>
51
</div>
52

    
53
<script>
54

55
// intercept metadata click
56
$("a.show-metadata").live('click', function() {
57
    // get server name and server ID
58
    var serverID = $(this).parent().parent().attr("id");
59
    var serverName = $(this).parent().prevAll("a.name").find("span.name").text();
60
    // set server name in box's title
61
    $("a#meta-editor-1 span").text(serverName);
62
    var triggers = $("a#meta-editor-1").overlay({
63
        // some mask tweaks suitable for modal dialogs
64
        mask: {
65
            color: '#ebecff',
66
            opacity: '0.9'
67
        },
68
        top: 'center',
69
        closeOnClick: false,
70
        oneInstance: false,
71
        load: false,
72
        onClose: function(){
73
            // With partial refresh working properly,
74
            // it is no longer necessary to refresh the whole page
75
            // choose_view();
76
        }
77
    });
78
    $("a#meta-editor-1").data('overlay').load();
79
    return false; 
80
});
81

82
// intercept reboot click 
83
$("div.actions a.action-reboot").live('click', function(){
84
    var serverID = $(this).parent().parent().attr("id");
85
    var serverName = $(this).parent().prevAll("a.name").find("span.name").text();
86
    var found = false;
87
    
88
    $(this).parent().children('a').removeClass('selected');
89
    $(this).addClass('selected');
90
    $(this).parent().addClass('display');
91
    $(this).parent().parent().find('.action_error').hide();
92
    for (i=0;i<pending_actions.length;i++){ // if there is already a pending action for this server replace it
93
        if (pending_actions[i][1]==serverID){
94
            pending_actions[i][0] = reboot;
95
            found = true
96
        }
97
    }
98
    if (!found) // no pending action for this server was found, so let's just add it to the list
99
        pending_actions.push([reboot, serverID, serverName])
100
    update_confirmations();
101
    return false;
102
});
103

104
// intercept shutdown click
105
$("div.actions a.action-shutdown").live('click', function(){ 
106
    var serverID = $(this).parent().parent().attr("id");
107
    var serverName = $(this).parent().prevAll("a.name").find("span.name").text();
108
    var found = false;
109
    $(this).parent().children('a').removeClass('selected');
110
    $(this).addClass('selected');
111
    $(this).parent().addClass('display')
112
    $(this).parent().parent().find('.action_error').hide();
113

114
    for (i=0;i<pending_actions.length;i++){ // if there is already a pending action for this server replace it
115
        if (pending_actions[i][1]==serverID){
116
            pending_actions[i][0] = shutdown;
117
            found = true
118
        }
119
    }
120
    if (!found) // no pending action for this server was found, so let's just add it to the list 
121
        pending_actions.push([shutdown, serverID, serverName])
122
    update_confirmations();
123
    return false;
124
});
125

126
// intercept start click
127
$("div.actions a.action-start").live('click', function(){ 
128
    var serverID = $(this).parent().parent().attr("id");
129
    var serverName = $(this).parent().prevAll("a.name").find("span.name").text();
130
    var found = false;
131
    $(this).parent().children('a').removeClass('selected');
132
    $(this).addClass('selected');
133
    $(this).parent().addClass('display')
134
    $(this).parent().parent().find('.action_error').hide();
135

136
    for (i=0;i<pending_actions.length;i++){ // if there is already a pending action for this server replace it
137
        if (pending_actions[i][1]==serverID){
138
            pending_actions[i][0] = start;
139
            found = true
140
        }
141
    }
142
    if (!found) // no pending action for this server was found, so let's just add it to the list
143
        pending_actions.push([start, serverID, serverName])
144
    update_confirmations();    
145
    return false;
146
});
147

148
// intercept destroy click
149
$("div.actions a.action-destroy").live('click', function(){ 
150
    var serverID = $(this).parent().parent().attr("id");
151
    var serverName = $(this).parent().prevAll("a.name").find("span.name").text();
152
    var found = false;
153
    $(this).parent().children('a').removeClass('selected');
154
    $(this).addClass('selected');
155
    $(this).parent().addClass('display')
156
    $(this).parent().parent().find('.action_error').hide();
157

158
    for (i=0;i<pending_actions.length;i++){ // if there is already a pending action for this server replace it
159
        if (pending_actions[i][1]==serverID){
160
            pending_actions[i][0] = destroy;
161
            found = true
162
        }
163
    }
164
    if (!found) // no pending action for this server was found, so let's just add it to the list
165
        pending_actions.push([destroy, serverID, serverName])
166
    update_confirmations();    
167
    return false;
168
});
169

170
$("div.confirm_single .yes").live('click', function(){
171
    var serverID = $(this).parent().parent().attr("id");
172
    for (i=0;i<pending_actions.length;i++){ // if there is a pending action for this server execute it
173
        if (pending_actions[i][1]==serverID){
174
            action = pending_actions.splice(i,1)[0]; // extract action
175
            // change the status text in cases where no api state exists
176
            if (action[0] == start) {
177
                $(this).parent().parent().find('.status').text('Starting');
178
                $(this).parent().parent().find('.spinner').show();
179
            } else if (action[0] == shutdown) {
180
                $(this).parent().parent().find('.status').text('Shutting down');
181
                $(this).parent().parent().find('.spinner').show();
182
            } else if (action[0] == reboot) {
183
                $(this).parent().parent().find('.status').text('Rebooting');
184
                $(this).parent().parent().find('.spinner').show();
185
            }  else if (action[0] == destroy) {
186
                $(this).parent().parent().find('.status').text('Destroying');
187
                $(this).parent().parent().find('.spinner').show();
188
            }                    
189
            action[0]([action[1]]); // execute action
190
        }
191
    }
192
    $(this).parent().hide();
193
    $(this).parent().parent().children('div.actions').children('a').removeClass('selected');
194
    $(this).parent().parent().children('.state').children('.spinner').show()
195
    $(this).parent().parent().children('div.actions').removeClass('display');
196
    update_confirmations(); 
197
    return false;
198
});
199

200
$("div.confirm_single .no").live('click', function(){
201
    // remove the action from the pending list
202
    var serverID = $(this).parent().parent().attr("id");
203
    
204
    $(this).parent().parent().children('div.actions').children('a').removeClass('selected');
205
    $(this).parent().parent().children('div.actions').removeClass('display');    
206
    for (i=0;i<pending_actions.length;i++){ // if there is a pending action for this server remove it
207
        if (pending_actions[i][1]==serverID){
208
            pending_actions.splice(i,1);
209
        }
210
    }
211
    $(this).parent().hide();
212
    update_confirmations();    
213
    return false;
214
});
215

216
$("div.action_error .details").live('click', function(){
217
    // remove the action from the pending list
218
    ajax_error($(this).parent().children('.code').text(), undefined, $(this).parent().children('.action').text(), $(this).parent().children('.message').text());
219
    $(this).parent().hide();
220
});
221

222

223
// update the servers list
224
function update_machines_view(data){
225
    /* 
226
    Go through the servers in the input data. Update existing entries, add
227
    new ones to the list
228
    */     
229
           
230
    $.each(data.servers.values, function(i,server){
231
        existing = $('#' + server.id);
232
        
233
        // if multiple machines exist in the DOM, delete all but one
234
        // defensive coding - that shouldn't happen normally
235
        while (existing.length > 1){
236
            existing.remove();
237
        }
238

239
        var server_image = os_icon(server.metadata);
240

241

242
        // server already exists in DOM
243
        if (existing.length){
244
            $("div.machine:last-child").find("div.separator").show();                
245

246
            //  if the status is deleted, delete it from the DOM
247
            if (server.status == 'DELETED') {
248
                existing.remove();            
249
                try {
250
                    console.info(existing.find("a.name span.name").text() + ' removed');
251
                } catch(err) {}            
252
            } else if (existing.find(".status").text() != STATUS_MESSAGES[server.status]) {
253

254
                try { // firebug console logging
255
                    console.info(existing.find("a.name span.name").text() + ' from ' 
256
                                + existing.find(".status").text() + ' to ' + STATUS_MESSAGES[server.status]);
257
                } catch(err) {}
258
                //show reboot and shutdown actions
259
                if (server.status == 'ACTIVE' || server.status == 'REBOOT') {
260
                    $('div.#' + server.id + ' a.action-reboot').show();
261
                    $('div.#' + server.id + ' a.action-shutdown').show();        
262
                    $('div.#' + server.id + ' a.action-destroy').removeClass('destroy-padding');        
263
                }
264
                if (['BUILD','ACTIVE','REBOOT'].indexOf(server.status) >= 0 &&
265
                    [STATUS_MESSAGES['STOPPED'], STATUS_MESSAGES['ERROR'],
266
                     'Starting'].indexOf(existing.find(".status").text()) >= 0) {
267
                    // from stopped, on error or starting to building, active or rebooting
268
                    // starting is not an api state, it means the vm is stopped or on error
269
                    moved = existing.clone().appendTo(".running");
270
                    moved.find("img.logo").attr("src","static/machines/" + server_image + '-on.png');
271
                    existing.remove();
272
                    existing = moved;
273
                    existing.find(".status").text(STATUS_MESSAGES[server.status]); 
274
                } else if (['STOPPED','ERROR'].indexOf(server.status) >= 0 &&
275
                           [STATUS_MESSAGES['ACTIVE'], STATUS_MESSAGES['BUILD'], STATUS_MESSAGES['REBOOT'],
276
                            'Shutting down'].indexOf(existing.find(".status").text()) >= 0) {
277
                    // from active, building, rebooting, or shutting down to stopped or on error
278
                    // shutting down is not an api state, it means the server is active
279
                    moved = existing.clone().appendTo(".terminated");
280
                    moved.find("img.logo").attr("src","static/machines/" + server_image + '-off.png');
281
                    existing.remove();
282
                    existing = moved;
283
                    existing.find(".status").text(STATUS_MESSAGES[server.status]); 
284
                } else if (['BUILD','ACTIVE','REBOOT'].indexOf(server.status) >= 0 && 
285
                            [STATUS_MESSAGES['ACTIVE'], STATUS_MESSAGES['BUILD'],
286
                             STATUS_MESSAGES['REBOOT']].indexOf(existing.find(".status").text()) >= 0) {
287
                    // the server changes status, but remains in running list
288
                    existing.find(".status").text(STATUS_MESSAGES[server.status]); 
289
                } else if (['STOPPED','ERROR'].indexOf(server.status) >= 0 &&
290
                    [STATUS_MESSAGES['STOPPED'], 
291
                     STATUS_MESSAGES['ERROR']].indexOf(existing.find(".status").text()) >= 0) {
292
                    // the server changes status, but remains in terminated list
293
                    existing.find(".status").text(STATUS_MESSAGES[server.status]); 
294
                }        
295
                existing.find('.spinner').hide();
296
                existing.find(' .wave').attr('src','static/wave.gif').show();
297
                setTimeout("$('#" + server.id +" .wave').attr('src','').hide()", 3000);
298
                // show spinner while the server is rebooting, starting or shutting down  
299
                if ([STATUS_MESSAGES['REBOOT'], 
300
                    'Starting', 'Shutting down'].indexOf(existing.find(".status").text()) >= 0 ) {
301
                    existing.find(' .wave').hide();
302
                    existing.find('.spinner').show();
303
                }                            
304
            }
305
            existing.find("a.name span.name").text(server.name);
306
            existing.find("a.ip span.public").text(String(server.addresses.values[0].values[0].addr).replace(',',' '));
307
        } else if (server.status != 'DELETED') {
308
            // If it does not exist and it's not deleted, we should create it
309
            var machine = $("#machine-template").clone().attr("id", server.id).fadeIn("slow");
310
            machine.find("a.name span.name").text(server.name);
311
            machine.find("img.logo").attr("src","static/machines/"+server_image+'-on.png');
312
            machine.find("span.imagetag").text(server_image);
313
            machine.find("a.ip span.public").text(String(server.addresses.values[0].values[0].addr).replace(',',' '));            
314
            machine.find(".status").text(STATUS_MESSAGES[server.status]);
315
            if (['BUILD', 'ACTIVE', 'REBOOT'].indexOf(server.status) >= 0){
316
                machine.appendTo(".running");
317
            } else {
318
                machine.find("img.logo").attr("src","static/machines/"+server_image+'-off.png');
319
                machine.appendTo(".terminated");
320
            }
321
            //show spinner while machine is building
322
            if (server.status == 'BUILD' || 
323
                ['Starting', 'Shutting down'].indexOf(existing.find(".status").text()) >= 0 ) { 
324
                machine.find('.spinner').show();
325
            }   
326
            //allow destroy action only while machine is building
327
            if (server.status == 'BUILD') {
328
                $('div.#' + server.id + ' a.action-reboot').hide();
329
                $('div.#' + server.id + ' a.action-shutdown').hide();        
330
                $('div.#' + server.id + ' a.action-destroy').addClass('destroy-padding');        
331
            }
332
        }
333
    });
334

335
    $("#spinner").hide();
336
    // show all separators
337
    $("div.machine div.separator").show();
338
    // hide the last one
339
    $("div.machine:last-child").find("div.separator").hide();
340
    // the separator shows only when running and terminated machines are available
341
    if ($(".terminated a.name").length > 0 && $(".running a.name").length > 0) {
342
        $("#mini.separator").fadeIn("slow");
343
    } else {
344
        $("#mini.separator").fadeOut("slow");
345
    }     
346

347
    // show message in case user has no servers!
348
    if (servers.length == 0) {
349
        showWelcome()
350
    } else {
351
        hideWelcome()
352
    }  
353
    
354
    // set confirm box position
355
    if (window.innerHeight - 220 < $('#machinesview').height())
356
        $('.confirm_multiple').addClass('fixed');
357
    else
358
        $('.confirm_multiple').removeClass('fixed');
359
}
360

361
// indicate that the requested action was succesfully completed
362
function display_success(serverID) {
363

364
}
365

366
// indicate that the requested action was not completed
367
function display_failure(status, serverID, action, responseText) {
368
    $('#'+serverID+ ' .spinner').hide();
369
    $('#'+serverID+ ' .action_error .action').text(action);
370
    $('#'+serverID+ ' .action_error .code').text(status);
371
    $('#'+serverID+ ' .action_error .message').text(responseText);
372
    $('#'+serverID+ ' .action_error').show();    
373
}
374

375
// basic functions executed on page load
376
if (images.length == 0) {
377
    // populate image list
378
    update_images();
379
}
380
if (flavors.length == 0) {
381
    // configure flavors
382
    update_flavors(); 
383
}
384
// set the label of the multiple buttons 
385
$('div.confirm_multiple button.yes').text('Confirm All');
386
$('div.confirm_multiple button.no').text('Cancel All');
387
// reposition multiple confirmation box on window resize
388
$(window).resize(function(){
389
    if (this.innerHeight - 220 < $('#machinesview').height())
390
        $('.confirm_multiple').addClass('fixed');
391
    else
392
        $('.confirm_multiple').removeClass('fixed');
393
});
394
// start updating vm list
395
update_vms(UPDATE_INTERVAL);
396
</script>