Statistics
| Branch: | Tag: | Revision:

root / ui / templates / machines_single.html @ 2b56fe60

History | View | Annotate | Download (34.2 kB)

1
<!--
2
Copyright 2011 GRNET S.A. All rights reserved.
3

4
Redistribution and use in source and binary forms, with or
5
without modification, are permitted provided that the following
6
conditions are met:
7

8
  1. Redistributions of source code must retain the above
9
     copyright notice, this list of conditions and the following
10
     disclaimer.
11

12
  2. Redistributions in binary form must reproduce the above
13
     copyright notice, this list of conditions and the following
14
     disclaimer in the documentation and/or other materials
15
     provided with the distribution.
16

17
THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
18
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
21
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
24
USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
25
AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
27
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28
POSSIBILITY OF SUCH DAMAGE.
29

30
The views and conclusions contained in the software and
31
documentation are those of the authors and should not be
32
interpreted as representing official policies, either expressed
33
or implied, of GRNET S.A.
34
-->
35

    
36
{% load i18n %}
37

    
38
<!-- the single view -->
39
<div id="machinesview-single" class="single">
40
    <div class="large-spinner"></div>
41
    <div class="single-container" id="machine-container-template" style="display:none;" >
42
        <div class="upper">
43
            <div class="column1">
44
                <div class='connect-border' title='{% trans 'Connect  machine' %}'></div>
45
                <div class='connect-arrow' title='{% trans 'Connect  machine' %}'></div>
46
                <img src="static/icons/machines/large/ubuntu-on.png" class="single-image" />
47
                <div class="state">
48
                    <span class="state-label">{% trans "Running" %}</span>
49
                    <div class="indicators">
50
                        <div class="indicator1"></div>
51
                        <div class="indicator2"></div>
52
                        <div class="indicator3"></div>
53
                        <div class="indicator4"></div>
54
                    </div>
55
                    <div class="action-indicator" style="display:none"></div>
56
                    <img class="spinner" style="display:none" src="static/icons/indicators/medium/progress.gif" />
57
                    <img class="wave" style="display:none" src="static/icons/indicators/medium/wave.gif" />
58
                </div>
59
            </div>
60
            <div class="column2">
61
                <div class="machine-labels">
62
                    <div class="machine-label name">{% trans "Name" %}:</div>
63
                    <div class="machine-label cpus">{% trans "CPUs" %}:</div>
64
                    <div class="machine-label ram">{% trans "RAM (MB)" %}:</div>
65
                    <div class="machine-label disk">{% trans "System Disk (GB)" %}:</div>
66
                    <div class="machine-label image-name">{% trans "Image Name" %}:</div>
67
                    <div class="machine-label image-size">{% trans "Image Size (GB)" %}:</div>
68
                    <div class="machine-label ipv4">{% trans "Public IPv4" %}:</div>
69
                    <div class="machine-label ipv6">{% trans "Public IPv6" %}:</div>
70
                </div>
71
                <div class="machine-details">
72
                    <div class="machine-detail name">My Desktop</div>
73
                    <div class="machine-detail cpus">4</div>
74
                    <div class="machine-detail ram">2048</div>
75
                    <div class="machine-detail disk">100</div>
76
                    <div class="machine-detail image-name">windos_XP_blah_blah</div>
77
                    <div class="machine-detail image-size">2.3</div>
78
                    <div class="machine-detail ipv4">no ipv4</div>
79
                    <div class="machine-detail ipv6">2001:db8:1f70::999:de8:7648:6e8</div>
80
                </div>
81
                <div class="tags">
82
                    <div class="tags-header">
83
                        <div class="tags-label">{% trans "Tags" %}</div>
84
                        <div class="toggler down"></div>
85
                    </div>
86
                    <div class="tags-content">
87
                        <div class="metadata-keys-container">
88
                            <div class="scrollable vertical">
89
                                <div class="items">
90
                                </div>
91
                            </div>
92
                            <div class="metadata-actions">
93
                                <div class="prev"></div>
94
                                <div class="next"></div>
95
                            </div>
96
                        </div>
97
                        <a href="#" class="manage-metadata">{% trans "Manage Tags" %}</a>
98
                    </div>
99
                </div>
100
            </div>
101
            <div class="single-actions">
102
                <div class="action-container start">
103
                    <div class="single-action action-start">{% trans "Start" %}</div>
104
                    <div class="confirm_single">
105
                        <button class="yes">{% trans "Confirm" %}</button>
106
                        <button class="no">X</button>
107
                    </div>
108
                </div>
109
                <div class="action-container reboot">
110
                    <div class="single-action action-reboot">{% trans "Reboot" %}</div>
111
                    <div class="confirm_single">
112
                        <button class="yes">{% trans "Confirm" %}</button>
113
                        <button class="no">X</button>
114
                    </div>
115
                </div>
116
                <div class="action-container shutdown">
117
                    <div class="single-action action-shutdown">{% trans "Shutdown" %}</div>
118
                    <div class="confirm_single">
119
                        <button class="yes">{% trans "Confirm" %}</button>
120
                        <button class="no">X</button>
121
                    </div>
122
                </div>
123
                <div class="action-container console">
124
                    <div class="single-action action-console">{% trans "Console" %}</div>
125
                    <div class="confirm_single">
126
                        <button class="yes">{% trans "Confirm" %}</button>
127
                        <button class="no">X</button>
128
                    </div>
129
                </div>
130
                <div class="action-container destroy">
131
                    <div class="single-action action-destroy">{% trans "Destroy" %}</div>
132
                    <div class="confirm_single">
133
                        <button class="yes">{% trans "Confirm" %}</button>
134
                        <button class="no">X</button>
135
                    </div>
136
                </div>
137
            </div>
138
            <div class="action_error" align="center">
139
                {% trans "<span>Error</span> on" %} <span class="action">{% trans "error action" %}</span>
140
                <span class="code"></span>
141
                <span class="message"></span>
142
                <button class="details">{% trans "Details" %}</button>
143
            </div>
144
        </div>
145
        <div class="lower">
146
            <div class="single-cpu">
147
                <div class="cpu-usage">
148
                    {% trans "CPU Utilization" %}
149
                </div>
150
                <div class="cpu-graph">
151
                    <img src="http://stats.okeanos.grnet.gr/test/cpu-ts.png" class="stats" />
152
                </div>
153
            </div>
154
            <div class="single-network">
155
                <div class="network-usage">
156
                    {% trans "Network Utilization" %}
157
                </div>
158
                <div class="network-graph">
159
                    <img src="http://stats.okeanos.grnet.gr/test/net-ts.png" class="stats" />
160
                </div>
161
            </div>
162
        </div>
163
    </div>
164
    <div class="column3" style="display:none;">
165
        <div class="controls">
166
            <div class="previous" style="display:block;">
167
                <div class="prev-arrow"></div>
168
                <div class="prev-label">
169
                    {% trans "previous" %}
170
                </div>
171
            </div>
172
            <div class="next" style="display:block;">
173
                <div class="next-arrow"></div>
174
                <div class="next-label">
175
                    {% trans "next" %}
176
                </div>
177
            </div>
178
        </div>
179
        <div class="separator">
180
        </div>
181
        <div class="servers">
182
            <div class="server-name" id="servers-widget-template" style="display:none;">server1</div>
183
        </div>
184
    </div>
185
</div>
186

    
187
<script>
188

189
init_action_indicator_handlers('single');
190

191
//hide the all of the tags contents
192
$("#machinesview-single.single .tags-content").hide();
193

194
//toggle the component with class tags-content
195
$("#machinesview-single.single div.tags-header").live('click', function() {
196
    if ($(this).find('.toggler').hasClass('up')) {
197
        $(this).find('.toggler').removeClass('up');
198
        $(this).find('.toggler').addClass('down');
199
        $(this).find('.tags-label').removeClass('darker');
200
        $(this).parent().parent().removeClass('light-background');
201
    } else {
202
        $(this).find('.toggler').removeClass('down');
203
        $(this).find('.toggler').addClass('up');
204
        $(this).find('.tags-label').addClass('darker');
205
        $(this).parent().parent().addClass('light-background');
206
    }
207
    $(this).parent().parent().find(".tags-content").slideToggle(600);
208
    return false;
209
});
210

211
// indicate that the requested action was not completed
212
function display_failure(status, serverID, action, responseText) {
213
    $('#machinesview-single.single #'+serverID+ ' .spinner').hide();
214
    $('#machinesview-single.single #'+serverID+ ' .action_error .action').text(action);
215
    $('#machinesview-single.single #'+serverID+ ' .action_error .code').text(status);
216
    $('#machinesview-single.single #'+serverID+ ' .action_error .message').text(responseText);
217
    $('#machinesview-single.single #'+serverID+ ' .action_error').show();
218
}
219

220
// cancel action
221
$("#machinesview-single.single div.confirm_single .no").live('click', function(){
222
    pending_actions = [];
223
    $('#machinesview-single').find('div.single-action').removeClass("selected");
224
    update_confirmations();
225
});
226

227
// update metadata list
228
function list_metadata_keys(serverID, keys) {
229
    // empty the list if it already exists
230
    $("#machinesview-single.single div.#" +serverID).find("div.items").empty();
231
    //start counter
232
    var i=0;
233
    // show values
234
    for (var key in keys) {
235
        $("#machinesview-single.single div.#" +serverID).find(".items").append("<div class='item'>" + key + ": " + keys[key].substring(0,40) + "</div>");
236
        i++;
237
    }
238
    //hide the metadata controls if we have less than 3 metadata
239
    if (i <= 3) {
240
        $("#machinesview-single.single div.#" +serverID).find(".metadata-actions").hide();
241
    }
242
    //show the metadata controls if we have more than 3 metadata
243
    if (i > 3) {
244
        $("#machinesview-single.single div.#" +serverID).find(".metadata-actions").show();
245
    }
246
    $("#machinesview-single.single div.#" +serverID).find(".metadata-count").text(i);
247
}
248

249
//show error popup box
250
$("#machinesview-single.single div.action_error .details").live('click', function(){
251
    // remove the action from the pending list
252
    ajax_error($(this).parent().children('.code').text(), undefined, $(this).parent().children('.action').text(), $(this).parent().children('.message').text());
253
    $(this).parent().hide();
254
});
255

256
//confirm action
257
$("#machinesview-single.single div.confirm_single .yes").live('click', function(){
258
    var serverID = $(this).closest(".single-container").attr("id");
259
    for (i=0;i<pending_actions.length;i++){ // if there is a pending action for this server execute it
260
        if (pending_actions[i][1]==serverID){
261
            action = pending_actions.splice(i,1)[0]; // extract action
262
            // change the status text in cases where no api state exists
263
            if (action[0] == start) {
264
                $(this).closest(".single-container").find(".column1 .state-label").text(TRANSITIONS['Starting']);
265
                $(this).closest(".single-container").find(".column1 .state").removeClass().addClass('state starting-state');
266
                $(this).closest(".single-container").find(".column1 .state .spinner").show();
267
            } else if (action[0] == shutdown) {
268
                $(this).closest(".single-container").find(".column1 .state-label").text(TRANSITIONS['Shutting down']);
269
                $(this).closest(".single-container").find(".column1 .state").removeClass().addClass('state shutting-state');
270
                $(this).closest(".single-container").find(".column1 .state .spinner").show();
271
            } else if (action[0] == reboot) {
272
                $(this).closest(".single-container").find(".column1 .state-label").text(TRANSITIONS['Rebooting']);
273
                $(this).closest(".single-container").find(".column1 .state").removeClass().addClass('state rebooting-state');
274
                $(this).closest(".single-container").find(".column1 .state .spinner").show();
275
            }  else if (action[0] == destroy) {
276
                $(this).closest(".single-container").find(".column1 .state-label").text(TRANSITIONS['Destroying']);
277
                $(this).closest(".single-container").find(".column1 .state").removeClass().addClass('state destroying-state');
278
                $(this).closest(".single-container").find(".column1 .state .spinner").show();
279
            }
280
            action[0]([action[1]]); // execute action
281
        }
282
    }
283
    $(this).parent().hide();
284
    $(this).closest('div.action-container').children('div.single-action').removeClass('selected');
285
    $(this).parent().parent().find('.state').children('.spinner').show();
286
    update_confirmations();
287
    return false;
288
});
289

290
// intercept manage metadata click
291
$("#machinesview-single.single a.manage-metadata").live('click', function() {
292
    // get server name and server ID
293
    var serverID = $(this).parent().parent().parent().parent().parent().attr("id");
294
    var serverName = $(this).closest('.machine-container').find("div.machine-details div.name").text();
295
    if (['BUILD', 'ACTIVE', 'REBOOT'].indexOf($(this).parent().parent().parent().parent().parent().find(".status").text()) < 0) {
296
        $("#metadata-wizard div#on-off").text('on');
297
    } else {
298
        $("#metadata-wizard div#on-off").text('off');
299
    }
300
    // set server name to all related metadata dialogs
301
    $("#metadata-wizard div.machine-name").text(serverName);
302
    // set server id to all related metadata dialogs
303
    $("#metadata-wizard p").text(serverID);
304
    show_metadata_wizard();
305
    return false;
306
});
307

308
// intercept start click
309
$("#machinesview-single.single div.action-start").live('click', function(){
310
    var serverID = $(this).closest(".single-container").attr("id");
311
    var serverName = $(this).closest("div.upper").find(".machine-details div.name").text();
312
    $('#machinesview-single').find('div.single-action').removeClass('selected');
313
    $(this).addClass('selected');
314
    $(this).parent().parent().find('.action_error').hide();
315
    // reset pending actions so not to allow multiple actions in this view
316
    pending_actions = [];
317
    pending_actions.push([start, serverID, serverName]);
318
    update_confirmations();
319
    return false;
320
});
321

322
// intercept shutdown click
323
$("#machinesview-single.single div.action-shutdown").live('click', function(){
324
    var serverID = $(this).closest(".single-container").attr("id");
325
    var serverName = $(this).closest("div.upper").find(".machine-details div.name").text();
326
    $('#machinesview-single').find('div.single-action').removeClass('selected');
327
    $(this).addClass('selected');
328
    $(this).parent().parent().find('.action_error').hide();
329
    // reset pending actions so not to allow multiple actions in this view
330
    pending_actions = [];
331
    pending_actions.push([shutdown, serverID, serverName]);
332
    update_confirmations();
333
    return false;
334
});
335

336
// intercept reboot click
337
$("#machinesview-single.single div.action-reboot").live('click', function(){
338
    var serverID = $(this).closest(".single-container").attr("id");
339
    var serverName = $(this).closest("div.upper").find(".machine-details div.name").text();
340
    $('#machinesview-single').find('div.single-action').removeClass('selected');
341
    $(this).addClass('selected');
342
    $(this).parent().parent().find('.action_error').hide();
343
    // reset pending actions so not to allow multiple actions in this view
344
    pending_actions = [];
345
    pending_actions.push([reboot, serverID, serverName]);
346
    update_confirmations();
347
    return false;
348
});
349

350
// intercept destroy click
351
$("#machinesview-single.single div.action-destroy").live('click', function(){
352
    var serverID = $(this).closest(".single-container").attr("id");
353
    var serverName = $(this).closest("div.upper").find(".machine-details div.name").text();
354
    $('#machinesview-single').find('div.single-action').removeClass('selected');
355
    $(this).addClass('selected');
356
    $(this).parent().parent().find('.action_error').hide();
357
    // reset pending actions so not to allow multiple actions in this view
358
    pending_actions = [];
359
    pending_actions.push([destroy, serverID, serverName]);
360
    update_confirmations();
361
    return false;
362
});
363

364
// intercept console click
365
$("#machinesview-single.single div.action-console").live('click', function(){
366
    var serverID = $(this).closest(".single-container").attr("id");
367
    var serverName = $(this).closest("div.upper").find(".machine-details div.name").text();
368
    $('#machinesview-single').find('div.single-action').removeClass('selected');
369
    $(this).addClass('selected');
370
    $(this).parent().parent().find('.action_error').hide();
371
    // reset pending actions so not to allow multiple actions in this view
372
    pending_actions = [];
373
    pending_actions.push([open_console, serverID, serverName]);
374
    update_confirmations();
375
    return false;
376
});
377

378
// open console on connect arrow click
379
$("#machinesview-single.single div.connect-arrow").live('click', function(){
380
    $(this).parent().parent().find("div.action-console").click();
381
    return false;
382
});
383

384
// open console on connect arrow border click
385
$("#machinesview-single.single div.connect-border").live('click', function(){
386
    $(this).parent().parent().find("div.action-console").click();
387
    return false;
388
});
389

390
// update the servers list
391
function update_machines_view(data){
392
    /*
393
    Go through the servers in the input data. Update existing entries, add
394
    new ones to the list
395
    */
396

397
    $.each(data.servers.values, function(i,server){
398

399
        existing = $('#machinesview-single.single #' + server.id);
400
        existing_link = $('#machinesview-single div.column3 #link-' + server.id);
401
        var current_Id = current_serverId();
402

403
        // if multiple machines exist in the DOM, delete all but one
404
        // defensive coding - that shouldn't happen normally
405
        while (existing.length > 1){
406
            existing.remove();
407
        }
408
        // get server OS, if it exists
409
        if (!(server.metadata == undefined)) {
410
            var server_image = os_icon(server.metadata);
411
        } else {
412
            var server_image = "unknown"
413
        }
414
        // get server status message, if it exists
415
        var current_message = existing.find(".state-label").text();
416

417
        // server already exists in DOM
418
        if (existing.length){
419
            $("#machinesview-single.single div.single-container:last-child").find("div.separator").show();
420
            //  if the status is deleted, delete it from the DOM
421
            if (server.status == 'DELETED') {
422
                existing.remove();
423
                existing_link.remove();
424
                //if the deleted vm is the displayed one, display the 1st vm
425
                if (server.id == current_Id) {
426
                    $("#machinesview-single.single div.single-container:eq(1)").show()
427
                    $('#machinesview-single.single .column3').find('.server-name:eq(1)').addClass('column3-selected');
428
                }
429
                try {
430
                    console.info(existing.find(".machine-details div.name").text() + ' removed');
431
                } catch(err) {}
432
            }
433
            // if the status has changed
434
            else if ( current_message != STATUSES[server.status]) {
435
                /*
436
                Here there are 4 possibilities:
437
                    1. From an active state to an inactive one
438
                    2. From an inactive state to an active one
439
                    3. From an active state to a different active one
440
                    4. From an inactive state to a different inactive one
441
                The last two (3, 4) can be dealt with the same way
442
                */
443
                if (ACTIVE_STATES.indexOf(current_message) >= 0 &&
444
                    INACTIVE_STATES.indexOf(STATUSES[server.status]) >= 0) {
445
                    // from an active state to an inactive one
446
                    log_server_status_change(existing, server.status);
447
                    existing.find("img.single-image").attr("src","static/icons/machines/large/" + server_image + '-off.png');
448
                    existing.find(".column1 .state-label").text(STATUSES[server.status]);
449
                    existing.find(".connect-border").hide();
450
                    existing.find(".connect-arrow").hide();
451
                    existing.find(".column1 .state .spinner").hide();
452
                    existing.find(' .wave').attr('src','static/icons/indicators/medium/wave.gif').show();
453
                    existing.find(".column1 .state").removeClass().addClass("state terminated-state");
454
                    setTimeout("$('#" + server.id +" .wave').attr('src','').hide()", 3000);
455
                }
456
                else if (INACTIVE_STATES.indexOf(current_message) >= 0 &&
457
                         ACTIVE_STATES.indexOf(STATUSES[server.status]) >= 0) {
458
                    // From an inactive state to an active one
459
                    log_server_status_change(existing, server.status);
460
                    existing.find("img.single-image").attr("src","static/icons/machines/large/" + server_image + '-on.png');
461
                    existing.find(".column1 .state-label").text(STATUSES[server.status]);
462
                    existing.find(".connect-border").show();
463
                    existing.find(".connect-arrow").show();
464
                    existing.find(".column1 .state .spinner").hide();
465
                    existing.find(' .wave').attr('src','static/icons/indicators/medium/wave.gif').show();
466
                    existing.find(".column1 .state").removeClass().addClass("state running-state");
467
                    setTimeout("$('#" + server.id +" .wave').attr('src','').hide()", 3000);
468
                }
469
                else {
470
                    // handling active to active or inactive to inactive changes
471
                    if (TRANSITIONS[current_message] && TRANSITIONS[current_message] != 'Rebooting') {
472
                        // don't do anything if it is still in transition
473
                    }
474
                    else if ((TRANSITIONS[current_message] == 'Rebooting' && server.status == 'ACTIVE') ||
475
                             (STATUSES['BUILD'] == current_message && server.status == 'ACTIVE')) {
476
                        // if it has been rebooted or just created
477
                        log_server_status_change(existing, server.status);
478
                        existing.find(".column1 .state-label").text(STATUSES[server.status]);
479
                        existing.find(".connect-border").show();
480
                        existing.find(".connect-arrow").show();
481
                        existing.find(".column1 .state .spinner").hide();
482
                        existing.find(".column1 .state").attr('src','static/icons/indicators/medium/wave.gif').show();
483
                        existing.find(".column1 .state").removeClass().addClass("state running-state");
484
                        setTimeout("$('#" + server.id +" .wave').attr('src','').hide()", 3000);
485
                    }
486
                    else {
487
                        // in any other case just change the status and ignore spinners/waves
488
                        existing.find(".column1 .state-label").text(STATUSES[server.status]);
489
                    }
490
                }
491
            }
492
            // find and display ips
493
            var ips = get_public_ips(server);
494
            existing.find(".machine-details div.ipv4").text(ips['ip4']);
495
            existing.find(".machine-details div.ipv6").text(ips['ip6']);
496

497
        } else if (server.status != 'DELETED') {
498
            // If it does not exist and it's not deleted, we should create it
499
            var serverwidget = $("#servers-widget-template").clone().attr("id", 'link-' + server.id);
500
            if (server.name.length > 18) {
501
                serverwidget.text(server.name.substring(0,15) + '...');
502
            } else {
503
                serverwidget.text(server.name)
504
            }
505
            serverwidget.appendTo('.servers');
506
            serverwidget.show();
507
            //find and hide the previously selected server
508
            $('.single').find('.single-container').hide();
509
            $('.single .column3').find('.column3-selected').removeClass('column3-selected');
510
            //create and select the new one
511
            var machine = $("#machinesview-single.single #machine-container-template").clone().attr("id", server.id);
512
            machine.find(".scrollable").scrollable({vertical: true});
513
            machine.find(".machine-details div.name").text(server.name.substring(0,30));
514
            machine.find("img.single-image").attr("src","static/icons/machines/large/"+server_image+'-on.png');
515
            machine.find("span.imagetag").text(server_image);
516
            machine.find(".column1 .state-label").text(STATUSES[server.status]);
517
            // find and display flavor parameters
518
            var flavor_params = get_flavor_params(server.flavorRef);
519
            machine.find(".machine-details div.cpus").text(flavor_params['cpus']);
520
            machine.find(".machine-details div.ram").text(flavor_params['ram']);
521
            machine.find(".machine-details div.disk").text(flavor_params['disk']);
522
            // find and display image parameters
523
            var image_params = get_image_params(server.imageRef);
524
            machine.find(".machine-details div.image-name").text(image_params['name'].substring(0,15));
525
            machine.find(".machine-details div.image-size").text(image_params['size']);
526
            // find and display ips
527
            var ips = get_public_ips(server);
528
            machine.find(".machine-details div.ipv4").text(ips['ip4']);
529
            machine.find(".machine-details div.ipv6").text(ips['ip6']);
530
            //show off image if server is not active
531
            if (['BUILD', 'ACTIVE', 'REBOOT'].indexOf(server.status) < 0){
532
                    machine.find("img.single-image").attr("src","static/icons/machines/large/"+server_image+'-off.png');
533
                    machine.find(".connect-border").hide();
534
                    machine.find(".connect-arrow").hide();
535
                    machine.find(".column1 .state").removeClass().addClass("state terminated-state");
536
            }
537
            //show spinner while machine is building or rebooting
538
            if (server.status == 'BUILD' ||
539
                [TRANSITIONS['Starting'], TRANSITIONS['Shutting down']].indexOf(existing.find(".status").text()) >= 0 ) {
540
                machine.find(".column1 .state .spinner").show();
541
                machine.find(".connect-border").hide();
542
                machine.find(".connect-arrow").hide();
543
                machine.find(".column1 .state").removeClass().addClass('state build-state');
544
            }
545
            if (server.status == 'REBOOT') {
546
                machine.find(".column1 .state").find('.spinner').show();
547
                machine.find(".connect-border").hide();
548
                machine.find(".connect-arrow").hide();
549
                machine.find(".column1 .state").removeClass().addClass('state rebooting-state');
550
            }
551
            machine.appendTo("#machinesview-single.single");
552
            //disable reboot and shutdown actions while machine is building
553
            if (server.status == 'BUILD') {
554
                $('#machinesview-single.single div.#' + server.id + ' div.action-reboot').hide();
555
                $('#machinesview-single.single div.#' + server.id + ' div.action-shutdown').hide();
556
            }
557
            // show console action only on active servers
558
            if (server.status == 'ACTIVE') {
559
                $('#machinesview-single.single div.#' + server.id + ' div.action-console').show();
560
                $('#machinesview-single.single div.#' + server.id + ' div.action-start').hide();
561
                machine.find(".connect-border").show();
562
                machine.find(".connect-arrow").show();
563
            } else if (server.status == 'REBOOT'){
564
                $('#machinesview-single.single div.#' + server.id + ' div.action-console').hide();
565
            } else {
566
                $('#machinesview-single.single div.#' + server.id + ' div.action-console').hide();
567
                $('#machinesview-single.single div.#' + server.id + ' div.action-reboot').hide();
568
                $('#machinesview-single.single div.#' + server.id + ' div.action-shutdown').hide();
569
            }
570
            //show the first machine and select it in the widget
571
            $('.single-container:eq(1)').show();
572
            $('.single .column3').find('.server-name:eq(1)').addClass('column3-selected');
573
        }
574
        update_iconview_actions(server.id, server.status);
575
        if (!(server.metadata == undefined)) {
576
                list_metadata_keys(server.id, server.metadata.values);
577
        }
578
    });
579

580
    // hide pane spinner
581
    $("#machinesview-single.single > div.large-spinner").hide();
582

583
    // show message in case user has no server!
584
    if ($('#machinesview-single div.single-container').length == 1) {
585
        showWelcome();
586
    } else {
587
        hideWelcome();
588
        $('.single .column3').show();
589
    }
590

591
    //enable widget links
592
    $(".server-name").live('click', function() {
593
        $('.single').find('.single-container').hide()
594
        $('.single').find('#' + $(this).attr('id').substring(5)).show();
595
        $('.single .column3').find('.column3-selected').removeClass('column3-selected');
596
        $(this).addClass('column3-selected');
597
        update_prev_next()
598
    });
599

600
    if ($.cookie('server')) {
601
        $('div#link-' + $.cookie('server')).click();
602
        $.cookie('server', null);
603
    }
604

605
    //if it is the last vm, disable the next button
606
    if ($("#machinesview-single.single .column3 .column3-selected").attr("id") == $("#machinesview-single.single .column3 .server-name:last").attr("id")) {
607
        $("#machinesview-single.single .column3 .next").addClass('disabled');
608
    }
609

610
    //if it is the first vm, disable the prev button
611
    if ($("#machinesview-single.single .column3 .column3-selected").attr("id") == $("#machinesview-single.single .column3 .server-name:eq(1)").attr("id")) {
612
        $("#machinesview-single.single .column3 .previous").addClass('disabled');
613
    }
614
}
615

616
//get currently displayed serverId
617
function current_serverId() {
618
    return $("#machinesview-single.single").find("div.single-container:visible").attr("id");
619
}
620

621
//enable prev-next buttons
622
$("#machinesview-single.single .column3 .previous").live('click', function() {
623
    // set behavior
624
    if ($("#machinesview-single.single .column3 .column3-selected").attr("id") == $("#machinesview-single.single .column3 .server-name:eq(1)").attr("id")) {
625
        return false;
626
    } else {
627
        current_server = $('#machinesview-single.single .column3').find('.column3-selected').attr("id").substring(5);
628
        $('#machinesview-single.single').find('#' + current_server).hide();
629
        $('#machinesview-single.single').find('#' + current_server).prev().show();
630
        $('#machinesview-single.single .column3').find('#link-' + current_server).removeClass('column3-selected');
631
        $('#machinesview-single.single .column3').find('#link-' + current_server).prev().addClass('column3-selected');
632
        update_prev_next()
633
        return false;
634
    }
635
});
636

637
$("#machinesview-single.single .column3 .next").live('click', function() {
638
    // set behavior
639
    if ($("#machinesview-single.single .column3 .column3-selected").attr("id") == $("#machinesview-single.single .column3 .server-name:last").attr("id")) {
640
        return false;
641
        } else {
642
        current_server = $('#machinesview-single.single .column3').find('.column3-selected').attr("id").substring(5);
643
        $('#machinesview-single.single').find('#' + current_server).hide();
644
        $('#machinesview-single.single').find('#' + current_server).next().show();
645
        $('#machinesview-single.single .column3').find('#link-' + current_server).removeClass('column3-selected');
646
        $('#machinesview-single.single .column3').find('#link-' + current_server).next().addClass('column3-selected');
647
        update_prev_next()
648
        return false;
649
    }
650
});
651

652

653
//enables-disables previous/next buttons accordingly
654
function update_prev_next() {
655
    if ($("#machinesview-single.single .column3 .column3-selected").attr("id") != $("#machinesview-single.single .column3 .server-name:eq(1)").attr("id")) {
656
        $(".single .column3 .previous").removeClass('disabled');
657
    } else {
658
        //disable class
659
        $(".single .column3 .previous").addClass('disabled');
660
    }
661
    if ($("#machinesview-single.single .column3 .column3-selected").attr("id") != $("#machinesview-single.single .column3 .server-name:last").attr("id")) {
662
        $(".single .column3 .next").removeClass('disabled');
663
    } else {
664
        //disable class
665
        $(".single .column3 .next").addClass('disabled');
666
    }
667
}
668

669
// basic functions executed on page load
670
if ( flavors.length == 0 && images.length == 0 ) {
671
    // configure flavors, this also calls update_vms(UPDATE_INTERVAL)
672
    update_flavors();
673
    // populate image list
674
    update_images();
675
} else if ( flavors.length == 0 && images.length != 0 ) {
676
    // configure flavors, this also calls update_vms(UPDATE_INTERVAL)
677
    update_flavors();
678
} else if ( flavors.length != 0 && images.length == 0 ) {
679
    // populate image list
680
    update_images();
681
    update_vms(UPDATE_INTERVAL);
682
} else {
683
    // start updating vm list
684
    update_vms(UPDATE_INTERVAL);
685
}
686

687
//IE specific fixes
688
if ($.browser.msie) {
689
    //IE fix for green arrow hover
690
    $("div.connect-arrow").live("mouseenter", function () {
691
        $(this).addClass("connect-arrow-ie");
692
    });
693
    $("div.connect-arrow").live("mouseleave", function () {
694
        $(this).removeClass("connect-arrow-ie");
695
    });
696
}
697

    
698
</script>