root / snf-cyclades-app / synnefo / ui / static / snf / js / ui / web / ui_ips_view.js @ 643fe7e3
History | View | Annotate | Download (7.8 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 views = snf.views = snf.views || {}
|
43 |
var storage = snf.storage = snf.storage || {};
|
44 |
|
45 |
views.IpPortView = views.ext.ModelView.extend({ |
46 |
tpl: '#ip-port-view-tpl', |
47 |
|
48 |
init: function() { |
49 |
this.model.bind("remove", function() { |
50 |
this.el.remove();
|
51 |
}, this);
|
52 |
}, |
53 |
|
54 |
vm_status_cls: function(vm) { |
55 |
var cls = 'inner clearfix main-content'; |
56 |
if (!this.model.get('vm')) { return cls } |
57 |
if (this.model.get('vm').in_error_state()) { |
58 |
cls += ' vm-status-error';
|
59 |
} |
60 |
return cls
|
61 |
}, |
62 |
|
63 |
vm_style: function() { |
64 |
var cls, icon_state;
|
65 |
var style = "background-image: url('{0}')"; |
66 |
var vm = this.model.get('vm') |
67 |
if (!vm) { return } |
68 |
this.$(".model-logo").removeClass("state1 state2 state3 state4"); |
69 |
icon_state = vm.is_active() ? "on" : "off"; |
70 |
if (icon_state == "on") { |
71 |
cls = "state1"
|
72 |
} else {
|
73 |
cls = "state2"
|
74 |
} |
75 |
this.$(".model-logo").addClass(cls); |
76 |
return style.format(this.get_vm_icon_path(this.model.get('vm'), |
77 |
'medium2'));
|
78 |
}, |
79 |
|
80 |
get_vm_icon_path: function(vm, icon_type) { |
81 |
var os = vm.get_os();
|
82 |
var icons = window.os_icons || views.IconView.VM_OS_ICONS;
|
83 |
|
84 |
if (icons.indexOf(os) == -1) { |
85 |
os = "unknown";
|
86 |
} |
87 |
|
88 |
return views.IconView.VM_OS_ICON_TPLS()[icon_type].format(os);
|
89 |
}, |
90 |
|
91 |
disconnect: function() { |
92 |
this.model.actions.reset_pending();
|
93 |
this.model.set({status: 'DISCONNECTING'}); |
94 |
} |
95 |
}); |
96 |
|
97 |
views.IpView = views.ext.ModelView.extend({ |
98 |
status_map: {
|
99 |
'CONNECTED': 'In use', |
100 |
'ACTIVE': 'In use', |
101 |
'CONNECTING': 'Attaching', |
102 |
'DISCONNECTING': 'Detaching', |
103 |
'DOWN': 'In use', |
104 |
'DISCONNECTED': 'Available', |
105 |
'REMOVING': 'Destroying' |
106 |
}, |
107 |
|
108 |
status_cls_map: {
|
109 |
'CONNECTED': 'status-active', |
110 |
'ACTIVE': 'status-active', |
111 |
'CONNECTING': 'status-progress', |
112 |
'DISCONNECTING': 'status-progress', |
113 |
'DOWN': 'status-inactive', |
114 |
'DISCONNECTED': 'status-inactive', |
115 |
'UP': 'status-active', |
116 |
'REMOVING': 'status-progress destroying-state', |
117 |
}, |
118 |
|
119 |
tpl: '#ip-view-tpl', |
120 |
auto_bind: ['connect_vm'], |
121 |
|
122 |
status_cls: function() { |
123 |
return this.status_cls_map[this.model.get('status')]; |
124 |
}, |
125 |
|
126 |
status_display: function(v) { |
127 |
return this.status_map[this.model.get('status')]; |
128 |
}, |
129 |
|
130 |
model_icon: function() { |
131 |
var img = 'ip-icon-detached.png'; |
132 |
var src = synnefo.config.images_url + '/{0}'; |
133 |
if (this.model.get('port_id')) { |
134 |
img = 'ip-icon.png';
|
135 |
} |
136 |
return src.format(img);
|
137 |
}, |
138 |
|
139 |
show_connect_overlay: function() { |
140 |
this.model.actions.reset_pending();
|
141 |
var vms = this.model.get("network").connectable_vms; |
142 |
var overlay = this.parent_view.connect_view; |
143 |
overlay.show_vms(this.model, vms, [], this.connect_vm); |
144 |
}, |
145 |
|
146 |
disconnect: function(model, e) { |
147 |
e && e.stopPropagation(); |
148 |
this.model.do_disconnect();
|
149 |
}, |
150 |
|
151 |
connect_vm: function(vms) { |
152 |
var overlay = this.parent_view.connect_view; |
153 |
overlay.set_in_progress(); |
154 |
_.each(vms, function(vm) {
|
155 |
vm.connect_floating_ip(this.model,
|
156 |
_.bind(this.connect_complete,this), |
157 |
_.bind(this.connect_error, this)); |
158 |
}, this);
|
159 |
}, |
160 |
|
161 |
connect_complete: function() { |
162 |
var overlay = this.parent_view.connect_view; |
163 |
overlay.hide(); |
164 |
overlay.unset_in_progress(); |
165 |
this.model.set({'status': 'CONNECTING'}); |
166 |
}, |
167 |
|
168 |
connect_error: function() { |
169 |
var overlay = this.parent_view.connect_view; |
170 |
overlay.hide(); |
171 |
overlay.unset_in_progress(); |
172 |
}, |
173 |
|
174 |
remove: function(model, e) { |
175 |
e && e.stopPropagation(); |
176 |
this.model.do_destroy();
|
177 |
} |
178 |
}); |
179 |
|
180 |
views.IpCollectionView = views.ext.CollectionView.extend({ |
181 |
collection: storage.floating_ips,
|
182 |
collection_name: 'floating_ips', |
183 |
model_view_cls: views.IpView,
|
184 |
create_view: undefined, // no create overlay for IPs |
185 |
quota_key: 'cyclades.floating_ip', |
186 |
initialize: function() { |
187 |
views.IpCollectionView.__super__.initialize.apply(this, arguments); |
188 |
this.connect_view = new views.IPConnectVmOverlay(); |
189 |
this.creating = false; |
190 |
}, |
191 |
|
192 |
set_creating: function() { |
193 |
this.creating = true; |
194 |
this.create_button.addClass("in-progress"); |
195 |
}, |
196 |
|
197 |
reset_creating: function() { |
198 |
this.creating = false; |
199 |
this.create_button.removeClass("in-progress"); |
200 |
}, |
201 |
|
202 |
handle_create_click: function() { |
203 |
if (this.creating) { |
204 |
return
|
205 |
} |
206 |
|
207 |
this.set_creating();
|
208 |
network = synnefo.storage.networks.get_floating_ips_network(); |
209 |
this.collection.create({
|
210 |
floatingip: {}
|
211 |
}, |
212 |
{ |
213 |
success: _.bind(function() { |
214 |
this.post_create();
|
215 |
}, this),
|
216 |
complete: _.bind(function() { |
217 |
this.creating = false; |
218 |
this.reset_creating();
|
219 |
this.collection.fetch();
|
220 |
}, this)});
|
221 |
} |
222 |
}); |
223 |
|
224 |
views.IpsPaneView = views.ext.PaneView.extend({ |
225 |
el: '#ips-pane', |
226 |
collection_view_cls: views.IpCollectionView,
|
227 |
}); |
228 |
|
229 |
views.IPConnectVmOverlay = views.NetworkConnectVMsOverlay.extend({ |
230 |
css_class: "overlay-info connect-ip", |
231 |
title: "Attach IP to machine", |
232 |
allow_multiple: false, |
233 |
|
234 |
show_vms: function(ip, vms, selected, callback, subtitle) { |
235 |
views.IPConnectVmOverlay.__super__.show_vms.call(this,
|
236 |
undefined, vms, selected, callback, subtitle);
|
237 |
this.ip = ip;
|
238 |
this.set_desc("Select machine to attach <em>" + |
239 |
ip.escape('floating_ip_address') +
|
240 |
"</em> to.");
|
241 |
}, |
242 |
|
243 |
set_desc: function(desc) { |
244 |
this.$(".description p").html(desc); |
245 |
} |
246 |
|
247 |
}); |
248 |
|
249 |
})(this);
|