Revision 9ac432ec

b/ui/static/synnefo.js
1406 1406
            states[states.length] = checkbox.className;
1407 1407
        }
1408 1408

  
1409
        var ip = $("#" + checkbox.id.replace('input-','') + ".ip span.public").text();
1410
        if (ip.replace('undefined','').length)
1411
            states[states.length] = 'network';
1409
        if (vm_has_public_ip(vm) && vm.status == "ACTIVE") { 
1410
            states = ['network'];
1411
            if (checked.length>1)
1412
                states[states.length] = 'multiple';
1413
        }
1412 1414
    });
1413 1415

  
1414 1416
    // decide which actions should be enabled
......
3379 3381
    return (bytes/Math.pow(1024, Math.floor(e))).toFixed(2)+" "+s[e];
3380 3382
}
3381 3383

  
3384
// find closest to the given element vm
3385
function iconview_closest_vm(el) {
3386
    id = $(el).closest(".machine-container").attr("id");
3387
    return get_machine(id);
3388
}
3389

  
3390
// find closest to the given element vm
3391
function singleview_closest_vm(el) {
3392
    id = $(el).closest(".single-container").attr("id");
3393
    return get_machine(id);
3394
}
3395

  
3396
function vm_has_public_ip(vm) {
3397
    try {
3398
        var serverIP = vm.addresses.values[0].values[0].addr;
3399
        return serverIP;
3400
    } catch (err) { return false }
3401

  
3402
}
b/ui/templates/machines_icon.html
179 179
// handle connect machine image states
180 180
$("div.connect-arrow, div.running .machine .logo").live('mouseover',
181 181
    function() {
182
        if ($(this).parent().parent().find('.status').text().replace(TRANSITION_STATE_APPEND, "") != STATUSES['ACTIVE']) { return };
182
        vm = iconview_closest_vm(this);
183
        if ($(this).parent().parent().find('.status').text().replace(TRANSITION_STATE_APPEND, "") != STATUSES['ACTIVE'] || !vm_has_public_ip(vm)) { return };
183 184
        set_machine_os_image($(this).parent().parent(), "icon", "hover", undefined, 1);
184 185
        var parent = $(this).parent().parent();
185 186
        parent.find(".connect-arrow").show().addClass('border-hover');
......
187 188

  
188 189
$("div.connect-arrow, div.running .machine .logo").live('mouseleave',
189 190
    function() {
190
        if ($(this).parent().parent().find('.status').text().replace(TRANSITION_STATE_APPEND, "") != STATUSES['ACTIVE']) { return };
191
        vm = iconview_closest_vm(this);
192
        if ($(this).parent().parent().find('.status').text().replace(TRANSITION_STATE_APPEND, "") != STATUSES['ACTIVE'] || !vm_has_public_ip(vm)) { return };
191 193
        set_machine_os_image($(this).parent().parent(), "icon", "hover", undefined, 1, "hover");
192 194
        // mouseup outside the element is not fired
193 195
        set_machine_os_image($(this).parent().parent(), "icon", "hover", undefined, 1, "click");
......
197 199

  
198 200
$("div.connect-arrow, div.running .machine .logo").live('mousedown',
199 201
function() {
200
        if ($(this).parent().parent().find(".connect-arrow:visible").length == 0) { return };
202
        vm = iconview_closest_vm(this);
203
        if ($(this).parent().parent().find(".connect-arrow:visible").length == 0 || !vm_has_public_ip(vm)) { return };
201 204
        set_machine_os_image($(this).parent().parent(), "icon", "click", undefined, 1);
202 205
    });
203 206

  
204 207
$("div.connect-arrow, div.running .machine .logo").live('mouseup',
205 208
    function() {
206
        if ($(this).parent().parent().find(".connect-arrow:visible").length == 0) { return };
209
        vm = iconview_closest_vm(this);
210
        if ($(this).parent().parent().find(".connect-arrow:visible").length == 0 || !vm_has_public_ip(vm)) { return };
207 211
        set_machine_os_image($(this).parent().parent(), "icon", "click", undefined, 1, "click");
208 212
    });
209 213

  
210 214
// actions on machine mouseover
211 215
$("#machinesview-icon.standard .machine").live('mouseover', function() {
212 216
    // show connect button only if the machine is active
213
    if ($(this).find('.status').text().replace(TRANSITION_STATE_APPEND, "") == STATUSES['ACTIVE']) {
217
    vm = iconview_closest_vm(this);
218
    if ($(this).find('.status').text().replace(TRANSITION_STATE_APPEND, "") == STATUSES['ACTIVE'] && vm_has_public_ip(vm)) {
214 219
        $(this).find("div.connect-arrow").show();
215 220
        $(this).find("div.connect-border").show();
216 221
    }
......
235 240

  
236 241
// open console on machine logo click
237 242
$("#machinesview-icon.standard .running div.logo").live('click', function(){
238
    if ($(this).parent().parent().find(".connect-arrow:visible").length == 0) { return };
243
    vm = iconview_closest_vm(this);
244
    if ($(this).parent().parent().find(".connect-arrow:visible").length == 0 || !vm_has_public_ip(vm)) { return };
239 245
    var serverID = $(this).parent().parent().attr("id");
240 246
    machine_connect([machine_connect, serverID]);
241 247
    return false;
b/ui/templates/machines_list.html
139 139

  
140 140
// TODO: This should be populated with more rules for all available states
141 141
//a key represents an action, while values are lists with permitted states to which the action can be applied
142
var actions = { 'reboot':        ['UNKOWN', 'ACTIVE', 'REBOOT', 'multiple'],
143
                'shutdown':      ['UNKOWN', 'ACTIVE', 'REBOOT', 'multiple'],
144
                'connect':       ['UNKOWN', 'ACTIVE'],
142
var actions = { 'reboot':        ['UNKOWN', 'ACTIVE', 'REBOOT', 'network', 'multiple'],
143
                'shutdown':      ['UNKOWN', 'ACTIVE', 'REBOOT', 'network', 'multiple'],
144
                'connect':       ['UNKOWN', 'network'],
145 145
                //'network-connect':       ['UNKOWN', 'ACTIVE'],
146 146
                //'network-disconnect':    ['UNKOWN', 'ACTIVE', 'network'],
147
                'console':       ['UNKOWN', 'ACTIVE', 'multiple'],
148
                'details':       ['UNKOWN', 'ACTIVE', 'REBOOT', 'STOPPED'],
147
                'console':       ['UNKOWN', 'ACTIVE', 'multiple', 'network'],
148
                'details':       ['UNKOWN', 'ACTIVE', 'REBOOT', 'STOPPED', 'network'],
149 149
                'start':         ['UNKOWN', 'STOPPED', 'multiple'],
150
                'destroy':       ['UNKOWN', 'ACTIVE', 'STOPPED', 'REBOOT', 'ERROR', 'BUILD', 'multiple']
150
                'destroy':       ['UNKOWN', 'ACTIVE', 'STOPPED', 'REBOOT', 'ERROR', 'BUILD', 'network', 'multiple']
151 151
                //'group':         ['UNKOWN', 'ACTIVE', 'STOPPED', 'REBOOT','multiple'],
152 152
               };
153 153

  
b/ui/templates/machines_single.html
198 198

  
199 199
// handle connect machine image states
200 200
$("div.connect-arrow, .single-image").live('mouseenter',
201
    function() {
201
function() {
202
        has_ip = vm_has_public_ip(singleview_closest_vm(this));
202 203
        // ugly check to see if machine is running
203
        if ($(this).parent().find(".connect-arrow:visible").length == 0) { return };
204
        if ($(this).parent().find(".connect-arrow:visible").length == 0 || !has_ip) { return };
204 205
        set_machine_os_image($(this).parent().parent(), "single", "hover", undefined, 1);
205 206
        var parent = $(this).parent().parent();
206 207
        parent.find(".connect-arrow").show().addClass('border-hover');
......
208 209

  
209 210
$("div.connect-arrow, .single-image").live('mouseleave',
210 211
    function() {
211
        if ($(this).parent().find(".connect-arrow:visible").length == 0) { return };
212
        has_ip = vm_has_public_ip(singleview_closest_vm(this));
213
        if ($(this).parent().find(".connect-arrow:visible").length == 0 || !has_ip) { return };
212 214
        set_machine_os_image($(this).parent().parent(), "single", "hover", undefined, 1, "hover");
213 215
        set_machine_os_image($(this).parent().parent(), "single", "click", undefined, 1, "click");
214 216
        var parent = $(this).parent().parent();
......
217 219

  
218 220
$("div.connect-arrow, .single-image").live('mousedown',
219 221
    function() {
220
        if ($(this).parent().find(".connect-arrow:visible").length == 0) { return };
222
        has_ip = vm_has_public_ip(singleview_closest_vm(this));
223
        if ($(this).parent().find(".connect-arrow:visible").length == 0 || !has_ip) { return };
221 224
        set_machine_os_image($(this).parent().parent(), "single", "click", undefined, 1);
222 225
    });
223 226

  
224 227
$("div.connect-arrow, .single-image").live('mouseup',
225 228
    function() {
226
        if ($(this).parent().find(".connect-arrow:visible").length == 0) { return };
229
        has_ip = vm_has_public_ip(singleview_closest_vm(this));
230
        if ($(this).parent().find(".connect-arrow:visible").length == 0 || !has_ip) { return };
227 231
        set_machine_os_image($(this).parent().parent(), "single", "click", undefined, 1, "click");
228 232
    });
229 233

  
......
415 419
// connect to machine on machine logo click
416 420
$("#machinesview-single.single div.single-image").live('click', function(){
417 421
    if ($(this).parent().find(".connect-arrow:visible").length == 0) { return };
422
    has_ip = vm_has_public_ip(singleview_closest_vm(this));
423
    if (!has_ip) { return }
418 424
    var serverID = $(this).closest(".single-container").attr("id");
419 425
    machine_connect([machine_connect, serverID]);
420 426
    return false;
......
512 518
                    log_server_status_change(existing, server.status);
513 519
                    set_machine_os_image(existing, "single", "on", server_image);
514 520
                    existing.find(".column1 .state-label").text(STATUSES[server.status]);
515
                    existing.find(".connect-border").show();
516
                    existing.find(".connect-arrow").show();
521

  
522
                    vm = get_machine(existing.attr("id"));
523
                    has_ip = vm_has_public_ip(vm);
524

  
525
                    if (has_ip) {
526
                        existing.find(".connect-border").show();
527
                        existing.find(".connect-arrow").show();
528
                    } else {
529
                        existing.find(".connect-border").hide();
530
                        existing.find(".connect-arrow").hide();
531
                    }
532

  
517 533
                    existing.find(".column1 .state .spinner").hide();
518 534
                    existing.find(' .wave').attr('src','static/icons/indicators/medium/wave.gif').show();
519 535
                    existing.find(".column1 .state").removeClass().addClass("state running-state");
......
529 545
                        // if it has been rebooted or just created
530 546
                        log_server_status_change(existing, server.status);
531 547
                        existing.find(".column1 .state-label").text(STATUSES[server.status]);
532
                        existing.find(".connect-border").show();
533
                        existing.find(".connect-arrow").show();
548
                        vm = get_machine(existing.attr("id"));
549
                        has_ip = vm_has_public_ip(vm);
550

  
551
                        if (has_ip) {
552
                            existing.find(".connect-border").show();
553
                            existing.find(".connect-arrow").show();
554
                        } else {
555
                            existing.find(".connect-border").hide();
556
                            existing.find(".connect-arrow").hide();
557
                        }
534 558
                        existing.find(".column1 .state .spinner").hide();
535 559
                        existing.find(".column1 .state").attr('src','static/icons/indicators/medium/wave.gif').show();
536 560
                        existing.find(".column1 .state").removeClass().addClass("state running-state");
......
622 646
            if (server.status == 'ACTIVE') {
623 647
                $('#machinesview-single.single div.#' + server.id + ' div.action-console').show();
624 648
                $('#machinesview-single.single div.#' + server.id + ' div.action-start').hide();
625
                machine.find(".connect-border").show();
626
                machine.find(".connect-arrow").show();
649

  
650
                vm = get_machine(machine.attr("id"));
651
                has_ip = vm_has_public_ip(vm);
652

  
653
                if (has_ip) {
654
                    machine.find(".connect-border").show();
655
                    machine.find(".connect-arrow").show();
656
                } else {
657
                    machine.find(".connect-border").hide();
658
                    machine.find(".connect-arrow").hide();
659
                }
660

  
627 661
            } else if (server.status == 'REBOOT'){
628 662
                $('#machinesview-single.single div.#' + server.id + ' div.action-console').hide();
629 663
            } else {

Also available in: Unified diff