root / snf-cyclades-app / synnefo / ui / new_ui / ui / javascripts / okeanos-ember.js @ d0fe8c12
History | View | Annotate | Download (6.9 kB)
1 |
/* Init Application */
|
---|---|
2 |
|
3 |
window.Okeanos = Ember.Application.create({ |
4 |
currentPath: 'vms', |
5 |
LOG_TRANSITIONS: true, // To have Ember write out transition events to the log (it can be helpful to see exactly what is going on with the router) |
6 |
}); |
7 |
|
8 |
Okeanos.ApplicationAdapter = DS.FixtureAdapter.extend(); |
9 |
|
10 |
/* Mapping */
|
11 |
|
12 |
Okeanos.Router.map(function() {
|
13 |
|
14 |
for(var i=0; i<Okeanos.places.length; i++) |
15 |
this.resource(Okeanos.places[i].destination);
|
16 |
}); |
17 |
|
18 |
|
19 |
/* Routes */
|
20 |
|
21 |
Okeanos.ApplicationRoute = Ember.Route.extend({ |
22 |
model: function() { |
23 |
|
24 |
return {email: 'athina@mail.com'}; |
25 |
} |
26 |
}); |
27 |
|
28 |
Okeanos.VmsRoute = Ember.Route.extend({ |
29 |
model: function() { |
30 |
return this.store.find('vm'); |
31 |
}, |
32 |
renderTemplate: function(controller) { |
33 |
this.render('snfElems', {controller: controller}) |
34 |
} |
35 |
}); |
36 |
|
37 |
Okeanos.NetsRoute = Ember.Route.extend({ |
38 |
model: function() { |
39 |
return [{id: '1', name:'net1', status: 'active'}, {id: '2', name:'net2', status: 'error'}]; |
40 |
}, |
41 |
renderTemplate: function(controller) { |
42 |
this.render('snfElems', {controller: controller}) |
43 |
} |
44 |
}); |
45 |
|
46 |
|
47 |
/* Controllers */
|
48 |
|
49 |
Okeanos.ApplicationController = Ember.Controller.extend({ |
50 |
updateCurrentPath: function() { |
51 |
Okeanos.set('currentPath', this.get('currentPath')) |
52 |
console.log('AppController: CurrentPath ->', this.get('currentPath')); |
53 |
return this.get('currentPath'); |
54 |
}.observes('currentPath'),
|
55 |
actions: {
|
56 |
test: function() { |
57 |
console.log('This is test from Okeanos.ApplicationController');
|
58 |
return 0; |
59 |
} |
60 |
}, |
61 |
|
62 |
pageTitle : function() { |
63 |
var currentPath =this.get('currentPath'); |
64 |
if(currentPath!== 'index') return Okeanos.places.findBy('destination', this.get('currentPath')).title; |
65 |
else return 'Home'; |
66 |
}.property('currentPath'),
|
67 |
|
68 |
// name: "okeanos application",
|
69 |
}); |
70 |
|
71 |
|
72 |
Okeanos.ElemsController = Ember.ArrayController.extend({ |
73 |
// ElementController: 'vm',
|
74 |
type: undefined, |
75 |
itemController: function(){ |
76 |
var type = this.type; |
77 |
console.log('type ', type.substring(0, type.length - 1)) |
78 |
return type.substring(0, type.length - 1); |
79 |
}.property(), |
80 |
icon: function() { |
81 |
return Okeanos.places.findBy('destination', this.get('type')).icon.replace('outline', 'full'); |
82 |
}.property(), |
83 |
iconCreate: function() { |
84 |
return this.icon.replace('full', 'create-full') |
85 |
}.property(), |
86 |
hasOS: function(){ |
87 |
if(Okeanos.get('currentPath') == "vms") |
88 |
return true; |
89 |
else return false; |
90 |
}.property(), |
91 |
}); |
92 |
|
93 |
Okeanos.VmsController = Okeanos.ElemsController.extend({ |
94 |
type: 'vms' |
95 |
}); |
96 |
|
97 |
|
98 |
Okeanos.NetsController = Okeanos.ElemsController.extend({ |
99 |
type: 'nets' |
100 |
}); |
101 |
|
102 |
|
103 |
Okeanos.ElemController = Ember.ObjectController.extend({ |
104 |
needs: [],
|
105 |
actionsList: Okeanos.AllActions,
|
106 |
setAvailableActions: function() { |
107 |
var parent = this.needs; |
108 |
var self = this; |
109 |
return this.actionsList.filter(function(el) { |
110 |
return _.contains(el['snf-components'], self.get('controllers.'+parent).type) &&( _.contains(el['enabled-status'], self.get('model.status')) || _.contains(el['enabled-status'], 'all')); |
111 |
}) |
112 |
// return this.actionsList
|
113 |
}.property(), |
114 |
createBtn: false, |
115 |
actions: {
|
116 |
shutdown: function(param) { |
117 |
console.log(this.get('model.status')); |
118 |
this.set('model.status', 'shutting') |
119 |
console.log(this.get('model.status')); |
120 |
// this.set('building')
|
121 |
}, |
122 |
destroyElement: function(param) { |
123 |
var element = this.get('model'); |
124 |
element.deleteRecord(); |
125 |
element.save(); |
126 |
} |
127 |
} |
128 |
}); |
129 |
|
130 |
Okeanos.VmController = Okeanos.ElemController.extend({ |
131 |
needs: ['vms'] |
132 |
}); |
133 |
|
134 |
Okeanos.NetController = Okeanos.ElemController.extend({ |
135 |
needs: ['nets'] |
136 |
}); |
137 |
|
138 |
|
139 |
/* Views */
|
140 |
|
141 |
Okeanos.NavIconView = Ember.View.extend({ |
142 |
tagName: 'span', |
143 |
click: function(e) { |
144 |
var parentEl = this.$().parent('a'); |
145 |
var currentEl = this.$().parents('li').siblings('li').find('a.current'); |
146 |
|
147 |
ui.replaceClass(currentEl, 'full', 'outline', 'snf-'); |
148 |
ui.replaceClass(parentEl, 'outline', 'full', 'snf-'); |
149 |
} |
150 |
|
151 |
}); |
152 |
|
153 |
Okeanos.NavigationView = Ember.CollectionView.extend({ |
154 |
tagName: "ul", |
155 |
classNames: ['icons-nav'], |
156 |
|
157 |
content: Okeanos.places,
|
158 |
itemViewClass: Ember.View.extend({
|
159 |
template: Ember.TEMPLATES["navigationItem"] |
160 |
}), |
161 |
}); |
162 |
|
163 |
|
164 |
Okeanos.ElemView = Ember.View.extend({ |
165 |
// templateName: 'elem',
|
166 |
template: Ember.TEMPLATES['snfElem'], |
167 |
tagName: 'li', |
168 |
classNameBindings: ['status'], |
169 |
attributeBindings: ['data-status'], |
170 |
'data-status': function() { |
171 |
return this.status; |
172 |
}.property(), |
173 |
status: function() { |
174 |
return this.get('controller.status'); |
175 |
}.property('controller.status')
|
176 |
}) |
177 |
|
178 |
|
179 |
/* Components */
|
180 |
|
181 |
Okeanos.ActionBtnsSimpleComponent = Ember.Component.extend({ |
182 |
tagName: 'a', |
183 |
click: function() { |
184 |
this.sendAction("action", this.get('param')); |
185 |
} |
186 |
}); |
187 |
|
188 |
|
189 |
Okeanos.LoginMenuComponent = Ember.Component.extend({ |
190 |
classNames: ['login'], |
191 |
didInsertElement: function() { |
192 |
console.log('didInsertElement');
|
193 |
var self = this.$(); |
194 |
self.mouseenter(function(e){
|
195 |
self.find('ul').stop(true, true).slideDown(200); |
196 |
}); |
197 |
self.mouseleave(function(e){
|
198 |
self.find('ul').stop(true, true).slideUp(200); |
199 |
}); |
200 |
|
201 |
} |
202 |
}); |
203 |
|
204 |
; |
205 |
|
206 |
Okeanos.Account = DS.Model.extend({ |
207 |
email: DS.attr('string') |
208 |
}); |
209 |
|
210 |
// CHECK can i use a single obj and not an array of obj
|
211 |
Okeanos.Account.FIXTURES = [{ |
212 |
id: 001, |
213 |
email: "athina@mail.com" |
214 |
}]; |
215 |
|
216 |
|
217 |
|
218 |
Okeanos.Vm = DS.Model.extend({ |
219 |
// id: DS.attr('number'), we do not define it ;)
|
220 |
name: DS.attr('string'), |
221 |
hostname: DS.attr('string'), |
222 |
status: DS.attr('string'), |
223 |
os: DS.attr()
|
224 |
}); |
225 |
|
226 |
Okeanos.Vm.FIXTURES = |
227 |
[{ |
228 |
id: 125355, |
229 |
name: "web-server", |
230 |
hostname: "user@snf-38389.vm.okeanos.grnet.gr", |
231 |
status: "running", |
232 |
os: "kubuntu" |
233 |
}, |
234 |
{ |
235 |
id: 12, |
236 |
name: "another-server", |
237 |
hostname: "user@snf-33333.vm.okeanos.grnet.gr", |
238 |
status: "off", |
239 |
os: "fedora" |
240 |
}]; |
241 |
|
242 |
Okeanos.Net = DS.Model.extend({ |
243 |
name: DS.attr('string'), |
244 |
status: DS.attr('string'), |
245 |
vms: DS.attr(),
|
246 |
ips: DS.attr()
|
247 |
}); |
248 |
|
249 |
Okeanos.Net.FIXTURES = |
250 |
[{ |
251 |
|
252 |
}]; |
253 |
|
254 |
|
255 |
|
256 |
|
257 |
Okeanos.places = [{ |
258 |
destination: "vms", |
259 |
title: "Virtual Machines", |
260 |
icon: "snf-pc-outline" |
261 |
}, |
262 |
{ |
263 |
destination: "nets", |
264 |
title: "Network", |
265 |
icon: "snf-network-outline" |
266 |
}, |
267 |
{ |
268 |
destination: "volumes", |
269 |
title: "Volumes", |
270 |
icon: "snf-volume-outline" |
271 |
}, |
272 |
{ |
273 |
destination: "pithos", |
274 |
title: "Pithos", |
275 |
icon: "snf-pithos-outline" |
276 |
}, |
277 |
{ |
278 |
destination: "images", |
279 |
title: "Images", |
280 |
icon: "snf-image-outline" |
281 |
}, |
282 |
{ |
283 |
destination: "snapshots", |
284 |
title: "Snapshots", |
285 |
icon: "snf-snapshot-outline" |
286 |
}, |
287 |
{ |
288 |
destination: "ips", |
289 |
title: "IPs", |
290 |
icon: "snf-nic-outline" |
291 |
}, |
292 |
{ |
293 |
destination: "sshkeys", |
294 |
title: "SSh Keys", |
295 |
icon: "snf-key-outline" |
296 |
}]; |
297 |
|
298 |
|
299 |
Okeanos.AllActions = [{ |
300 |
description:'start', |
301 |
'snf-components':['vms'], |
302 |
'enabled-status': ['off'], |
303 |
action: 'is this a function?' |
304 |
}, |
305 |
{ |
306 |
description:'destroyElement', |
307 |
'snf-components': ['vms', 'nets'], |
308 |
'enabled-status': ['all'], |
309 |
action: 'is this a function?', |
310 |
}, |
311 |
{ |
312 |
description:'shutdown', |
313 |
'snf-components': ['vms'], |
314 |
'enabled-status': ['running'], |
315 |
action: 'is this a function?' |
316 |
}, |
317 |
{ |
318 |
description:'add machine', |
319 |
'snf-components': ['nets'], |
320 |
'enabled-status': ['active'], |
321 |
action: 'is this a function?' |
322 |
}, |
323 |
{ |
324 |
description:'action for all', |
325 |
'snf-components': ['vms', 'nets'], |
326 |
'enabled-status': ['all'], |
327 |
action: 'is this a function?' |
328 |
}] |