Statistics
| Branch: | Tag: | Revision:

root / ui / templates / machines_single.html @ 46f24840

History | View | Annotate | Download (30.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
    $('#machinesview-single').find('div.single-action').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
    try {
208
        console.info(serverID);
209
    } catch(err) {}
210
    for (i=0;i<pending_actions.length;i++){ // if there is a pending action for this server execute it
211
        if (pending_actions[i][1]==serverID){
212
            action = pending_actions.splice(i,1)[0]; // extract action
213
            // change the status text in cases where no api state exists
214
            if (action[0] == start) {
215
                $(this).parent().parent().find('.state-label').text(TRANSITIONS['Starting']);
216
                $(this).parent().parent().find('.state').removeClass().addClass('state starting-state');
217
                $(this).parent().parent().find('.spinner').show();
218
            } else if (action[0] == shutdown) {
219
                $(this).parent().parent().find('.state-label').text(TRANSITIONS['Shutting down']);
220
                $(this).parent().parent().find('.state').removeClass().addClass('state shutting-state');
221
                $(this).parent().parent().find('.spinner').show();
222
            } else if (action[0] == reboot) {
223
                $(this).parent().parent().find('.state-label').text(TRANSITIONS['Rebooting']);
224
                $(this).parent().parent().find('.state').removeClass().addClass('state rebooting-state');
225
                $(this).parent().parent().find('.spinner').show();
226
            }  else if (action[0] == destroy) {
227
                $(this).parent().parent().find('.state-label').text(TRANSITIONS['Destroying']);
228
                $(this).parent().parent().find('.state').removeClass().addClass('state destroying-state');
229
                $(this).parent().parent().find('.spinner').show();
230
            }
231
            action[0]([action[1]]); // execute action
232
        }
233
    }
234
    $(this).parent().hide();
235
    $(this).closest('div.action-container').children('div.single-action').removeClass('selected');
236
    $(this).parent().parent().children('.state').children('.spinner').show()
237
    update_confirmations();
238
    return false;
239
});
240

241

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

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

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

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

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

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

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

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

331
    $.each(data.servers.values, function(i,server){
332

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

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

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

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

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

515
    // hide pane spinner
516
    $("#machinesview-single.single > div.large-spinner").hide();
517

518
    // show message in case user has no server!
519
    if ($('#machinesview-single div.single-container').length == 1) {
520
        showWelcome();
521
    } else {
522
        hideWelcome();
523
    }
524

525
    //enable widget links
526
    $(".server-name").live('click', function() {
527
        $('.single').find('.single-container').hide()
528
        $('.single').find('#' + $(this).attr('id').substring(5)).show();
529
        $('.single .column3').find('.selected').removeClass('selected');
530
        $(this).addClass('selected');
531
        //show prev next links only if there are prev next servers
532
        if ($("#machinesview-single.single .column3 .selected").attr("id") != $("#machinesview-single.single .column3 .server-name:eq(1)").attr("id")) {
533
            $(".single .column3 .previous").show();
534
        } else {
535
            $(".single .column3 .previous").hide();
536
        }
537
        if ($("#machinesview-single.single .column3 .selected").attr("id") != $("#machinesview-single.single .column3 .server-name:last").attr("id")) {
538
            $(".single .column3 .next").show();
539
        } else {
540
            $(".single .column3 .next").hide();
541
        }
542
    });
543

544
    if ($.cookie('server')) {
545
        $('div#link-' + $.cookie('server')).click();
546
        $.cookie('server', null);
547
    }
548

549
    //if it is the last vm, hide the next button
550
    if ($("#machinesview-single.single .column3 .selected").attr("id") == $("#machinesview-single.single .column3 .server-name:last").attr("id")) {
551
        $("#machinesview-single.single .column3 .next").hide()
552
    } else {
553
        $("#machinesview-single.single .column3 .next").show()
554
    }
555

556
    //if it is the first vm, hide the prev button
557
    if ($("#machinesview-single.single .column3 .selected").attr("id") == $("#machinesview-single.single .column3 .server-name:eq(1)").attr("id")) {
558
        $("#machinesview-single.single .column3 .previous").hide()
559
    } else {
560
        $("#machinesview-single.single .column3 .previous").show()
561
    }
562
}
563

564
//get currently displayed serverId
565
function current_serverId() {
566
    return $("#machinesview-single.single").find("div.single-container:visible").attr("id");
567
}
568

569
//enable prev-next buttons
570
$("#machinesview-single.single .column3 .previous").live('click', function() {
571
    // set behavior
572
    if ($("#machinesview-single.single .column3 .selected").attr("id") == $("#machinesview-single.single .column3 .server-name:eq(1)").attr("id")) {
573
        return false;
574
    } else {
575
        current_server = $('#machinesview-single.single .column3').find('.selected').attr("id").substring(5);
576
        $('#machinesview-single.single').find('#' + current_server).hide();
577
        $('#machinesview-single.single').find('#' + current_server).prev().show();
578
        $('#machinesview-single.single .column3').find('#link-' + current_server).removeClass('selected');
579
        $('#machinesview-single.single .column3').find('#link-' + current_server).prev().addClass('selected');
580
        if ($("#machinesview-single.single .column3 .selected").attr("id") == $("#machinesview-single.single .column3 .server-name:eq(1)").attr("id")) {
581
            $(this).hide()
582
        }
583
        $("#machinesview-single.single .column3 .next").show()
584
        return false;
585
    }
586
});
587

588
$("#machinesview-single.single .column3 .next").live('click', function() {
589
    // set behavior
590
    if ($("#machinesview-single.single .column3 .selected").attr("id") == $("#machinesview-single.single .column3 .server-name:last").attr("id")) {
591
        return false;
592
        } else {
593
        current_server = $('#machinesview-single.single .column3').find('.selected').attr("id").substring(5);
594
        $('#machinesview-single.single').find('#' + current_server).hide();
595
        $('#machinesview-single.single').find('#' + current_server).next().show();
596
        $('#machinesview-single.single .column3').find('#link-' + current_server).removeClass('selected');
597
        $('#machinesview-single.single .column3').find('#link-' + current_server).next().addClass('selected');
598
        //if it is the last vm, hide the next button
599
        if ($("#machinesview-single.single .column3 .selected").attr("id") == $("#machinesview-single.single .column3 .server-name:last").attr("id")) {
600
            $(this).hide()
601
        }
602
        $("#machinesview-single.single .column3 .previous").show();
603
        return false;
604
    }
605
});
606

607
//hide prev button on startup
608
$("#machinesview-single.single .column3 .previous").hide()
609

610
// basic functions executed on page load
611
if ( flavors.length == 0 && images.length == 0 ) {
612
    // configure flavors, this also calls update_vms(UPDATE_INTERVAL)
613
    update_flavors();
614
    // populate image list
615
    update_images();
616
} else if ( flavors.length == 0 && images.length != 0 ) {
617
    // configure flavors, this also calls update_vms(UPDATE_INTERVAL)
618
    update_flavors();
619
} else if ( flavors.length != 0 && images.length == 0 ) {
620
    // populate image list
621
    update_images();
622
    update_vms(UPDATE_INTERVAL);
623
} else {
624
    // start updating vm list
625
    update_vms(UPDATE_INTERVAL);
626
}
627
</script>