Statistics
| Branch: | Tag: | Revision:

root / ui / templates / standard.html @ 1508a5ab

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 h3").text(serverName);
62
    var triggers = $("a#meta-editor-1").overlay({
63
        // some mask tweaks suitable for modal dialogs
64
        mask: '#000',
65
        effect: 'default',
66
        top: 'center',
67
        closeOnClick: false,
68
        oneInstance: false,
69
        load: false,
70
        onClose: function(){
71
            // With partial refresh working properly,
72
            // it is no longer necessary to refresh the whole page
73
            // choose_view();
74
        }
75
    });
76
    $("a#meta-editor-1").data('overlay').load();
77
    return false; 
78
});
79

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

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

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

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

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

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

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

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

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

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

220

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

237
        var server_image = os_icon(server.metadata);
238

239

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

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

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

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

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

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

362
}
363

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

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