Statistics
| Branch: | Tag: | Revision:

root / ui / templates / standard.html @ 198e13aa

History | View | Annotate | Download (15.1 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:" %} <a href="#">{% trans "disks" %}</a> | <a href="#">{% trans "networks" %}</a> | <a href="#">{% trans "group" %}</a>
31
        </h5>
32

    
33
        <div class="confirm_single">
34
            <button class="yes">{% trans "Confirm" %}</button>
35
            <button class="no">{% trans "Cancel" %}</button>
36
        </div>
37
        <div class="action_error" align="center">
38
            {% trans "<span class='orange'>Error</span> on" %} <span class="action">{% trans "error action" %}</span>
39
            <span class="code"></span>            
40
            <span class="message"></span>
41
            <button class="details">{% trans "Details" %}</button>
42
        </div>
43
        <div class="separator"></div>
44
    </div>
45

    
46
    <div class="running"></div>
47
    <div id="mini" class="separator"></div>
48
    <div class="terminated"></div>
49
</div>
50

    
51
<script>
52
    
53
// intercept reboot click 
54
$("div.actions a.action-reboot").live('click', function(){
55
    var serverID = $(this).parent().parent().attr("id");
56
    var serverName = $(this).parent().prevAll("a.name").find("span.name").text();
57
    var found = false;
58
    
59
    $(this).parent().children('a').removeClass('selected');
60
    $(this).addClass('selected');
61
    $(this).parent().addClass('display');
62
    $(this).parent().parent().find('.action_error').hide();
63
    for (i=0;i<pending_actions.length;i++){ // if there is already a pending action for this server replace it
64
        if (pending_actions[i][1]==serverID){
65
            pending_actions[i][0] = reboot;
66
            found = true
67
        }
68
    }
69
    if (!found) // no pending action for this server was found, so let's just add it to the list
70
        pending_actions.push([reboot, serverID, serverName])
71
    update_confirmations();
72
    return false;
73
});
74

75
// intercept shutdown click
76
$("div.actions a.action-shutdown").live('click', function(){ 
77
    var serverID = $(this).parent().parent().attr("id");
78
    var serverName = $(this).parent().prevAll("a.name").find("span.name").text();
79
    var found = false;
80
    $(this).parent().children('a').removeClass('selected');
81
    $(this).addClass('selected');
82
    $(this).parent().addClass('display')
83
    $(this).parent().parent().find('.action_error').hide();
84

85
    for (i=0;i<pending_actions.length;i++){ // if there is already a pending action for this server replace it
86
        if (pending_actions[i][1]==serverID){
87
            pending_actions[i][0] = shutdown;
88
            found = true
89
        }
90
    }
91
    if (!found) // no pending action for this server was found, so let's just add it to the list 
92
        pending_actions.push([shutdown, serverID, serverName])
93
    update_confirmations();
94
    return false;
95
});
96

97
// intercept start click
98
$("div.actions a.action-start").live('click', function(){ 
99
    var serverID = $(this).parent().parent().attr("id");
100
    var serverName = $(this).parent().prevAll("a.name").find("span.name").text();
101
    var found = false;
102
    $(this).parent().children('a').removeClass('selected');
103
    $(this).addClass('selected');
104
    $(this).parent().addClass('display')
105
    $(this).parent().parent().find('.action_error').hide();
106

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

119
// intercept destroy click
120
$("div.actions a.action-destroy").live('click', function(){ 
121
    var serverID = $(this).parent().parent().attr("id");
122
    var serverName = $(this).parent().prevAll("a.name").find("span.name").text();
123
    var found = false;
124
    $(this).parent().children('a').removeClass('selected');
125
    $(this).addClass('selected');
126
    $(this).parent().addClass('display')
127
    $(this).parent().parent().find('.action_error').hide();
128

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

141
$("div.confirm_single .yes").live('click', function(){
142
    var serverID = $(this).parent().parent().attr("id");
143
    for (i=0;i<pending_actions.length;i++){ // if there is a pending action for this server execute it
144
        if (pending_actions[i][1]==serverID){
145
            action = pending_actions.splice(i,1)[0]; // extract action
146
            // change the status text in cases where no api state exists
147
            if (action[0] == start) {
148
                $(this).parent().parent().find('.status').text('Starting');
149
                $(this).parent().parent().find('.spinner').show();
150
            } else if (action[0] == shutdown) {
151
                $(this).parent().parent().find('.status').text('Shutting down');
152
                $(this).parent().parent().find('.spinner').show();
153
            }                  
154
            action[0]([action[1]]); // execute action
155
        }
156
    }
157
    $(this).parent().hide();
158
    $(this).parent().parent().children('div.actions').children('a').removeClass('selected');
159
    $(this).parent().parent().children('.state').children('.spinner').show()
160
    $(this).parent().parent().children('div.actions').removeClass('display');
161
    update_confirmations(); 
162
    return false;
163
});
164

165
$("div.confirm_single .no").live('click', function(){
166
    // remove the action from the pending list
167
    var serverID = $(this).parent().parent().attr("id");
168
    
169
    $(this).parent().parent().children('div.actions').children('a').removeClass('selected');
170
    $(this).parent().parent().children('div.actions').removeClass('display');    
171
    for (i=0;i<pending_actions.length;i++){ // if there is a pending action for this server remove it
172
        if (pending_actions[i][1]==serverID){
173
            pending_actions.splice(i,1);
174
        }
175
    }
176
    $(this).parent().hide();
177
    update_confirmations();    
178
    return false;
179
});
180

181
$("div.action_error .details").live('click', function(){
182
    // remove the action from the pending list
183
    ajax_error($(this).parent().children('.code').text(), undefined, $(this).parent().children('.action').text(), $(this).parent().children('.message').text());
184
    $(this).parent().hide();
185
});
186

187

188
// update the servers list
189
function update_machines_view(data){
190
    /* 
191
    Go through the servers in the input data. Update existing entries, add
192
    new ones to the list
193
    */    
194
    $.each(data.servers.values, function(i,server){
195
        existing = $('#' + server.id);
196
        
197
        // if multiple machines exist in the DOM, delete all but one
198
        // defensive coding - that shouldn't happen normally
199
        while (existing.length > 1){
200
            existing.remove();
201
        }
202
        
203
        // server already exists in DOM
204
        if (existing.length){
205
            $("div.machine:last-child").find("div.separator").show();                
206

207
            //  if the status is deleted, delete it from the DOM
208
            if (server.status == 'DELETED') {
209
                existing.remove();            
210
                try {
211
                    console.info(existing.find("a.name span.name").text() + ' removed');
212
                } catch(err) {}            
213
            } else if (existing.find(".status").text() != STATUS_MESSAGES[server.status]) {
214

215
                try { // firebug console logging
216
                    console.info(existing.find("a.name span.name").text() + ' from ' 
217
                                + existing.find(".status").text() + ' to ' + STATUS_MESSAGES[server.status]);
218
                } catch(err) {}
219

220
                if (['BUILD','ACTIVE','REBOOT'].indexOf(server.status) >= 0 &&
221
                    [STATUS_MESSAGES['STOPPED'], STATUS_MESSAGES['ERROR']].indexOf(existing.find(".status").text())>=0){
222
                    // from stopped to running
223
                    moved = existing.clone().appendTo(".running");
224
                    moved.find("img.logo").attr("src","static/machines/"+image_tags[server.imageRef]+'.png');
225
                    existing.remove();
226
                    existing = moved;
227
                    existing.find(".status").text(STATUS_MESSAGES[server.status]);          
228
                } else if (['STOPPED','ERROR'].indexOf(server.status) >= 0 &&
229
                           [STATUS_MESSAGES['ACTIVE'], STATUS_MESSAGES['BUILD'], STATUS_MESSAGES['REBOOT']].indexOf(existing.find(".status").text()) >= 0) {
230
                    // from running to stopped
231
                    moved = existing.clone().appendTo(".terminated");
232
                    moved.find("img.logo").attr("src","static/machines/"+image_tags[server.imageRef]+'-off.png');
233
                    existing.remove();
234
                    existing = moved;
235
                    existing.find(".status").text(STATUS_MESSAGES[server.status]);          
236
                } else if (server.status == 'ACTIVE' && existing.find(".status").text() == 'Starting') {
237
                    moved = existing.clone().appendTo(".running");
238
                    moved.find("img.logo").attr("src","static/machines/"+image_tags[server.imageRef]+'.png');
239
                    existing.remove();
240
                    existing = moved;
241
                    existing.find(".status").text(STATUS_MESSAGES['ACTIVE']);
242
                } else if (server.status == 'STOPPED' && existing.find(".status").text() == 'Shutting down') {
243
                    moved = existing.clone().appendTo(".terminated");
244
                    moved.find("img.logo").attr("src","static/machines/"+image_tags[server.imageRef]+'-off.png');
245
                    existing.remove();
246
                    existing = moved;
247
                    existing.find(".status").text(STATUS_MESSAGES['STOPPED']);
248
                }
249
                existing.find('.spinner').hide();
250
                existing.find(' .wave').attr('src','static/wave.gif').show();
251
                setTimeout("$('#" + server.id +" .wave').attr('src','').hide()", 3000);
252
                // show spinner while machine is rebooting 
253
                if (server.status == 'REBOOT' ||
254
                    ['Starting', 'Shutting down'].indexOf(existing.find(".status").text()) >= 0 ) {
255
                    existing.find(' .wave').hide();
256
                    existing.find('.spinner').show();
257
                }                            
258
            }
259
            existing.find("a.name span.name").text(server.name);
260
            existing.find("a.ip span.public").text(String(server.addresses.values[0].values[0].addr).replace(',',' '));
261
        } else if (server.status != 'DELETED') {
262
            // If it does not exist and it's not deleted, we should create it
263
            var machine = $("#machine-template").clone().attr("id", server.id).fadeIn("slow");
264
            machine.find("a.name span.name").text(server.name);
265
            machine.find("img.logo").attr("src","static/machines/"+image_tags[server.imageRef]+'.png');
266
            machine.find("span.imagetag").text(image_tags[server.imageRef]);
267
            machine.find("a.ip span.public").text(String(server.addresses.values[0].values[0].addr).replace(',',' '));            
268
            machine.find(".status").text(STATUS_MESSAGES[server.status]);
269
            if (['BUILD', 'ACTIVE', 'REBOOT'].indexOf(server.status) >= 0){
270
                machine.appendTo(".running");
271
            } else {
272
                //show spinner while machine is building
273
                machine.find("img.logo").attr("src","static/machines/"+image_tags[server.imageRef]+'-off.png');
274
                machine.appendTo(".terminated");
275
            }
276
            //show spinner while machine is building
277
            if (server.status == 'BUILD' || 
278
                ['Starting', 'Shutting down'].indexOf(existing.find(".status").text()) >= 0 ) { 
279
                machine.find('.spinner').show();
280
            }   
281
        }
282
    });
283

284
    $("#spinner").hide();
285
    // show all separators
286
    $("div.machine div.separator").show();
287
    // hide the last one
288
    $("div.machine:last-child").find("div.separator").hide();
289
    // the separator shows only when running and terminated machines are available
290
    if ($(".terminated a.name").length > 0 && $(".running a.name").length > 0) {
291
        $("#mini.separator").fadeIn("slow");
292
    } else {
293
        $("#mini.separator").fadeOut("slow");
294
    }
295

296
    // show message in case user has no servers!
297
    if (servers.length == 0) {
298
        showWelcome()
299
    } else {
300
        hideWelcome()
301
    }           
302
    
303
    // set confirm box position
304
    if (window.innerHeight - 220 < $('#machinesview').height())
305
        $('.confirm_multiple').addClass('fixed');
306
    else
307
        $('.confirm_multiple').removeClass('fixed');
308
}
309

310
// indicate that the requested action was succesfully completed
311
function display_success(serverID) {
312

313
}
314

315
// indicate that the requested action was not completed
316
function display_failure(status, serverID, action, responseText) {
317
    $('#'+serverID+ ' .spinner').hide();
318
    $('#'+serverID+ ' .action_error .action').text(action);
319
    $('#'+serverID+ ' .action_error .code').text(status);
320
    $('#'+serverID+ ' .action_error .message').text(responseText);
321
    $('#'+serverID+ ' .action_error').show();
322
    
323
}
324

325
if (images.length == 0) {
326
    // populate image list
327
    update_images();
328
}
329
if (flavors.length == 0) {
330
    // configure flavors
331
    update_flavors(); 
332
}
333
// set the label of the multiple buttons 
334
$('div.confirm_multiple button.yes').text('Confirm All');
335
$('div.confirm_multiple button.no').text('Cancel All');
336

337
// reposition multiple confirmation box on window resize
338
$(window).resize(function(){
339
    if (this.innerHeight - 220 < $('#machinesview').height())
340
        $('.confirm_multiple').addClass('fixed');
341
    else
342
        $('.confirm_multiple').removeClass('fixed');
343
});
344

345
// start updating vm list
346
update_vms(UPDATE_INTERVAL);
347
</script>