Statistics
| Branch: | Tag: | Revision:

root / ui / static / snf / js / ui / web / ui_connect_view.js @ 1eb9b57e

History | View | Annotate | Download (2.7 kB)

1
;(function(root){
2

    
3
    // root
4
    var root = root;
5
    
6
    // setup namepsaces
7
    var snf = root.synnefo = root.synnefo || {};
8
    var models = snf.models = snf.models || {}
9
    var storage = snf.storage = snf.storage || {};
10
    var ui = snf.ui = snf.ui || {};
11
    var util = snf.util = snf.util || {};
12

    
13
    var views = snf.views = snf.views || {}
14

    
15
    // shortcuts
16
    var bb = root.Backbone;
17

    
18

    
19
    views.VMConnectView = views.VMOverlay.extend({
20
        
21
        view_id: "connect_view",
22
        content_selector: "#vm-connect-overlay-content",
23
        css_class: 'overlay-vmconnect overlay-info',
24
        overlay_id: "vmconnect-overlay",
25

    
26
        subtitle: "",
27
        title: "Connect to machine",
28

    
29
        initialize: function(options) {
30
            views.VMConnectView.__super__.initialize.apply(this);
31
            _.bindAll(this, "handle_success", "handle_error");
32

    
33
            this.error = this.$("div.error");
34
            this.info = this.$("div.connection-info");
35
            this.description = this.info.find(".description p");
36
            this.connect = this.info.find(".connect p");
37
            this.subinfo = this.info.find(".subinfo");
38
        },
39

    
40
        beforeOpen: function() {
41
            this.clip = new snf.util.ClipHelper();
42
            this.connect.parent().append(this.clip.cont);
43
        },
44

    
45
        handle_success: function(data) {
46
            this.error.hide();
47
            this.info.show();
48
            this.description.html(data.info);
49
            if (data.ssh) {
50
                this.connect.html(data.link.title);
51
            } else {
52
                this.connect.html('<a href="{0}">{1}</a>'.format(data.link.url, data.link.title))
53
            }
54

    
55
            this.subinfo.html(data.subinfo).show();
56
            if (!data.subinfo) { this.subinfo.hide() };
57
            
58
            if (data.ssh) {
59
                this.clip.cont.show();
60
                this.clip.setText(data.link.title);
61
            } else {
62
                this.clip.cont.hide();
63
            }
64
        },
65

    
66
        handle_error: function() {
67
            this.error.show();
68
            this.info.hide();
69
        },
70

    
71
        handle_vm_change: function(vm) {
72
            if (!this.vm) { this.vm = undefined; return; }
73
            if (this.vm.state() == "DESTROY") {
74
                this.hide();
75
            }
76
            this._update_vm_details();
77
        },
78
        
79
        update_vm_details: function() {
80
        },
81

    
82
        show: function() {
83
            views.VMConnectView.__super__.show.apply(this, arguments);
84
            
85
            this.error.hide();
86
            this.info.hide();
87

    
88
            this.vm.get_connection_info($.client.os, this.handle_success, this.handle_error)
89
        }
90

    
91
    });
92
    
93
})(this);