root / snf-cyclades-app / synnefo / ui / static / snf / js / ui / web / ui_ips_view.js @ 02effd9c
History | View | Annotate | Download (6.1 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 |
vm_style: function() { |
49 |
var style = "background-image: url('{0}')"; |
50 |
return style.format(this.get_vm_icon_path(this.model.get('vm'), |
51 |
'medium'));
|
52 |
}, |
53 |
|
54 |
get_vm_icon_path: function(vm, icon_type) { |
55 |
var os = vm.get_os();
|
56 |
var icons = window.os_icons || views.IconView.VM_OS_ICONS;
|
57 |
|
58 |
if (icons.indexOf(os) == -1) { |
59 |
os = "unknown";
|
60 |
} |
61 |
|
62 |
return views.IconView.VM_OS_ICON_TPLS()[icon_type].format(os);
|
63 |
}, |
64 |
|
65 |
disconnect: function() { |
66 |
this.model.actions.reset_pending();
|
67 |
this.model.set({status: 'DISCONNECTING'}); |
68 |
} |
69 |
}); |
70 |
|
71 |
views.IpView = views.ext.ModelView.extend({ |
72 |
status_map: {
|
73 |
'CONNECTED': 'Connected', |
74 |
'CONNECTING': 'Connecting', |
75 |
'DISCONNECTING': 'Disconnecting', |
76 |
'DOWN': 'Down', |
77 |
'DISCONNECTED': 'Not connected', |
78 |
'ACTIVE': 'Active', |
79 |
'REMOVING': 'Destroying' |
80 |
}, |
81 |
|
82 |
status_cls_map: {
|
83 |
'CONNECTED': 'status-active', |
84 |
'CONNECTING': 'status-active', |
85 |
'DISCONNECTING': 'status-inactive', |
86 |
'DOWN': 'status-inactive', |
87 |
'DISCONNECTED': 'status-inactive', |
88 |
'UP': 'status-active', |
89 |
'REMOVING': 'status-progress', |
90 |
}, |
91 |
|
92 |
tpl: '#ip-view-tpl', |
93 |
auto_bind: ['connect_vm'], |
94 |
|
95 |
status_cls: function() { |
96 |
return this.status_cls_map[this.model.get('status')]; |
97 |
}, |
98 |
|
99 |
status_display: function(v) { |
100 |
return this.status_map[this.model.get('status')]; |
101 |
}, |
102 |
|
103 |
show_connect_overlay: function() { |
104 |
this.model.actions.reset_pending();
|
105 |
var vms = synnefo.storage.vms.models;
|
106 |
var overlay = this.parent_view.connect_view; |
107 |
overlay.show_vms(this.model, vms, [], this.connect_vm); |
108 |
}, |
109 |
|
110 |
disconnect: function(model, e) { |
111 |
e && e.stopPropagation(); |
112 |
this.model.actions.reset_pending();
|
113 |
this.model.disconnect(this.disconnect_complete) |
114 |
}, |
115 |
|
116 |
disconnect_complete: function() { |
117 |
}, |
118 |
|
119 |
connect_vm: function(vms) { |
120 |
var overlay = this.parent_view.connect_view; |
121 |
overlay.set_in_progress(); |
122 |
_.each(vms, function(vm) {
|
123 |
vm.connect_floating_ip(this.model, this.connect_complete); |
124 |
}, this);
|
125 |
}, |
126 |
|
127 |
connect_complete: function() { |
128 |
var overlay = this.parent_view.connect_view; |
129 |
overlay.hide(); |
130 |
overlay.unset_in_progress(); |
131 |
}, |
132 |
|
133 |
remove: function(model, e) { |
134 |
e && e.stopPropagation(); |
135 |
this.model.actions.reset_pending();
|
136 |
this.model.destroy({
|
137 |
success: _.bind(function() { |
138 |
this.model.set({status: 'REMOVING'}); |
139 |
}, this),
|
140 |
silent: true |
141 |
}); |
142 |
} |
143 |
}); |
144 |
|
145 |
views.IpCollectionView = views.ext.CollectionView.extend({ |
146 |
collection: storage.floating_ips,
|
147 |
collection_name: 'floating_ips', |
148 |
model_view_cls: views.IpView,
|
149 |
create_view: views.IpCreateView,
|
150 |
initialize: function() { |
151 |
views.IpCollectionView.__super__.initialize.apply(this, arguments); |
152 |
this.connect_view = new views.IPConnectVmOverlay(); |
153 |
}, |
154 |
|
155 |
handle_create_click: function() { |
156 |
network = synnefo.storage.networks.get_floating_ips_network(); |
157 |
this.collection.create({
|
158 |
floatingip: {
|
159 |
floating_network_id: network.id
|
160 |
} |
161 |
}, |
162 |
{ |
163 |
complete: _.bind(function() { |
164 |
this.collection.fetch();
|
165 |
}, this)});
|
166 |
} |
167 |
}); |
168 |
|
169 |
views.IpsPaneView = views.ext.PaneView.extend({ |
170 |
el: '#ips-pane', |
171 |
collection_view_cls: views.IpCollectionView,
|
172 |
}); |
173 |
|
174 |
views.IPConnectVmOverlay = views.NetworkConnectVMsOverlay.extend({ |
175 |
css_class: "overlay-info connect-ip", |
176 |
title: "Connect IP to machine", |
177 |
allow_multiple: false, |
178 |
|
179 |
show_vms: function(ip, vms, selected, callback, subtitle) { |
180 |
views.IPConnectVmOverlay.__super__.show_vms.call(this,
|
181 |
undefined, vms, selected, callback, subtitle);
|
182 |
this.ip = ip;
|
183 |
this.set_desc("Select machine to assign <em>" + |
184 |
ip.escape('floating_ip_address') +
|
185 |
"</em> to.");
|
186 |
}, |
187 |
|
188 |
set_desc: function(desc) { |
189 |
this.$(".description p").html(desc); |
190 |
} |
191 |
|
192 |
}); |
193 |
|
194 |
})(this);
|