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