Statistics
| Branch: | Tag: | Revision:

root / ui / templates / networks.html @ e9e7fe51

History | View | Annotate | Download (56.3 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 create button -->
39
<div id="networks-createcontainer">
40
    <div id="beforecreate"></div>
41
    <a id="networkscreate" rel="#networks-wizard" href="#">{% trans "Create New +" %}</a>
42
</div>
43

    
44
<!-- add new network overlay -->
45
<div>
46
    <div class="modal" id="networks-wizard">
47
        <div class="header">
48
        </div>
49
        <h2>{% trans "Name your network" %}</h2>
50
        <hr class="topruler" />
51
        <div class="container">
52
            <div class="name-input">
53
                <label>{% trans "Name" %}:</label>
54
                <input type="text" class="text" name="machine_name"></input>
55
                <span class="help">{% trans "(* Required field)" %}</span>
56
            </div>
57
        </div>
58
        <hr class="bottomruler" />
59
        <button type="button" id="add-network-cancel" class="cancel">{% trans "Cancel" %}</button>
60
        <button type="button" id="add-network-create" class="create">{% trans "Create Network" %}</button>
61
        <hr class="separator-end"></hr>
62
    </div>
63
</div>
64

    
65
<!-- networks list -->
66
<div id="networks-container">
67
    <!-- spinner while loading list -->
68
    <div class = "large-spinner"></div>
69

    
70
    <!-- public network template -->
71
    <div class="network" id="public-template">
72
        <img class="network-logos" src="static/internet.png" />
73
        <div href="#" class="name-div">
74
            <h5 class="namecontainer">
75
                <span class="name">{% trans "Internet" %}</span>
76
            </h5>
77
        </div>
78
        <div class="network-machines">
79
            <div class="machines-header">
80
                <div class="machines-label">{% trans "machines" %}
81
                    (<span class="machines-count">0</span>)
82
                </div>
83
                <div class="toggler down"></div>
84
            </div>
85
        </div>
86
        <div class="network-contents">
87
            <div class="network-placeholder">
88
                <div class="machines-list">
89
                <!-- append machines here -->
90
                </div>
91
                <!-- Adding servers to public network is not supported in 0.5
92
                <div class="empty-network-slot" id="machine-template">
93
                    <div class='network-add-machine'>
94
                        <span class="add-icon">+</span>
95
                    </div>
96
                </div>
97
                -->
98
            </div>
99
        </div>
100
        <div class="state">
101
            <div class="status">{% trans "Public Network" %}</div>
102
            <div class="indicators network-indicator">
103
                <div class="indicator1"></div>
104
                <div class="indicator2"></div>
105
                <div class="indicator3"></div>
106
                <div class="indicator4"></div>
107
            </div>
108
        </div>
109
        <div class="actions">
110
             <!-- Adding servers to public network is not supported in 0.5
111
            <a href="#" class="action-add">{% trans "Add Machine" %}</a>
112
            -->
113
        </div>
114
        <div class="confirm_single">
115
            <button class="yes">{% trans "Confirm" %}</button>
116
            <button class="no">{% trans "Cancel" %}</button>
117
        </div>
118
        <div class="action_error" align="center">
119
            {% trans "<span>Error</span> on" %} <span class="action">{% trans "error action" %}</span>
120
            <span class="code"></span>
121
            <span class="message"></span>
122
            <button class="details">{% trans "Details" %}</button>
123
        </div>
124
    </div>
125

    
126
    <!-- template for machines in public network -->
127
    <div class="network-machine" id="public-machine-template">
128
        <div class="network-cable"></div>
129
        <div class="machine-actions">
130
            <a href="#" class="action-details">{% trans "Details" %}</a>
131
        </div>
132
        <div class="confirm_single">
133
            <button class="yes">{% trans "Confirm" %}</button>
134
            <button class="no">{% trans "Cancel" %}</button>
135
        </div>
136
        <div class="action_error" align="center">
137
            {% trans "<span>Error</span> on" %} <span class="action">{% trans "error action" %}</span>
138
            <span class="code"></span>
139
            <span class="message"></span>
140
            <button class="details">{% trans "Details" %}</button>
141
        </div>
142
        <div class="ips">
143
            <div class="ip4-container status">
144
                {% trans "IPv4" %}:
145
                <span class="ip4 ipv4-text">192.94.73.15</span>
146
            </div>
147
            <div class="ip6-container status">
148
                {% trans "IPv6" %}:
149
                <span class="ip6 ipv6-text"></span>
150
            </div>
151
        </div>
152
        <img class="logo" src="static/icons/machines/medium/debian-on.png" />
153
        <div class='network-remove-machine'>
154
            <!-- Removing servers from public network is not supported in 0.5
155
            <span class="remove-icon">X</span>
156
            -->
157
            <span>&nbsp;</span>
158
        </div>
159
        <div href="#" class="machine-name-div">
160
            <h5 class="namecontainer">
161
                <span class="name">my desktop1</span>
162
            </h5>
163
        </div>
164
        <div class="firewall">
165
            <div class="firewall-header">
166
                <div class="firewall-label">{% trans "Firewall" %}
167
                    (<span class="firewall-off">{% trans "Off" %}</span>)
168
                </div>
169
                <div class="toggler down"></div>
170

    
171
                <div class="network-progress-indicator">
172
                    <img src="/static/icons/indicators/small/progress.gif" alt="{% trans "updating  settings" %}" title="{% trans "updating  settings" %}" />
173
                </div>
174
            </div>
175
        </div>
176
        <div class="firewall-content">
177
            <div class="firewall-cable"></div>
178
            <input type="radio" class="checkboxes" value="DISABLED" name="firewall" />
179
            <span class="checkbox-legends">{% trans "Unprotected mode (Firewall off)" %}</span>
180
            <br />
181
            <input type="radio" class="checkboxes" value="ENABLED" name="firewall" />
182
            <span class="checkbox-legends">{% trans "Fully protected mode (Firewall on)" %}</span>
183
            <br />
184
            <input type="radio" class="checkboxes" value="PROTECTED" name="firewall" />
185
            <span class="checkbox-legends">{% trans "Basically protected mode (Firewall on)" %}</span>
186
            <button type="submit" class="firewall-apply">{% trans "Apply" %}</button>
187
        </div>
188
        <div class="network-separator machines"></div>
189
    </div>
190

    
191
    <div class="separator" style="display:none;"></div>
192

    
193
    <!-- private network template -->
194
    <div class="network" id="private-template">
195
        <div class="actions">
196
            <a href="#" class="action-add">{% trans "Add Machine" %}</a>
197
            <a href="#" class="action-network-destroy">{% trans "Destroy" %}</a>
198
        </div>
199
        <div class="action_error" align="center">
200
            {% trans "<span>Error</span> on" %} <span class="action">{% trans "error action" %}</span>
201
            <span class="code"></span>
202
            <span class="message"></span>
203
            <button class="details">{% trans "Details" %}</button>
204
        </div>
205
        <div class="confirm_single">
206
            <button class="yes">{% trans "Confirm" %}</button>
207
            <button class="no">X</button>
208
        </div>
209
        <div class="action_error" align="center">
210
            {% trans "<span>Error</span> on" %} <span class="action">{% trans "error action" %}</span>
211
            <span class="code"></span>
212
            <span class="message"></span>
213
            <button class="details">{% trans "Details" %}</button>
214
        </div>
215
        <div class="state">
216
            <div class="status">{% trans "Private Network" %}</div>
217
            <div class="indicators network-indicator">
218
                <div class="indicator1"></div>
219
                <div class="indicator2"></div>
220
                <div class="indicator3"></div>
221
                <div class="indicator4"></div>
222
            </div>
223
            <img class="spinner" style="display:none" src="static/icons/indicators/medium/progress.gif" />
224
            <img class="wave" style="display:none" src="static/icons/indicators/medium/wave.gif" />
225
        </div>
226
        <img class="network-logos" src="static/network.png" />
227
        <div href="#" class="name-div">
228
            <h5 class="namecontainer editable">
229
                <span class="name">{% trans "My Network 1" %}</span>
230
                <span class="rename-network"></span>
231
                <div class="editbuttons" style="display:none">
232
                    <span class="save"></span>
233
                    <span class="cancel"></span>
234
                </div>
235
            </h5>
236
        </div>
237
        <div class="network-machines">
238
            <div class="machines-header">
239
                <div class="machines-label">{% trans "machines" %}
240
                    (<span class="machines-count">0</span>)
241
                </div>
242
                <div class="toggler down"></div>
243
            </div>
244
        </div>
245
        <div class="network-contents">
246
            <div class="network-placeholder">
247
                <div class="machines-list">
248
                <!-- append machines here -->
249
                </div>
250
                <div class="empty-network-slot" id="machine-template">
251
                    <div class='network-add-machine'><div class="add-icon">+</div></div>
252
                </div>
253
            </div>
254
        </div>
255
    </div>
256

    
257
    <!-- template for machines in private network -->
258
    <div class="network-machine" id="private-machine-template">
259
        <div class="machine-actions">
260
            <a href="#" class="action-disconnect">{% trans "Disconnect" %}</a>
261
            <a href="#" class="action-details">{% trans "Details" %}</a>
262
        </div>
263
        <div class="confirm_single">
264
            <button class="yes">{% trans "Confirm" %}</button>
265
            <button class="no">X</button>
266
        </div>
267
        <div class="action_error" align="center">
268
            {% trans "<span>Error</span> on" %} <span class="action">{% trans "error action" %}</span>
269
            <span class="code"></span>
270
            <span class="message"></span>
271
            <button class="details">{% trans "Details" %}</button>
272
        </div>
273
        <img class="logo" src="static/icons/machines/medium/debian-on.png" />
274
        <div class='network-remove-machine'><span class="remove-icon">X</span></div>
275
        <div href="#" class="machine-name-div">
276
            <h5 class="namecontainer editable">
277
                <span class="name">my desktop1</span>
278
            </h5>
279
        </div>
280
        <h5 class='machine-connect'>
281
            <span>{% trans "Connect" %}</span> {% trans "to manage private IPs" %}
282
        </h5>
283
        <div class="network-separator machines"></div>
284
    </div>
285

    
286
    <!-- the actual structure to be populated -->
287
    <div class="public-networks"></div>
288
    <div class="private-networks" style="display:none;"></div>
289
</div>
290

    
291
<!-- add servers to network overlay -->
292
<div>
293
    <div id="add-machines-wizard" class="modal">
294
        <h3 class="popup-header">{% trans "Add machine" %}</h3>
295
        <p style='display:none;'>hidden network id</p>
296
        <div class="popup-body">
297
            <div class="popup-body-inner">
298
                <div class="popup-title">{% trans "Select machines to add to:" %}</div>
299
                <div class="network-name"></div>
300
                <div class="popup-separator"></div>
301
                <div class="machines-container">
302
                    <div class="large-spinner"></div>
303
                    <div id='machine-entry-template' style="display:none;">
304
                        <input type="checkbox" />
305
                        <img class=list-logo src="static/icons/machines/small/debian-on.png" title="debian"></img>
306
                        <span class="machine-name">kati</span>
307
                    </div>
308
                </div>
309
            </div>
310
        </div>
311
        <div class="buttons">
312
            <button type="button" class="cancel" id="add-server-cancel">{% trans "Cancel" %}</button>
313
            <button type="button" class="add" id="add-server-add">{% trans "Add" %}</button>
314
        </div>
315
    </div>
316
</div>
317

    
318
<a id="add-machines-overlay" href="#" rel="#add-machines-wizard"></a>
319

    
320
<!-- reboot dialog -->
321
<div class="reboot-dialog">
322
    <p>{% trans "For the network changes to take effect you need to reboot all affected machines:" %}</p>
323
    <button class="reboot-all">{% trans "Reboot All" %}</button>
324
    <div id="reboot-machine-template" class='reboot-machine-entry'>
325
        <div class="name">my debian server</div>
326
        <button class="reboot-single">{% trans "Reboot" %}</button>
327
        <div class="reboot-error">
328
            <div class="code"></div>
329
            <div class="action"></div>
330
            <div class="message"></div>
331
            <button class="details">{% trans "Error!" %}</button>
332
        </div>
333
    </div>
334
    <div class="reboot-list"></div>
335
</div>
336

    
337
<!-- multiple confirmation dialog -->
338
<div class="confirm_multiple">
339
    <p>{% trans "Your actions will affect" %} <span class="actionLen">XX</span> {% trans "networks or machines" %}</p>
340
    <button class="yes">{% trans "Confirm All" %}</button>
341
    <button class="no">{% trans "Cancel All" %}</button>
342
</div>
343

    
344
<script>
345
// add network wizard initialization
346
$(function() {
347
    // create wizard overlay
348
    $("a#networkscreate").overlay({
349
        mask: '#666',
350
        effect: 'default',
351
        top: '10%',
352
        closeOnClick: false,
353
        oneInstance: false,
354
        closeOnEsc: true,
355
        load: false
356
    });
357
});
358

359
// intercept click to create new private network
360
$("#networkscreate").click(function() {
361
    // reset and load wizard
362
    $('#networks-wizard span.help').removeClass('red');
363
    $('#networks-wizard input').val('');
364
    $('#networks-wizard #add-network-create').text('{% trans 'Create Network' %}');
365
    $("#networks-wizard").show();
366
    $('#networks-wizard input').focus();
367
    $("a#networkscreate").data('overlay').load();
368
    // enable submit button
369
    $("#networks-wizard #add-network-create").removeAttr('disabled');
370
    return false;
371
});
372

373
// exit the add machine to network wizard
374
$("#add-network-cancel").live('click', function() {
375
    $("a#networkscreate").overlay().close();
376
});
377

378
// add selected machines to network
379
$("#add-network-create").live('click', function() {
380
    if ($('#networks-wizard input').val() == '') {
381
        $('#networks-wizard input').focus();
382
        $('#networks-wizard span.help').addClass('red');
383
    } else {
384
        // disable submit button to prevent multiple calls
385
        $(this).attr("disabled", true);
386
        // load progress bar
387
        $(this).text('');
388
        $(this).html('<img src="static/icons/indicators/medium/horizontal-progress.gif"></img>');
389
        // make the call
390
        networkName = $('#networks-wizard input').val();
391
        create_network(networkName);
392
    }
393
    return false;
394
});
395

396
// toggle component with class network-contents
397
$("#networks-pane div.machines-header").live('click', function() {
398
    if ($(this).find('.toggler').hasClass('up')) {
399
        $(this).find('.toggler').removeClass('up');
400
        $(this).find('.toggler').addClass('down');
401
        $(this).find('.machines-label').removeClass('darker');
402
        $(this).closest('div.network').removeClass('light-background');
403
    } else {
404
        $(this).find('.toggler').removeClass('down');
405
        $(this).find('.toggler').addClass('up');
406
        $(this).find('.machines-label').addClass('darker');
407
        $(this).closest('div.network').addClass('light-background');
408
    }
409
    $(this).parent().next("#networks-pane .network-contents").slideToggle(600, update_net_ui);
410
    return false;
411
});
412

413
// toggle component with class network-contents
414
$("#networks-pane .network-logos").live('click', function() {
415
    $(this).closest('div.network').find('div.machines-header').click();
416
    return false;
417
});
418

419
//initiate network renaming
420
$("#networks-pane .name-div .rename-network, #networks-pane .name-div h5.editable span.name").live('click', function() {
421
    $(this).parent().find('.name').html("<input id=\"txtEdit\" type=\"text\" class=\"nametextbox\" value=\"" +
422
                                        $(this).parent().find('.name').text() +
423
                                        "\" / ><span class=\"oldValue\">" +
424
                                        $(this).parent().find('.name').text() + "</span>");
425
    $(this).parent().find('.rename-network').hide();
426
    $(this).parent().find(".editbuttons").fadeIn();
427
    $(this).parent().find(".nametextbox").focus().select();
428
    $(this).parent().removeClass('editable');
429

430
    //submit wizard by pressing enter on the name textbox
431
    $("#txtEdit").keydown(function (e) {
432
        if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13)) {
433
            $(this).parent().parent().find('div.editbuttons span.save').click();
434
            return false;
435
        } else if ((e.which && e.which == 27) || (e.keyCode && e.keyCode == 27)) {
436
            $(this).parent().parent().find('div.editbuttons span.cancel').click();
437
            return true;
438
        }
439
    });
440
    return false;
441
});
442

443
//rename machine
444
$("#networks-pane .name-div .editbuttons .save").live('click', function() {
445
    networkID = $(this).closest('.network').attr("id").split('-').pop();
446
    networkName = $(this).parent().parent().find('.nametextbox').val();
447
    if (networkName.trim() == ''){
448
        return false;
449
    }
450
    $(this).parent().parent().find('.name').html($(this).parent().parent().find('.nametextbox').val());
451
    $(this).parent().parent().find(".editbuttons").fadeOut("fast");
452
    $(this).parent().parent().find(".rename-network").fadeIn("slow");
453
    rename_network(networkID, networkName);
454
    return false;
455
});
456

457
//cancel renaming
458
$("#networks-pane .name-div .editbuttons .cancel").live('click', function() {
459
    $(this).parent().parent().find('.name').html($(this).parent().parent().find('.oldValue').text());
460
    $(this).parent().parent().find(".editbuttons").hide();
461
    $(this).parent().parent().find(".rename-network").fadeIn();
462
    $(this).parent().parent().addClass('editable');
463
    return false;
464
});
465

466
// intercept click to delete network
467
$("#networks-pane .action-network-destroy").live('click', function() {
468
    var networkID = $(this).parent().parent().attr('id').split('-').pop();
469
    var networkName = $(this).parent().parent().find(".name-div span.name").text();
470
    var found = false;
471
    $(this).parent().children('a').removeClass('selected');
472
    $(this).addClass('selected');
473
    $(this).parent().addClass('display')
474
    $(this).parent().parent().find('.action_error').hide();
475
    for (i=0; i < pending_actions.length; i++){ // if there is already a pending action for this network replace it
476
        if (pending_actions[i][0] == delete_network && pending_actions[i][1] == networkID){
477
            pending_actions[i][0] = delete_network;
478
            found = true
479
        }
480
    }
481
    if (!found) {
482
        // no pending action for this network was found, so let's just add it to the list
483
        pending_actions.push([delete_network, networkID, networkName]);
484
    }
485
    update_network_confirmations();
486
    return false;
487
});
488

489
// intercept click to remove machine from network
490
$("#networks-pane .remove-icon").live('click', function() {
491
    $(this).closest('.network-machine').find('.action-disconnect').click();
492
    return false;
493
});
494

495
// intercept click to remove machine from network
496
$("#networks-pane .action-disconnect").live('click', function() {
497
    var serverID = $(this).parent().parent().attr('id').split('-').pop();
498
    var serverName = $(this).closest('.network-machine').find('span.name').text();
499
    var networkID = $(this).closest('.network').attr('id').split('-').pop();
500
    var serverState = $(this).closest('.network-machine').find('img.logo').attr('src').split('-')[1];
501
    serverState = serverState.split('.')[0];
502
    var found = false;
503
    $(this).parent().children('a').removeClass('selected');
504
    $(this).addClass('selected');
505
    $(this).parent().addClass('display')
506
    $(this).parent().parent().find('.action_error').hide();
507
    for (i=0; i < pending_actions.length; i++){
508
        // if there is already a pending action for this network replace it
509
        if (pending_actions[i][0] == remove_server_from_network &&
510
            pending_actions[i][1] == networkID &&
511
            pending_actions[i][2] == serverID) {
512
                pending_actions[i][0] = remove_server_from_network;
513
                found = true
514
        }
515
    }
516
    if (!found) {
517
        // no pending action for this network was found, so let's just add it to the list
518
        pending_actions.push([remove_server_from_network, networkID, serverID, serverName, serverState]);
519
    }
520
    update_network_confirmations();
521
    return false;
522
});
523

524
$("#networks-pane .action-details").live('click', function() {
525
    var serverID = $(this).parent().parent().attr('id').split('-').pop();
526
    $.cookie('view', '2');
527
    $.cookie('server', serverID);
528
    $('a#machines').click();
529
    return false;
530
});
531

532
// add machines wizard initialization
533
$(function() {
534
    // create wizard overlay
535
    $("a#add-machines-overlay").overlay({
536
        mask: '#666',
537
        effect: 'default',
538
        top: '10%',
539
        closeOnClick: false,
540
        oneInstance: false,
541
        closeOnEsc: true,
542
        load: false
543
    });
544
});
545

546
// intercept click to add machine to  network
547
$("#networks-pane .action-add").live('click', function() {
548
    // reset pre-existing values
549
    $('#add-server-add').text('{% trans 'Add' %}');
550
    $("#add-machines-wizard .network-name").text($(this).closest('.network').find('.name-div span.name').text());
551
    $("#add-machines-wizard p").text($(this).closest('.network').attr('id').split('-').pop());
552
    $("#add-machines-wizard .large-spinner").show();
553
    $('[id^="list-entry-server-"]').remove();
554
    // list new values
555
    list_machines();
556
    // load wizard
557
    $("#add-machines-wizard").show();
558
    $("a#add-machines-overlay").data('overlay').load();
559
    // enable submit button
560
    $("#add-machines-wizard #add-server-add").removeAttr('disabled');
561
    return false;
562
});
563

564
//submit wizard by pressing enter on the name textbox
565
$("#networks-wizard div.name-input input.text").keypress(function (e) {
566
    if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13)) {
567
        $('#add-network-create').click();
568
        return false;
569
    } else {
570
        return true;
571
    }
572
});
573

574
// intercept click to bring up the add machine to network wizard
575
$("#networks-pane .add-icon").live('click', function() {
576
    $(this).closest('.network').find('.action-add').click();
577
});
578

579
// get machines in public network and list them in add server to network wizard
580
function list_machines() {
581
    var networkID = $("#add-machines-wizard p").text();
582
    // get the list of servers from the UI
583
    var all_machines = $("#networks-pane .public-networks .network-machine");
584

585
    $.each(all_machines, function(i, machine) {
586
        var currentID = machine.id.split('-').pop();
587
        // if machine already exists in private network
588
        if ( $('#net-' + networkID + '-server-' + currentID).length > 0 ) {
589
            // do nothing
590
        } else {
591
            // put it in the list
592
            var entry = $("#add-machines-wizard #machine-entry-template").clone().attr("id", "list-entry-server-" + currentID);
593
            entry.find('input').attr("name", currentID);
594
            entry.find('img').attr('src', 'static/icons/machines/small/' + $(machine).find('img.logo').attr('src').split('/').pop());
595
            entry.find('.machine-name').text($(machine).find('span.name').text());
596
            entry.appendTo("#add-machines-wizard .machines-container");
597
        }
598
    });
599
    $("#add-machines-wizard .large-spinner").hide();
600
    $('[id^="list-entry-server-"]').fadeIn("slow");
601
    return false;
602
}
603

604
// exit the add machine to network wizard
605
$("#add-server-cancel").live('click', function() {
606
    $("a#add-machines-overlay").overlay().close();
607
});
608

609
// add selected machines to network
610
$("#add-server-add").live('click', function() {
611
    var selections = $("#add-machines-wizard :checkbox:checked");
612
    // if there are no selections simply close the wizard
613
    if (selections.length == 0 ) {
614
        $("a#add-machines-overlay").overlay().close();
615
    }
616
    // if there are servers selected make the proper call
617
    else {
618
        var networkID = $("#add-machines-wizard p").text();
619
        var serverIDs = [];
620
        var serverNames = [];
621
        var serverState = [];
622
        var serverStates = [];
623
        $.each(selections, function(i, selection) {
624
            serverIDs.push(selection.name);
625
            serverNames.push($("#list-entry-server-" + selection.name + " span.machine-name").text());
626
            serverState = $("#list-entry-server-" + selection.name + " img.list-logo").attr('src').split('-')[1];
627
            serverState = serverState.split('.')[0];
628
            serverStates.push(serverState);
629
        });
630
        // disable submit button to prevent multiple calls
631
        $(this).attr("disabled", true);
632
        // load progress bar
633
        $(this).text('');
634
        $(this).html('<img src="static/icons/indicators/medium/horizontal-progress.gif"></img>');
635
        // show the proper spinner
636
        $('#net-' + networkID + '.network div.status').text(NET_STATES['Connecting']);
637
        $('#net-' + networkID + '.network img.spinner').show();
638
        // make the calls
639
        add_server_to_network(networkID, serverIDs, serverNames, serverStates);
640
    }
641
    return false;
642
});
643

644
// toggle component with class firewall-contents
645
$("#networks-pane div.firewall-header").live('click', function() {
646
    if ($(this).find('.toggler').hasClass('up')) {
647
        $(this).find('.toggler').removeClass('up');
648
        $(this).find('.toggler').addClass('down');
649
        $(this).find('.firewall-label').removeClass('darker');
650
    } else {
651
        $(this).find('.toggler').removeClass('down');
652
        $(this).find('.toggler').addClass('up');
653
        $(this).find('.firewall-label').addClass('darker');
654
    }
655
    $(this).parent().next(".firewall-content").slideToggle(600, update_net_ui);
656
    return false;
657
});
658

659
//hide firewall content on apply click
660
$("#networks-pane .firewall-apply").live('click', function() {
661
    var serverID = $(this).closest('.network-machine').attr("id").split('-').pop();
662
    var networkID = $(this).closest('.network-machine').attr("id").split('-')[1];
663
    var profile = $(this).parent().find('input:checked').attr('value');
664

665
    // Do not make api call if profile choice is the 
666
    // same as current vm firewall profile
667
    try {
668
        if (profile == get_machine(serverID).addresses.values[0].firewallProfile) {
669
            return;
670
        }
671
    } catch (err) {
672
        console.info(err);
673
    }
674
    
675
    if (profile != undefined) {
676
        set_firewall(networkID, serverID, profile);
677
        $(this).attr("disabled", true);
678
        $(this).html('<img src="static/icons/indicators/medium/horizontal-progress.gif"></img>');
679
        show_machine_network_indicator(serverID, "pub");
680
    }
681
    return false;
682
});
683

684
function display_reboot_dialog(networkID, serverID, serverName, serverState) {
685
    // check if the server already exists in the list
686
    var existing_reboot = $("div.reboot-list div#server-" + serverID);
687
    if ( !existing_reboot.length && serverState != 'off') {
688
        $('div.reboot-dialog').fadeIn("slow");
689
        var reboot_entry = $('div#reboot-machine-template').clone().attr("id", "server-" + serverID);
690
        reboot_entry.find('div.name').text(serverName);
691
        reboot_entry.appendTo('div.reboot-list').show();
692
    }
693
    return false;
694
}
695

696
// intercept single reboot click
697
$("div.reboot-dialog button.reboot-single").live('click', function() {
698
    var serverID = $(this).parent().attr('id').split('-')[1];
699
    reboot([serverID]);
700
    // load progress bar
701
    $(this).text('');
702
    $(this).html('<img src="static/icons/indicators/medium/horizontal-progress.gif"></img>');
703
    // disable submit button to prevent multiple calls
704
    $(this).attr("disabled", true);
705
    return false;
706
});
707

708
// intercept multiple reboot click
709
$("div.reboot-dialog button.reboot-all").live('click', function() {
710
    $(this).parent().find('div.reboot-list button.reboot-single').click();
711
    // load progress bar for all buttons
712
    $(this).parent().find('button').text('');
713
    $(this).parent().find('button').html('<img src="static/icons/indicators/medium/horizontal-progress.gif"></img>');
714
    // disable submit button to prevent multiple calls
715
    $(this).attr("disabled", true);
716
    return false;
717
});
718

719
// intercept error on reboot click
720
$("div.reboot-dialog button.details").live('click', function() {
721
    $(this).closest('.reboot-machine-entry').remove();
722
    ajax_error( $(this).parent().children('.code').text(),
723
                undefined,
724
                $(this).parent().children('.action').text(),
725
                $(this).parent().children('.message').text());
726
    if ( !$('div.reboot-list').children().length ) {
727
        $('div.reboot-dialog').hide();
728
    }
729
    return false;
730
});
731

732
// after reboot success
733
function display_reboot_success(serverID) {
734
    // remove server from the list
735
    $('div.reboot-list #server-' + serverID).remove();
736
    // if there are no other servers on the list, hide the reboot dialog
737
    if ( !$('div.reboot-list').children().length ) {
738
        $('div.reboot-dialog').hide();
739
        // reset all buttons
740
        $("div.reboot-dialog button.reboot-all").html('');
741
        $("div.reboot-dialog button.reboot-all").text('{% trans 'Reboot All' %}');
742
        $("div.reboot-dialog button.reboot-single").html('');
743
        $("div.reboot-dialog button.reboot-single").text('{% trans 'Reboot' %}');
744
        // enable submit button
745
        $("#div.reboot-dialog button.reboot-all").removeAttr('disabled');
746
    }
747
    return false;
748
}
749

750
// after reboot error
751
function display_reboot_failure(status, serverID, responseText) {
752
    $('div.reboot-list #server-' + serverID + ' button.reboot-single').hide();
753
    $('div.reboot-list #server-' + serverID + ' div.code').text(status);
754
    $('div.reboot-list #server-' + serverID + ' div.action').text('Reboot');
755
    $('div.reboot-list #server-' + serverID + ' div.message').text(responseText);
756
    $('div.reboot-list #server-' + serverID + ' button.details').show();
757
    return false;
758
}
759

760
// confirm single action
761
$("#networks-pane div.confirm_single .yes").live('click', function() {
762
    // this works both for server and network actions
763
    var serverID = [];
764
    if ($(this).closest('.network-machine').attr('id')) {
765
        serverID = $(this).closest('.network-machine').attr('id').split('-').pop();
766
    }
767
    var networkID = $(this).closest('.network').attr("id").split('-').pop();
768
    // execute actions
769
    for (i=0;i<pending_actions.length;i++){
770
        // if there is a pending action for this server execute it
771
        if (pending_actions[i][0] == delete_network &&
772
            pending_actions[i][1] == networkID) {
773
                action = pending_actions.splice(i,1)[0];
774
                $(this).closest('div.network').find('div.status').text(NET_STATES['Destroying']);
775
                $(this).closest("div.network").find('div.state').addClass('destroying-state');
776
                $(this).closest('div.network').find('img.spinner').show();
777
                action[0]([action[1]]); // execute action
778
        } else if ( pending_actions[i][0] == remove_server_from_network &&
779
                    pending_actions[i][1] == networkID ) {
780
                        $(this).closest('div.network').find('div.status').text(NET_STATES['Disconnecting']);
781
                        $(this).closest('div.network').find('img.spinner').show();
782
                        action = pending_actions.splice(i,1)[0];
783
                        action[0]([action[1]], [action[2]], [action[3]], [action[4]]); // execute action
784
        } // for adding servers to a network look in $("#add-server-add").live('click', function() {...});
785
    }
786
    $(this).parent().hide();
787
    $(this).parent().parent().find('a.selected').removeClass('selected');
788
    $(this).parent().parent().children('div.actions').removeClass('display');
789
    update_network_confirmations();
790
    return false;
791
});
792

793
// cancel single action
794
$("#networks-pane div.confirm_single .no").live('click', function(){
795
    // this works both for server and network actions
796
    var serverID = [];
797
    if ($(this).closest('.network-machine').attr('id')) {
798
        serverID = $(this).closest('.network-machine').attr('id').split('-').pop();
799
    }
800
    var networkID = $(this).closest('.network').attr("id").split('-').pop();
801
    // remove the action from the pending list
802
    $(this).parent().parent().children('div.machine-actions').children('a').removeClass('selected');
803
    $(this).parent().parent().children('div.machine-actions').removeClass('display');
804

805
    for (i=0; i < pending_actions.length; i++) { // if there is a pending action for this network remove it
806
        if (pending_actions[i][0] == delete_network && pending_actions[i][1] == networkID) {
807
                pending_actions.splice(i,1);
808
        } else if ( pending_actions[i][0] == remove_server_from_network &&
809
                    pending_actions[i][1] == networkID &&
810
                    pending_actions[i][2] == serverID) {
811
                        pending_actions.splice(i,1);
812
        }
813
    }
814
    $(this).parent().hide();
815
    $(this).parent().parent().find('a.selected').removeClass('selected');
816
    $(this).parent().parent().children('div.actions').removeClass('display');
817
    update_network_confirmations();
818
    return false;
819
});
820

821
// after single action call error
822
function display_net_failure(status, networkID, action, responseText) {
823
    return false;
824
}
825

826
// show, single action, error details
827
$("#networks-pane div.action_error .details").live('click', function(){
828
    $(this).parent().hide();
829
    ajax_error($(this).parent().children('.code').text(),
830
                 undefined,
831
                 $(this).parent().children('.action').text(),
832
                 $(this).parent().children('.message').text());
833
    return false;
834
});
835

836
// confirm all actions
837
$("#networks-pane div.confirm_multiple .yes").live('click', function(){
838
    while(pending_actions.length > 0){ // if there is a pending action for this network execute it
839
        action = pending_actions.pop(); // extract action
840
        var networkID = action[1];
841
        $('#networks-pane .selected').removeClass('selected');
842
        $('#networks-pane .display').removeClass('display');
843
        $('#networks-pane .confirm_single').hide();
844
        if (action[0] == delete_network) {
845
            $('#networks-pane #net-' + networkID + ' .status').text(NET_STATES['Destroying']);
846
            $('#networks-pane #net-' + networkID + ' .state').addClass('destroying-state');
847
            $('#networks-pane #net-' + networkID + ' .spinner').show();
848
            action[0]([networkID]); // execute action
849
        } else if (action[0] == remove_server_from_network) {
850
            $('div.network#net-'+networkID).find('div.status').text(NET_STATES['Disconnecting']);
851
            $('div.network#net-'+networkID).find('img.spinner').show();
852
            action[0]([action[1]], [action[2]], [action[3]], [action[4]]); // execute action
853
        }
854
    }
855
    update_network_confirmations();
856
    return false;
857
});
858

859
// cancel all actions
860
$("#networks-pane div.confirm_multiple .no").live('click', function(){
861
    pending_actions = [];
862
    $('#networks-pane .selected').removeClass('selected');
863
    $('#networks-pane .display').removeClass('display');
864
    $('#networks-pane .confirm_single').hide();
865
    update_network_confirmations();
866
    return false;
867
});
868

869
// update the networks list
870
function update_networks_view(servers_data, networks_data){
871
    /*
872
    Go through the input data. Update existing entries, add
873
    new ones to the list
874
    */
875

876
    // check for changes in networks
877
    if (networks_data){
878
        /*
879
        Here we are interested in private networks only
880
        and for servers disconnected from them
881
        */
882

883
        // if we wait for a new network to be created
884
        if ($('#add-network-create').children().length > 0) {
885
            var response_objects = networks_data.networks.values;
886
            // check all objects in the response
887
            for (i=0; i < response_objects.length; i++) {
888
                // if it contains the network we want to create
889
                var networkName = $('#networks-wizard input').val();
890
                if ( response_objects[i]['name'] == networkName) {
891
                    // close the wizard
892
                    $("a#networkscreate").overlay().close();
893
                    // and the network will be inserted in the DOM
894
                    // during this update loop
895
                }
896
            }
897
        }
898

899
        // update private networks
900
        $.each(networks_data.networks.values, function(i,network) {
901
            // search DOM for this network
902
            existing = $('#networks-pane #net-' + network.id);
903

904
            // If in the DOM exist multiple networks with the same id,
905
            // delete all but one.
906
            // Defensive coding - that shouldn't happen normally
907
            while (existing.length > 1) {
908
                existing.remove();
909
            }
910

911
            // If network already exists in DOM, update it
912
            if (existing.length) {
913
                // network was deleted
914
                if (network.status == 'DELETED') {
915
                    existing.next().remove(); // to delete its separator
916
                    existing.remove();
917
                }
918
                // network was renamed
919
                if (existing.find('.name-div span.name').text() != network.name) {
920
                    // set the new name
921
                    existing.find('.name-div span.name').text(network.name);
922
                }
923
                // a server was disconnected
924
                // search DOM for all machines
925
                existing_machines = $('div.private-networks div.network-machine');
926
                // check if the machines in the DOM exist in the response
927
                for (i=0; i<existing_machines.length; i++) {
928
                    // get the existing server id
929
                    var serverID = existing_machines[i].id.split('-')[3];
930
                    // if a server exists in DOM, but not in the response it has
931
                    // been disconnected
932
                    if ( network.servers.values.indexOf( parseInt(serverID) ) == -1 ) {
933
                        // remove it from DOM and reset all spinners
934
                        $('#' + existing_machines[i].id).remove();
935
                        $('#net-' + network.id + '.network div.status').text(NET_STATES['ACTIVE']);
936
                        $('#net-' + network.id + '.network img.spinner').hide();
937
                    }
938
                }
939
            }
940
            // If network does not exist in DOM, create it, do not take into account public network
941
            else if (network.id != 'public'){
942
                var privNet = $("#networks-pane #private-template").clone().attr("id", "net-" + network.id);
943
                privNet.find(".name-div span.name").text(network.name).fadeIn("slow");
944
                privNet.appendTo("#networks-pane .private-networks");
945
                $('div.separator:last').clone().appendTo("#networks-pane .private-networks");
946
            }
947
        });
948
    }
949

950
    // check for changes in servers
951
    if (servers_data) {
952
        /*
953
        Here we are interested in any server contained
954
        either in a public network or a private one
955
        */
956
        $.each(servers_data.servers.values, function(i,server) {
957
            /*
958
            First update the public network
959
            */
960

961
            // search public network's DOM for this server
962
            existing_public = $('#networks-pane #net-pub-server-' + server.id);
963

964
            // get the server's OS icon
965
            var server_image = os_icon(server.metadata);
966
            if (!(server.metadata == undefined)) {
967
                var server_image = os_icon(server.metadata);
968
            } else {
969
                var server_image = "unknown"
970
            }
971

972
            // server was deleted
973
            if (server.status == 'DELETED') {
974
                existing_public.remove();
975
            }
976

977
            // If server already exists in public network, update it
978
            if (existing_public.length){
979
                // server was renamed
980
                if (server.name != existing_public.find('span.name').text()) {
981
                    existing_public.find('span.name').text(fix_server_name(server.name,25));
982
                }
983
                // server has changed state
984
                if (server.status=='BUILD' || server.status=='ACTIVE' ||server.status=='REBOOT') {
985
                    existing_public.find("img.logo").attr("src","static/icons/machines/medium/" + server_image + '-on.png');
986
                } else {
987
                    existing_public.find("img.logo").attr("src","static/icons/machines/medium/" + server_image + '-off.png');
988
                }
989
                // server has new ips
990
                var old_ip4 = existing_public.find('span.ip4').text();
991
                var old_ip6 = existing_public.find('span.ip6').text();
992
                var new_ips = get_public_ips(server);
993
                var new_ip4 = new_ips['ip4'];
994
                var new_ip6 = new_ips['ip6'];
995
                if (old_ip4 != new_ip4) {
996
                    if (new_ips['ip4'] == undefined) {
997
                        existing_public.find(".ip4-container").hide();
998
                    } else {
999
                        existing_public.find('span.ip4').text(new_ip4);
1000
                    }
1001
                }
1002
                if (old_ip6 != new_ip6) {
1003
                    if (new_ip6 == undefined) {
1004
                        existing_public.find(".ip6-container").hide();
1005
                    } else {
1006
                        existing_public.find('span.ip6').text(new_ip6);
1007
                        fix_v6_addresses();
1008
                    }
1009
                }
1010
                //update firewall setting
1011
                try {
1012
                    if (server.addresses.values[0].firewallProfile) {
1013
                        existing_public.find("input[value=" + server.addresses.values[0].firewallProfile + "]").attr('checked',true);
1014
                        existing_public.find(".firewall-label span").removeClass('firewall-off firewall-on');
1015
                        if (server.addresses.values[0].firewallProfile == 'DISABLED') {
1016
                            existing_public.find('.firewall-label span').addClass('firewall-off');
1017
                            existing_public.find('.firewall-label span').html(VARIOUS["OFF"]);
1018
                        } else {
1019
                            existing_public.find('.firewall-label span').addClass('firewall-on');
1020
                            existing_public.find('.firewall-label span').html(VARIOUS["ON"]);
1021
                        }
1022
                        existing_public.find(".firewall-apply").hide();
1023
                     }
1024
                } catch (err) {
1025
                    try{console.info('Server ' + server.id + ' has no network addresses')}catch(err){};
1026
                }
1027
                //TODO: server has changed OS
1028

1029
                // indicator handle
1030
                var vm = get_machine(server.id);
1031
                var networkID = "pub";
1032
                var serverID = server.id;
1033
                var network_el = existing_public;
1034

1035
                network_el.find(".network-progress-indicator").hide();
1036
                if (vm.network_transition == "NETWORK_CHANGE") {
1037
                    network_el.find(".network-progress-indicator").show();
1038
                }
1039

1040
                if (vm.network_transition == "CHANGED") {
1041
                    network_el.find(".network-progress-indicator").hide();
1042
                }
1043
            } else {
1044
                // If server does not exist in public network, create it
1045

1046
                // quick fix to skip machines with no addresses
1047
                if (server.addresses) {
1048
                    var machine = $("#networks-pane #public-machine-template").clone().attr("id", "net-pub-server-" + server.id).fadeIn("slow");
1049
                    machine.find('span.name').text(fix_server_name(server.name,25));
1050

1051
                    // unique radio group for each machine
1052
                    machine.find('input[type=radio]').attr({name:'firewall-'+server.id});
1053

1054
                    // find and display ips
1055
                    var ips = get_public_ips(server);
1056
                    if (ips['ip4'] == undefined) {
1057
                        machine.find(".ip4-container").hide();
1058
                    } else {
1059
                        machine.find("span.ip4").text(ips['ip4']);
1060
                    }
1061
                    if (ips['ip6'] == undefined) {
1062
                        machine.find(".ip6-container").hide();
1063
                    } else {
1064
                        machine.find("span.ip6").text(ips['ip6']);
1065
                    }
1066
                    // add the proper icon
1067
                    if (server.status=='BUILD' || server.status=='ACTIVE' ||server.status=='REBOOT') {
1068
                        machine.find("img.logo").attr("src","static/icons/machines/medium/" + server_image + '-on.png');
1069
                    } else {
1070
                        machine.find("img.logo").attr("src","static/icons/machines/medium/" + server_image + '-off.png');
1071
                    }
1072
                    machine.appendTo("#networks-pane .public-networks .machines-list");
1073
                    fix_v6_addresses();
1074
                    //update firewall setting
1075
                    try {
1076
                        if (server.addresses.values[0].firewallProfile) {
1077
                            machine.find("input[value=" + server.addresses.values[0].firewallProfile + "]").attr('checked',true);
1078
                            machine.find(".firewall-label span").removeClass('firewall-off firewall-on');
1079
                            if (server.addresses.values[0].firewallProfile == 'DISABLED') {
1080
                                machine.find('.firewall-label span').addClass('firewall-off');
1081
                                machine.find('.firewall-label span').html(VARIOUS["OFF"]);
1082
                            } else {
1083
                                machine.find('.firewall-label span').addClass('firewall-on');
1084
                                machine.find('.firewall-label span').html(VARIOUS["ON"]);
1085
                            }
1086
                        }
1087
                        machine.find(".firewall-apply").hide();
1088
                    } catch (err) {
1089
                        try{console.info('Server ' + server.id + ' has no network addresses')}catch(err){};
1090
                    }
1091

1092
                    // indicator handle
1093
                    var vm = get_machine(server.id);
1094
                    var networkID = "pub";
1095
                    var serverID = server.id;
1096
                    var network_el = machine;
1097
                    
1098
                    network_el.find(".network-progress-indicator").hide();
1099
                    if (vm.network_transition == "NETWORK_CHANGE") {
1100
                        network_el.find(".network-progress-indicator").show();
1101
                    }
1102

1103
                    if (vm.network_transition == "CHANGED") {
1104
                        network_el.find(".network-progress-indicator").hide();
1105
                    }
1106

1107
                    // vm added. apply firewall options change handlers
1108
                    $(".firewall-content input[type=radio]", machine).change(function() {
1109
                        var vm = server;
1110
                        var el = $(this).closest(".firewall-content");
1111
                        var current_profile = get_firewall_profile(vm.id);
1112
                        var selected_profile = $(this).val();
1113
                        
1114
                        if (current_profile == selected_profile) {
1115
                            el.find(".firewall-apply").hide();
1116
                        } else {
1117
                            el.find(".firewall-apply").show();
1118
                        }
1119
                    })
1120
                }
1121
            }
1122

1123
            /*
1124
            Now update all private networks, this does NOT check for
1125
            disconnected servers (see above in updating private networks).
1126
            Since one server may belong to more than one private networks,
1127
            we follow a different approach.
1128
            We check each server and add, update or leave it as it is accordingly
1129
            */
1130
            try {
1131
                $.each(server.addresses.values, function(i,server_net) {
1132
                    // find in which private networks it belongs
1133
                    if (server_net.id != "public") {
1134
                        var existing_private = $("#networks-pane .private-networks #net-" + server_net.id + "-server-" + server.id);
1135
                        // add new server
1136
                        if (!existing_private.length) {
1137
                            var machine = $("#networks-pane #private-machine-template").clone().attr("id", "net-" + server_net.id + "-server-" + server.id).fadeIn("slow");
1138
                            machine.find('span.name').text(fix_server_name(server.name, 25));
1139

1140
                            // the id of the server the callback function will show connect message for
1141
                            var CONNECT_SERVER_ID = server.id;
1142
                            machine.find('.machine-connect').click(function(){
1143
                                // keep id in local scope
1144
                                var id = CONNECT_SERVER_ID;
1145
                                machine_connect([machine_connect, id])
1146
                            });
1147

1148
                            if (server.status=='BUILD' || server.status=='ACTIVE' ||server.status=='REBOOT') {
1149
                                machine.find("img.logo").attr("src","static/icons/machines/medium/" + server_image + '-on.png');
1150
                            } else {
1151
                                machine.find("img.logo").attr("src","static/icons/machines/medium/" + server_image + '-off.png');
1152
                            }
1153
                            machine.appendTo("#networks-pane .private-networks #net-" + server_net.id + " .machines-list");
1154
                        // hide spinners
1155
                        $('#net-' + server_net.id + '.network div.status').text(NET_STATES['ACTIVE']);
1156
                        $('#net-' + server_net.id + '.network img.spinner').hide();
1157
                        }
1158
                        // server was deleted
1159
                        if (server.status == 'DELETED') {
1160
                            existing_private.remove();
1161
                        }
1162
                        // server was renamed
1163
                        if (server.name != existing_private.find('span.name').text()) {
1164
                            existing_private.find('span.name').text(fix_server_name(server.name,25));
1165
                        }
1166
                        // server has changed state
1167
                        if (server.status=='BUILD' || server.status=='ACTIVE' ||server.status=='REBOOT') {
1168
                            existing_private.find("img.logo").attr("src","static/icons/machines/medium/" + server_image + '-on.png');
1169
                        } else {
1170
                            existing_private.find("img.logo").attr("src","static/icons/machines/medium/" + server_image + '-off.png');
1171
                        }
1172
                        //TODO: server has changed OS
1173
                    }
1174
                });
1175
            } catch (err) {
1176
                try{console.info('Server ' + server.id + ' has no network addresses')}catch(err){};
1177
            }
1178
        });
1179
    }
1180
    $("#networks-pane #networks-container > .large-spinner").hide();
1181
    update_net_ui();
1182
}
1183

1184
function update_net_ui() {
1185
    // show all separators and hide the last one
1186
    $("div.private-networks div.separator").show();
1187
    $("div.private-networks div.separator:last").hide();
1188
    // update the counters of servers in each network
1189
    var nets = $('#networks-pane .network');
1190
    $.each(nets, function(i,net) {
1191
        $(net).find('span.machines-count').text($(net).find('.network-machine').length);
1192
    });
1193

1194
    // the private div shows only when private networks are available
1195
    if ($("div.private-networks div.network").length > 0) {
1196
        $("div.private-networks").fadeIn("slow");
1197
    } else {
1198
        $("div.private-networks").fadeOut("slow");
1199
    }
1200

1201
    // tag the first and last seperators for better styling
1202
    $("#pub .network-machine").removeClass('first');
1203
    $("#pub .network-machine").first().addClass('first');
1204
    $("#pub .network-machine").removeClass('last');
1205
    $("#pub .network-machine").last().addClass('last');
1206

1207
    if ($("div.public-networks div.network-machine").length == 1) {
1208
        $("div.public-networks div.network-machine div.network-cable").css('height','60px');
1209
    }
1210

1211
    //remove top margin from the first machine of each private network
1212
    $(".private-networks").find(".network-contents .network-machine:first-child").css("margin-top","0");
1213

1214
}
1215

1216
// indicate that the requested action was not completed
1217
function display_failure(status, networkID, action, responseText) {
1218
    $('#networks-container #net-'+networkID+ ' .spinner').hide();
1219
    $('#networks-container #net-'+networkID+ ' .action_error .action').text(action);
1220
    $('#networks-container #net-'+networkID+ ' .action_error .code').text(status);
1221
    $('#networks-container #net-'+networkID+ ' .action_error .message').text(responseText);
1222
    $('#networks-container #net-'+networkID+ ' .action_error').show();
1223
}
1224

1225
// reposition multiple confirmation box on window resize
1226
$(window).resize(function(){
1227
    if (this.innerHeight - 220 < $('#networks-pane #networks-container').height()) {
1228
        $('#networks-pane .confirm_multiple').addClass('fixed');
1229
        $('div.reboot-dialog').addClass('fixed');
1230
    } else {
1231
        $('#networks-pane .confirm_multiple').removeClass('fixed');
1232
        $('div.reboot-dialog').removeClass('fixed');
1233
    }
1234
});
1235

1236
// basic functions executed on page load
1237
// hide the all of the networks contents
1238
$("#networks-pane .network-contents").hide();
1239
// hide the all of the firewall contents
1240
$("#networks-pane .firewall-content").hide();
1241
changes_since = 0; // to reload full list of servers
1242
networks_changes_since= 0; // to reload full list of networks
1243
// there is always one public network to render
1244
var pubNet = $("#networks-pane #public-template").clone().attr("id", "pub").fadeIn("slow");
1245
pubNet.appendTo("#networks-pane .public-networks");
1246
update_networks(UPDATE_INTERVAL);
1247

1248
//fix ie z-index bug by moving the overlays to the bottom
1249
$(document).ready(function() {
1250
    if ($.browser.msie) {
1251
        $("body").append($("#networks-wizard"));
1252
        $("body").append($("#add-machines-wizard"));
1253
    }
1254
});
1255

1256
//IE specific fixes
1257
if ($.browser.msie) {
1258
    //IE fix for network div hover
1259
    $("div.network").live("mouseenter", function () {
1260
        $(this).css("background-color","#A1C8DB");
1261
        $(this).find(".actions a").css("visibility","visible");
1262
    });
1263
    $("div.network").live("mouseleave", function () {
1264
        $(this).css("background-color","transparent");
1265
        $(this).find(".actions a").css("visibility","hidden");
1266
    });
1267
    $("div.machine-actions").live("mouseenter", function () {
1268
        $(this).find("a").css("visibility","visible");
1269
    });
1270
    $("div.machine-actions").live("mouseleave", function () {
1271
        $(this).find("a").css("visibility","hidden");
1272
    });
1273
    //IE fix for network machine hover
1274
    $("div.network-machine").live("mouseenter", function () {
1275
        $(this).css("background-color","#84B7D0");
1276
        $(this).find("div.machine-actions a").css("visibility","visible");
1277
    });
1278
    $("div.network-machine").live("mouseleave", function () {
1279
        $(this).css("background-color","transparent");
1280
        $(this).find("div.machine-actions a").css("visibility","hidden");
1281
    });
1282
    //IE fix for network machine hover
1283
    $("button.reboot-single").live("mouseenter", function () {
1284
        $(this).css("background-color","#FF7F2A");
1285
    });
1286
    $("button.reboot-single").live("mouseleave", function () {
1287
        $(this).css("background-color","transparent");
1288
    });
1289
}
1290
</script>