root / snf-cyclades-app / synnefo / ui / static / snf / js / ui / web / ui_connect_view.js @ 3cac4a52
History | View | Annotate | Download (5.2 kB)
1 |
// Copyright 2011 GRNET S.A. All rights reserved.
|
---|---|
2 |
//
|
3 |
// Redistribution and use in source and binary forms, with or
|
4 |
// without modification, are permitted provided that the following
|
5 |
// conditions are met:
|
6 |
//
|
7 |
// 1. Redistributions of source code must retain the above
|
8 |
// copyright notice, this list of conditions and the following
|
9 |
// disclaimer.
|
10 |
//
|
11 |
// 2. Redistributions in binary form must reproduce the above
|
12 |
// copyright notice, this list of conditions and the following
|
13 |
// disclaimer in the documentation and/or other materials
|
14 |
// provided with the distribution.
|
15 |
//
|
16 |
// THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
|
17 |
// OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
18 |
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
19 |
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
|
20 |
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
21 |
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
22 |
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
23 |
// USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
24 |
// AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
25 |
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
26 |
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
27 |
// POSSIBILITY OF SUCH DAMAGE.
|
28 |
//
|
29 |
// The views and conclusions contained in the software and
|
30 |
// documentation are those of the authors and should not be
|
31 |
// interpreted as representing official policies, either expressed
|
32 |
// or implied, of GRNET S.A.
|
33 |
//
|
34 |
|
35 |
;(function(root){
|
36 |
|
37 |
// root
|
38 |
var root = root;
|
39 |
|
40 |
// setup namepsaces
|
41 |
var snf = root.synnefo = root.synnefo || {};
|
42 |
var models = snf.models = snf.models || {}
|
43 |
var storage = snf.storage = snf.storage || {};
|
44 |
var ui = snf.ui = snf.ui || {};
|
45 |
var util = snf.util = snf.util || {};
|
46 |
|
47 |
var views = snf.views = snf.views || {}
|
48 |
|
49 |
// shortcuts
|
50 |
var bb = root.Backbone;
|
51 |
|
52 |
|
53 |
views.VMConnectView = views.VMOverlay.extend({ |
54 |
|
55 |
view_id: "connect_view", |
56 |
content_selector: "#vm-connect-overlay-content", |
57 |
css_class: 'overlay-vmconnect overlay-info', |
58 |
overlay_id: "vmconnect-overlay", |
59 |
|
60 |
subtitle: "", |
61 |
title: "Connect to machine", |
62 |
|
63 |
initialize: function(options) { |
64 |
views.VMConnectView.__super__.initialize.apply(this);
|
65 |
_.bindAll(this, "handle_success", "handle_error"); |
66 |
|
67 |
this.error = this.$("div.error"); |
68 |
this.info = this.$("div.connection-info"); |
69 |
this.no_public = this.$("div.no-public-ip"); |
70 |
this.description = this.info.find(".description p"); |
71 |
this.connect = this.info.find(".connect p"); |
72 |
this.subinfo = this.info.find(".subinfo"); |
73 |
this.v6_warn = this.info.find(".v6-warn"); |
74 |
|
75 |
var self = this; |
76 |
this.no_public.find("a").click(function(e) { |
77 |
e.preventDefault(); |
78 |
self.hide(); |
79 |
window.setTimeout(function() {
|
80 |
synnefo.router.ips_view(); |
81 |
}, 200)
|
82 |
}); |
83 |
}, |
84 |
|
85 |
beforeOpen: function() { |
86 |
this.$(".clipboard").empty(); |
87 |
}, |
88 |
|
89 |
beforeClose: function() { |
90 |
this.$(".clipboard").empty(); |
91 |
try { delete this.clip; } catch (err) {}; |
92 |
}, |
93 |
|
94 |
show_no_public_ip: function() { |
95 |
this.error.hide();
|
96 |
this.info.hide();
|
97 |
this.no_public.removeClass("hidden").show(); |
98 |
}, |
99 |
|
100 |
handle_success: function(data) { |
101 |
this.error.hide();
|
102 |
this.info.show();
|
103 |
this.v6_warn.hide();
|
104 |
this.no_public.hide();
|
105 |
this.description.html(data.info);
|
106 |
if (data.ssh) {
|
107 |
this.connect.html(data.link.title);
|
108 |
} else {
|
109 |
this.connect.html('<a href="{0}">{1}</a>'.format(data.link.url, data.link.title)) |
110 |
} |
111 |
|
112 |
this.subinfo.html(data.subinfo).show();
|
113 |
if (!data.subinfo) { this.subinfo.hide() }; |
114 |
|
115 |
if (data.ssh) {
|
116 |
var ssh_msg = data.link.title;
|
117 |
this.clip = new snf.util.ClipHelper(this.$(".clipboard"), ssh_msg); |
118 |
} else {
|
119 |
} |
120 |
|
121 |
if (!this.vm.has_public_ipv4()) { |
122 |
this.v6_warn.removeClass("hidden").show(); |
123 |
} else {
|
124 |
this.v6_warn.hide();
|
125 |
} |
126 |
}, |
127 |
|
128 |
handle_error: function() { |
129 |
this.error.show();
|
130 |
this.info.hide();
|
131 |
}, |
132 |
|
133 |
handle_vm_change: function(vm) { |
134 |
if (!this.vm) { this.vm = undefined; return; } |
135 |
if (this.vm.state() == "DESTROY") { |
136 |
this.hide();
|
137 |
} |
138 |
this._update_vm_details();
|
139 |
}, |
140 |
|
141 |
update_vm_details: function() { |
142 |
}, |
143 |
|
144 |
show: function() { |
145 |
views.VMConnectView.__super__.show.apply(this, arguments); |
146 |
|
147 |
this.error.hide();
|
148 |
this.info.hide();
|
149 |
|
150 |
if (!this.vm.has_public_ip()) { |
151 |
this.show_no_public_ip();
|
152 |
} else {
|
153 |
this.vm.get_connection_info($.client.os, this.handle_success, this.handle_error) |
154 |
} |
155 |
} |
156 |
|
157 |
}); |
158 |
|
159 |
})(this);
|