Statistics
| Branch: | Tag: | Revision:

root / ui / templates / machines_single.html @ b13b401f

History | View | Annotate | Download (31.6 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'></div>
45
                <div class='connect-arrow'></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
                    <img class="spinner" style="display:none" src="static/icons/indicators/medium/progress.gif" />
56
                    <img class="wave" style="display:none" src="static/icons/indicators/medium/wave.gif" />
57
                </div>
58
            </div>
59
            <div class="column2">
60
                <div class="machine-labels">
61
                    <div class="machine-label name">{% trans "Name" %}:</div>
62
                    <div class="machine-label cpus">{% trans "CPUs" %}:</div>
63
                    <div class="machine-label ram">{% trans "RAM (MB)" %}:</div>
64
                    <div class="machine-label disk">{% trans "System Disk (GB)" %}:</div>
65
                    <div class="machine-label image-name">{% trans "Image Name" %}:</div>
66
                    <div class="machine-label image-size">{% trans "Image Size (GB)" %}:</div>
67
                    <div class="machine-label ipv4">{% trans "Public IPv4" %}:</div>
68
                    <div class="machine-label ipv6">{% trans "Public IPv6" %}:</div>
69
                </div>
70
                <div class="machine-details">
71
                    <div class="machine-detail name">My Desktop</div>
72
                    <div class="machine-detail cpus">4</div>
73
                    <div class="machine-detail ram">2048</div>
74
                    <div class="machine-detail disk">100</div>
75
                    <div class="machine-detail image-name">windos_XP_blah_blah</div>
76
                    <div class="machine-detail image-size">2.3</div>
77
                    <div class="machine-detail ipv4">no ipv4</div>
78
                    <div class="machine-detail ipv6">2001:db8:1f70::999:de8:7648:6e8</div>
79
                </div>
80
                <div class="tags">
81
                    <div class="tags-header">
82
                        <div class="tags-label">
83
                            {% trans "Tags" %}
84
                        </div>
85
                        <div class="tags-down-arrow">
86
                        </div>
87
                    </div>
88
                    <div class="tags-content">
89
                    </div>
90
                </div>
91
            </div>
92
            <div class="single-actions">
93
                <div class="action-container start">
94
                    <div class="single-action action-start">{% trans "Start" %}</div>
95
                    <div class="confirm_single">
96
                        <button class="yes">{% trans "Confirm" %}</button>
97
                        <button class="no">X</button>
98
                    </div>
99
                </div>
100
                <div class="action-container reboot">
101
                    <div class="single-action action-reboot">{% trans "Reboot" %}</div>
102
                    <div class="confirm_single">
103
                        <button class="yes">{% trans "Confirm" %}</button>
104
                        <button class="no">X</button>
105
                    </div>
106
                </div>
107
                <div class="action-container shutdown">
108
                    <div class="single-action action-shutdown">{% trans "Shutdown" %}</div>
109
                    <div class="confirm_single">
110
                        <button class="yes">{% trans "Confirm" %}</button>
111
                        <button class="no">X</button>
112
                    </div>
113
                </div>
114
                <div class="action-container console">
115
                    <div class="single-action action-console">{% trans "Console" %}</div>
116
                    <div class="confirm_single">
117
                        <button class="yes">{% trans "Confirm" %}</button>
118
                        <button class="no">X</button>
119
                    </div>
120
                </div>
121
                <div class="action-container destroy">
122
                    <div class="single-action action-destroy">{% trans "Destroy" %}</div>
123
                    <div class="confirm_single">
124
                        <button class="yes">{% trans "Confirm" %}</button>
125
                        <button class="no">X</button>
126
                    </div>
127
                </div>
128
            </div>
129
            <div class="action_error" align="center">
130
                {% trans "<span>Error</span> on" %} <span class="action">{% trans "error action" %}</span>
131
                <span class="code"></span>
132
                <span class="message"></span>
133
                <button class="details">{% trans "Details" %}</button>
134
            </div>
135
        </div>
136
        <div class="lower">
137
            <div class="single-cpu">
138
                <div class="cpu-usage">
139
                    {% trans "CPU Usage" %}<span class="toggler">&#710;</span>
140
                </div>
141
                <div class="cpu-graph">
142

    
143
                </div>
144
            </div>
145
            <div class="single-network">
146
                <div class="network-usage">
147
                    {% trans "Network Usage" %}<span class="toggler">&#710;</span>
148
                </div>
149
                <div class="network-graph">
150

    
151
                </div>
152
            </div>
153
        </div>
154
    </div>
155
    <div class="column3">
156
        <div class="controls">
157
            <div class="previous" style="display:none;">
158
                <div class="prev-arrow"></div>
159
                {% trans "previous" %}
160
            </div>
161
            <div class="next" style="display:none;">
162
                {% trans "next" %}
163
                <div class="next-arrow"></div>
164
            </div>
165
        </div>
166
        <div class="separator">
167
        </div>
168
        <div class="servers">
169
            <div class="server-name" id="servers-widget-template" style="display:none;">server1</div>
170
        </div>
171
    </div>
172
</div>
173

    
174
<script>
175

176
//hide the all of the info contents
177
$("#machinesview-single.single .disks-content").hide();
178
$("#machinesview-single.single .networks-content").hide();
179
$("#machinesview-single.single .stats-content").hide();
180

181
// indicate that the requested action was not completed
182
function display_failure(status, serverID, action, responseText) {
183
    $('#machinesview-single.single #'+serverID+ ' .spinner').hide();
184
    $('#machinesview-single.single #'+serverID+ ' .action_error .action').text(action);
185
    $('#machinesview-single.single #'+serverID+ ' .action_error .code').text(status);
186
    $('#machinesview-single.single #'+serverID+ ' .action_error .message').text(responseText);
187
    $('#machinesview-single.single #'+serverID+ ' .action_error').show();
188
}
189

190
// cancel action
191
$("#machinesview-single.single div.confirm_single .no").live('click', function(){
192
    pending_actions = [];
193
    $(".selected").removeClass("selected");
194
    update_confirmations();
195
});
196

197
//show error popup box
198
$("#machinesview-single.single div.action_error .details").live('click', function(){
199
    // remove the action from the pending list
200
    ajax_error($(this).parent().children('.code').text(), undefined, $(this).parent().children('.action').text(), $(this).parent().children('.message').text());
201
    $(this).parent().hide();
202
});
203

204
//confirm action
205
$("#machinesview-single.single div.confirm_single .yes").live('click', function(){
206
    var serverID = $(this).closest(".single-container").attr("id");
207
    console.info(serverID);
208
    for (i=0;i<pending_actions.length;i++){ // if there is a pending action for this server execute it
209
        if (pending_actions[i][1]==serverID){
210
            action = pending_actions.splice(i,1)[0]; // extract action
211
            // change the status text in cases where no api state exists
212
            if (action[0] == start) {
213
                $(this).parent().parent().find('.state-label').text(TRANSITIONS['Starting']);
214
                $(this).parent().parent().find('.state').removeClass().addClass('state starting-state');
215
                $(this).parent().parent().find('.spinner').show();
216
            } else if (action[0] == shutdown) {
217
                $(this).parent().parent().find('.state-label').text(TRANSITIONS['Shutting down']);
218
                $(this).parent().parent().find('.state').removeClass().addClass('state shutting-state');
219
                $(this).parent().parent().find('.spinner').show();
220
            } else if (action[0] == reboot) {
221
                $(this).parent().parent().find('.state-label').text(TRANSITIONS['Rebooting']);
222
                $(this).parent().parent().find('.state').removeClass().addClass('state rebooting-state');
223
                $(this).parent().parent().find('.spinner').show();
224
            }  else if (action[0] == destroy) {
225
                $(this).parent().parent().find('.state-label').text(TRANSITIONS['Destroying']);
226
                $(this).parent().parent().find('.state').removeClass().addClass('state destroying-state');
227
                $(this).parent().parent().find('.spinner').show();
228
            }
229
            action[0]([action[1]]); // execute action
230
        }
231
    }
232
    $(this).parent().hide();
233
    $(this).closest('div.action-container').children('div.single-action').removeClass('selected');
234
    $(this).parent().parent().children('.state').children('.spinner').show()
235
    update_confirmations();
236
    return false;
237
});
238

239

240
// intercept start click
241
$("#machinesview-single.single div.action-start").live('click', function(){
242
    var serverID = $(this).closest(".single-container").attr("id");
243
    var serverName = $(this).closest("div.upper").find(".machine-details div.name").text();
244
    $('#machinesview-single').find('div.single-action').removeClass('selected');
245
    $(this).addClass('selected');
246
    $(this).parent().parent().find('.action_error').hide();
247
    // reset pending actions so not to allow multiple actions in this view
248
    pending_actions = [];
249
    pending_actions.push([start, serverID, serverName]);
250
    update_confirmations();
251
    return false;
252
});
253

254
// intercept shutdown click
255
$("#machinesview-single.single div.action-shutdown").live('click', function(){
256
    var serverID = $(this).closest(".single-container").attr("id");
257
    var serverName = $(this).closest("div.upper").find(".machine-details div.name").text();
258
    $('#machinesview-single').find('div.single-action').removeClass('selected');
259
    $(this).addClass('selected');
260
    $(this).parent().parent().find('.action_error').hide();
261
    // reset pending actions so not to allow multiple actions in this view
262
    pending_actions = [];
263
    pending_actions.push([shutdown, serverID, serverName]);
264
    update_confirmations();
265
    return false;
266
});
267

268
// intercept reboot click
269
$("#machinesview-single.single div.action-reboot").live('click', function(){
270
    var serverID = $(this).closest(".single-container").attr("id");
271
    var serverName = $(this).closest("div.upper").find(".machine-details div.name").text();
272
    $('#machinesview-single').find('div.single-action').removeClass('selected');
273
    $(this).addClass('selected');
274
    $(this).parent().parent().find('.action_error').hide();
275
    // reset pending actions so not to allow multiple actions in this view
276
    pending_actions = [];
277
    pending_actions.push([reboot, serverID, serverName]);
278
    update_confirmations();
279
    return false;
280
});
281

282
// intercept destroy click
283
$("#machinesview-single.single div.action-destroy").live('click', function(){
284
    var serverID = $(this).closest(".single-container").attr("id");
285
    var serverName = $(this).closest("div.upper").find(".machine-details div.name").text();
286
    $('#machinesview-single').find('div.single-action').removeClass('selected');
287
    $(this).addClass('selected');
288
    $(this).parent().parent().find('.action_error').hide();
289
    // reset pending actions so not to allow multiple actions in this view
290
    pending_actions = [];
291
    pending_actions.push([destroy, serverID, serverName]);
292
    update_confirmations();
293
    return false;
294
});
295

296
// intercept console click
297
$("#machinesview-single.single div.action-console").live('click', function(){
298
    var serverID = $(this).closest(".single-container").attr("id");
299
    var serverName = $(this).closest("div.upper").find(".machine-details div.name").text();
300
    $('#machinesview-single').find('div.single-action').removeClass('selected');
301
    $(this).addClass('selected');
302
    $(this).parent().parent().find('.action_error').hide();
303
    // reset pending actions so not to allow multiple actions in this view
304
    pending_actions = [];
305
    pending_actions.push([open_console, serverID, serverName]);
306
    update_confirmations();
307
    return false;
308
});
309

310
// open console on connect arrow click
311
$("#machinesview-single.single div.connect-arrow").live('click', function(){
312
    $(this).parent().parent().find("div.action-console").click();
313
    return false;
314
});
315

316
// open console on connect arrow border click
317
$("#machinesview-single.single div.connect-border").live('click', function(){
318
    $(this).parent().parent().find("div.action-console").click();
319
    return false;
320
});
321

322
// update the servers list
323
function update_machines_view(data){
324
    /*
325
    Go through the servers in the input data. Update existing entries, add
326
    new ones to the list
327
    */
328

329
    $.each(data.servers.values, function(i,server){
330

331
        existing = $('#machinesview-single.single #' + server.id);
332
        existing_link = $('#machinesview-single div.column3 #link-' + server.id);
333
        var current_Id = current_serverId();
334

335
        //hide next button if there is only one vm
336
        if (data.servers.values.length == 1) {
337
            $("#machinesview-single.single .column3 .next").hide();
338
        }
339

340
        // if multiple machines exist in the DOM, delete all but one
341
        // defensive coding - that shouldn't happen normally
342
        while (existing.length > 1){
343
            existing.remove();
344
        }
345
        // get server OS, if it exists
346
        if (!(server.metadata == undefined)) {
347
            var server_image = os_icon(server.metadata);
348
        } else {
349
            var server_image = "unknown"
350
        }
351
        // get server status message, if it exists
352
        var current_message = existing.find(".state-label").text();
353

354
        // server already exists in DOM
355
        if (existing.length){
356
            $("#machinesview-single.single div.single-container:last-child").find("div.separator").show();
357
            //  if the status is deleted, delete it from the DOM
358
            if (server.status == 'DELETED') {
359
                existing.remove();
360
                existing_link.remove();
361
                //if the deleted vm is the displayed one, display the 1st vm
362
                if (server.id == current_Id) {
363
                    $("#machinesview-single.single div.single-container:eq(1)").show()
364
                    $('#machinesview-single.single .column3').find('.server-name:eq(1)').addClass('selected');
365
                }
366
                try {
367
                    console.info(existing.find(".machine-details div.name").text() + ' removed');
368
                } catch(err) {}
369
            }
370
            // if the status has changed
371
            else if ( current_message != STATUSES[server.status]) {
372
                /*
373
                Here there are 4 possibilities:
374
                    1. From an active state to an inactive one
375
                    2. From an inactive state to an active one
376
                    3. From an active state to a different active one
377
                    4. From an inactive state to a different inactive one
378
                The last two (3, 4) can be dealt with the same way
379
                */
380
                if (ACTIVE_STATES.indexOf(current_message) >= 0 &&
381
                    INACTIVE_STATES.indexOf(STATUSES[server.status]) >= 0) {
382
                    // from an active state to an inactive one
383
                    log_server_status_change(existing, server.status);
384
                    existing.find("img.single-image").attr("src","static/icons/machines/large/" + server_image + '-off.png');
385
                    existing.find(".state-label").text(STATUSES[server.status]);
386
                    existing.find(".connect-border").hide();
387
                    existing.find(".connect-arrow").hide();
388
                    existing.find(".spinner").hide();
389
                    existing.find(' .wave').attr('src','static/icons/indicators/medium/wave.gif').show();
390
                    existing.find(".state").removeClass().addClass("state terminated-state");
391
                    setTimeout("$('#" + server.id +" .wave').attr('src','').hide()", 3000);
392
                }
393
                else if (INACTIVE_STATES.indexOf(current_message) >= 0 &&
394
                         ACTIVE_STATES.indexOf(STATUSES[server.status]) >= 0) {
395
                    // From an inactive state to an active one
396
                    log_server_status_change(existing, server.status);
397
                    existing.find("img.single-image").attr("src","static/icons/machines/large/" + server_image + '-on.png');
398
                    existing.find(".state-label").text(STATUSES[server.status]);
399
                    existing.find(".connect-border").show();
400
                    existing.find(".connect-arrow").show();
401
                    existing.find(".spinner").hide();
402
                    existing.find(' .wave').attr('src','static/icons/indicators/medium/wave.gif').show();
403
                    existing.find(".state").removeClass().addClass("state running-state");
404
                    setTimeout("$('#" + server.id +" .wave').attr('src','').hide()", 3000);
405
                }
406
                else {
407
                    // handling active to active or inactive to inactive changes
408
                    if (TRANSITIONS[current_message] && TRANSITIONS[current_message] != 'Rebooting') {
409
                        // don't do anything if it is still in transition
410
                    }
411
                    else if ((TRANSITIONS[current_message] == 'Rebooting' && server.status == 'ACTIVE') ||
412
                             (STATUSES['BUILD'] == current_message && server.status == 'ACTIVE')) {
413
                        // if it has been rebooted or just created
414
                        log_server_status_change(existing, server.status);
415
                        existing.find(".state-label").text(STATUSES[server.status]);
416
                        existing.find(".connect-border").show();
417
                        existing.find(".connect-arrow").show();
418
                        existing.find(".spinner").hide();
419
                        existing.find(' .wave').attr('src','static/icons/indicators/medium/wave.gif').show();
420
                        existing.find(".state").removeClass().addClass("state running-state");
421
                        setTimeout("$('#" + server.id +" .wave').attr('src','').hide()", 3000);
422
                    }
423
                    else {
424
                        // in any other case just change the status and ignore spinners/waves
425
                        existing.find(".state-label").text(STATUSES[server.status]);
426
                    }
427
                }
428
            }
429
            // find and display ips
430
            var ips = get_public_ips(server);
431
            existing.find(".machine-details div.ipv4").text(ips['ip4']);
432
            existing.find(".machine-details div.ipv6").text(ips['ip6']);
433

434
        } else if (server.status != 'DELETED') {
435
            // If it does not exist and it's not deleted, we should create it
436
            var serverwidget = $("#servers-widget-template").clone().attr("id", 'link-' + server.id);
437
            if (server.name.length > 18) {
438
                serverwidget.text(server.name.substring(0,15) + '...');
439
            } else {
440
                serverwidget.text(server.name)
441
            }
442
            serverwidget.appendTo('.servers');
443
            serverwidget.show();
444
            //find and hide the previously selected server
445
            $('.single').find('.single-container').hide();
446
            $('.single .column3').find('.selected').removeClass('selected');
447
            //create and select the new one
448
            var machine = $("#machinesview-single.single #machine-container-template").clone().attr("id", server.id);
449
            machine.find(".machine-details div.name").text(server.name.substring(0,100));
450
            machine.find("img.single-image").attr("src","static/icons/machines/large/"+server_image+'-on.png');
451
            machine.find("span.imagetag").text(server_image);
452
            machine.find(".state-label").text(STATUSES[server.status]);
453
            // find and display ips
454
            var ips = get_public_ips(server);
455
            machine.find(".machine-details div.ipv4").text(ips['ip4']);
456
            machine.find(".machine-details div.ipv6").text(ips['ip6']);
457
            // find and display flavor parameters
458
            var CPUs, RAM, disk, image_name, image_size;
459
            if ( flavors.length > 0 ) {
460
                var current_flavor = '';
461
                for (i=0; i<flavors.length; i++) {
462
                    if (flavors[i]['id'] == server.flavorRef) {
463
                        current_flavor = flavors[i];
464
                    }
465
                }
466
                CPUs = current_flavor['cpu'];
467
                RAM = current_flavor['ram'];
468
                disk = current_flavor['disk'];
469
            } else {
470
                CPUs = 0;
471
                RAM = 0;
472
                disk = 0;
473
            }
474
            if ( images.length > 0 ) {
475
                var current_image = '';
476
                for (i=0; i<images.length; i++) {
477
                    if (images[i]['id'] == server.imageRef) {
478
                        current_image = images[i];
479
                    }
480
                }
481
                image_name = current_image['name'];
482
                image_size = current_image['metadata']['values']['size'];
483
            } else {
484
                image_name = ''
485
                image_size = ''
486
            }
487
            machine.find(".machine-details div.cpus").text(CPUs);
488
            machine.find(".machine-details div.ram").text(RAM);
489
            machine.find(".machine-details div.disk").text(disk);
490
            machine.find(".machine-details div.image-name").text(image_name.substring(0,35));
491
            machine.find(".machine-details div.image-size").text(image_size);
492
            //show off image if server is not active
493
            if (['BUILD', 'ACTIVE', 'REBOOT'].indexOf(server.status) < 0){
494
                    machine.find("img.single-image").attr("src","static/icons/machines/large/"+server_image+'-off.png');
495
                    machine.find(".connect-border").hide();
496
                    machine.find(".connect-arrow").hide();
497
                    machine.find(".state").removeClass().addClass("state terminated-state");
498
            }
499
            //show spinner while machine is building or rebooting
500
            if (server.status == 'BUILD' ||
501
                [TRANSITIONS['Starting'], TRANSITIONS['Shutting down']].indexOf(existing.find(".status").text()) >= 0 ) {
502
                machine.find('.spinner').show();
503
                machine.find(".connect-border").hide();
504
                machine.find(".connect-arrow").hide();
505
                machine.find('.state').removeClass().addClass('state build-state');
506
            }
507
            if (server.status == 'REBOOT') {
508
                machine.find('.spinner').show();
509
                machine.find(".connect-border").hide();
510
                machine.find(".connect-arrow").hide();
511
                machine.find('.state').removeClass().addClass('state rebooting-state');
512
            }
513
            machine.appendTo("#machinesview-single.single");
514
            //disable reboot and shutdown actions while machine is building
515
            if (server.status == 'BUILD') {
516
                $('#machinesview-single.single div.#' + server.id + ' div.action-reboot').hide();
517
                $('#machinesview-single.single div.#' + server.id + ' div.action-shutdown').hide();
518
            }
519
            // show console action only on active servers
520
            if (server.status == 'ACTIVE') {
521
                $('#machinesview-single.single div.#' + server.id + ' div.action-console').show();
522
                $('#machinesview-single.single div.#' + server.id + ' div.action-start').hide();
523
                machine.find(".connect-border").show();
524
                machine.find(".connect-arrow").show();
525
            } else if (server.status == 'REBOOT'){
526
                $('#machinesview-single.single div.#' + server.id + ' div.action-console').hide();
527
            } else {
528
                $('#machinesview-single.single div.#' + server.id + ' div.action-console').hide();
529
                $('#machinesview-single.single div.#' + server.id + ' div.action-reboot').hide();
530
                $('#machinesview-single.single div.#' + server.id + ' div.action-shutdown').hide();
531
            }
532
            //show the first machine and select it in the widget
533
            $('.single-container:eq(1)').show();
534
            $('.single .column3').find('.server-name:eq(1)').addClass('selected');
535
        }
536
    update_iconview_actions(server.id, server.status);
537
    });
538
    $("#machinesview-single.single > div.large-spinner").hide();
539

540
    // show message in case user has no servers!
541
    //if ($('.single-container').length < 2) {
542
    //    showWelcome();
543
    //} else {
544
    //    hideWelcome();
545
    //}
546

547
    // set confirm box position
548
    if (window.innerHeight - 220 < $('#machinesview-single').height())
549
        $('.confirm_multiple').addClass('fixed');
550
    else
551
        $('.confirm_multiple').removeClass('fixed');
552

553
    //enable widget links
554
    $(".server-name").live('click', function() {
555
        $('.single').find('.single-container').hide()
556
        $('.single').find('#' + $(this).attr('id').substring(5)).show();
557
        $('.single .column3').find('.selected').removeClass('selected');
558
        $(this).addClass('selected');
559
        //show prev next links only if there are prev next servers
560
        if ($("#machinesview-single.single .column3 .selected").attr("id") != $("#machinesview-single.single .column3 .server-name:eq(1)").attr("id")) {
561
            $(".single .column3 .previous").show();
562
        } else {
563
            $(".single .column3 .previous").hide();
564
        }
565
        if ($("#machinesview-single.single .column3 .selected").attr("id") != $("#machinesview-single.single .column3 .server-name:last").attr("id")) {
566
            $(".single .column3 .next").show();
567
        } else {
568
            $(".single .column3 .next").hide();
569
        }
570
    });
571

572
    if ($.cookie('server')) {
573
        $('div#link-' + $.cookie('server')).click();
574
        $.cookie('server', null);
575
    }
576

577
    //if it is the last vm, hide the next button
578
    if ($("#machinesview-single.single .column3 .selected").attr("id") == $("#machinesview-single.single .column3 .server-name:last").attr("id")) {
579
        $("#machinesview-single.single .column3 .next").hide()
580
    } else {
581
        $("#machinesview-single.single .column3 .next").show()
582
    }
583

584
    //if it is the first vm, hide the prev button
585
    if ($("#machinesview-single.single .column3 .selected").attr("id") == $("#machinesview-single.single .column3 .server-name:eq(1)").attr("id")) {
586
        $("#machinesview-single.single .column3 .previous").hide()
587
    } else {
588
        $("#machinesview-single.single .column3 .previous").show()
589
    }
590
}
591

592
//get currently displayed serverId
593
function current_serverId() {
594
    return $("#machinesview-single.single").find("div.single-container:visible").attr("id");
595
}
596

597
//enable prev-next buttons
598
$("#machinesview-single.single .column3 .previous").live('click', function() {
599
    // set behavior
600
    if ($("#machinesview-single.single .column3 .selected").attr("id") == $("#machinesview-single.single .column3 .server-name:eq(1)").attr("id")) {
601
        return false;
602
    } else {
603
        current_server = $('#machinesview-single.single .column3').find('.selected').attr("id").substring(5);
604
        $('#machinesview-single.single').find('#' + current_server).hide();
605
        $('#machinesview-single.single').find('#' + current_server).prev().show();
606
        $('#machinesview-single.single .column3').find('#link-' + current_server).removeClass('selected');
607
        $('#machinesview-single.single .column3').find('#link-' + current_server).prev().addClass('selected');
608
        if ($("#machinesview-single.single .column3 .selected").attr("id") == $("#machinesview-single.single .column3 .server-name:eq(1)").attr("id")) {
609
            $(this).hide()
610
        }
611
        $("#machinesview-single.single .column3 .next").show()
612
        return false;
613
    }
614
});
615

616
$("#machinesview-single.single .column3 .next").live('click', function() {
617
    // set behavior
618
    if ($("#machinesview-single.single .column3 .selected").attr("id") == $("#machinesview-single.single .column3 .server-name:last").attr("id")) {
619
        return false;
620
        } else {
621
        current_server = $('#machinesview-single.single .column3').find('.selected').attr("id").substring(5);
622
        $('#machinesview-single.single').find('#' + current_server).hide();
623
        $('#machinesview-single.single').find('#' + current_server).next().show();
624
        $('#machinesview-single.single .column3').find('#link-' + current_server).removeClass('selected');
625
        $('#machinesview-single.single .column3').find('#link-' + current_server).next().addClass('selected');
626
        //if it is the last vm, hide the next button
627
        if ($("#machinesview-single.single .column3 .selected").attr("id") == $("#machinesview-single.single .column3 .server-name:last").attr("id")) {
628
            $(this).hide()
629
        }
630
        $("#machinesview-single.single .column3 .previous").show();
631
        return false;
632
    }
633
});
634

635
//hide prev button on startup
636
$("#machinesview-single.single .column3 .previous").hide()
637

638
// basic functions executed on page load
639
if ( flavors.length == 0 && images.length == 0 ) {
640
    // configure flavors, this also calls update_vms(UPDATE_INTERVAL)
641
    update_flavors();
642
    // populate image list
643
    update_images();
644
} else if ( flavors.length == 0 && images.length != 0 ) {
645
    // configure flavors, this also calls update_vms(UPDATE_INTERVAL)
646
    update_flavors();
647
} else if ( flavors.length != 0 && images.length == 0 ) {
648
    // populate image list
649
    update_images();
650
    update_vms(UPDATE_INTERVAL);
651
} else {
652
    // start updating vm list
653
    update_vms(UPDATE_INTERVAL);
654
}
655

656
//FIXME: Hide and show welcome depending on number of machines
657
hideWelcome();
658
</script>