root / snf-cyclades-app / synnefo / ui / new_ui / ui / javascripts / okeanos-ember.js @ cc5d0e0e
History | View | Annotate | Download (20.4 kB)
1 |
/* Init Application */
|
---|---|
2 |
|
3 |
window.Synnefo = 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 |
Synnefo.ApplicationAdapter = DS.FixtureAdapter.extend();;/* Objects */
|
9 |
|
10 |
Ember.Inflector.inflector.uncountable('account');
|
11 |
|
12 |
Synnefo.Account = DS.Model.extend({ |
13 |
email: DS.attr('string') |
14 |
}); |
15 |
|
16 |
// CHECK can i use a single obj and not an array of obj
|
17 |
Synnefo.Account.FIXTURES = { |
18 |
id: 001, |
19 |
email: "athina@mail.com" |
20 |
}; |
21 |
|
22 |
|
23 |
|
24 |
Synnefo.Vm = DS.Model.extend({ |
25 |
// id: DS.attr('number'), we do not define it ;)
|
26 |
name: DS.attr('string'), |
27 |
hostname: DS.attr('string'), |
28 |
status: DS.attr('string'), |
29 |
os: DS.attr()
|
30 |
}); |
31 |
|
32 |
Synnefo.Vm.FIXTURES = |
33 |
[{ |
34 |
id: 125355, |
35 |
name: "web-server", |
36 |
hostname: "user@snf-38389.vm.okeanos.grnet.gr", |
37 |
status: "running", |
38 |
os: "kubuntu" |
39 |
}, |
40 |
{ |
41 |
id: 12, |
42 |
name: "another-server", |
43 |
hostname: "user@snf-33333.vm.okeanos.grnet.gr", |
44 |
status: "off", |
45 |
os: "fedora" |
46 |
}]; |
47 |
|
48 |
Synnefo.Network = DS.Model.extend({ |
49 |
name: DS.attr('string'), |
50 |
status: DS.attr('string'), |
51 |
}); |
52 |
|
53 |
Synnefo.Network.FIXTURES = |
54 |
[{ |
55 |
id: 11, |
56 |
name: 'Network-1', |
57 |
status: 'running' |
58 |
}, |
59 |
{ |
60 |
id: 22, |
61 |
name: 'Network-2', |
62 |
status: 'error' |
63 |
}]; |
64 |
|
65 |
|
66 |
Synnefo.Volume = DS.Model.extend({ |
67 |
name: DS.attr('string'), |
68 |
status: DS.attr('string'), |
69 |
}); |
70 |
|
71 |
Synnefo.Volume.FIXTURES = |
72 |
[{ |
73 |
id: 111, |
74 |
name: 'Volume-1', |
75 |
status: 'running' |
76 |
}, |
77 |
{ |
78 |
id: 222, |
79 |
name: 'Volume-2', |
80 |
status: 'building' |
81 |
}]; |
82 |
|
83 |
Synnefo.Snapshot = DS.Model.extend({ |
84 |
name: DS.attr('string'), |
85 |
status: DS.attr('string'), |
86 |
}); |
87 |
|
88 |
Synnefo.Snapshot.FIXTURES = |
89 |
[{ |
90 |
id: 33, |
91 |
name: 'Snapshot-1', |
92 |
status: 'running' |
93 |
}, |
94 |
{ |
95 |
id: 44, |
96 |
name: 'Snapshot-2', |
97 |
status: 'building' |
98 |
}]; |
99 |
|
100 |
|
101 |
Synnefo.UserImage = DS.Model.extend({ |
102 |
name: DS.attr('string'), |
103 |
status: DS.attr('string'), |
104 |
}); |
105 |
|
106 |
Synnefo.UserImage.FIXTURES = |
107 |
[{ |
108 |
id: 55, |
109 |
name: 'Image-1', |
110 |
status: 'running' |
111 |
}, |
112 |
{ |
113 |
id: 66, |
114 |
name: 'Image-2', |
115 |
status: 'running' |
116 |
}]; |
117 |
|
118 |
|
119 |
Synnefo.conf = { |
120 |
sectors: [{
|
121 |
destination: "vms", |
122 |
title: "Virtual Machines", |
123 |
icon: "snf-pc-outline" |
124 |
}, |
125 |
{ |
126 |
destination: "networks", |
127 |
title: "Network", |
128 |
icon: "snf-network-outline" |
129 |
|
130 |
}, |
131 |
{ |
132 |
destination: "volumes", |
133 |
title: "Volumes", |
134 |
icon: "snf-volume-outline" |
135 |
}, |
136 |
{ |
137 |
destination: "pithos", |
138 |
title: "Pithos", |
139 |
icon: "snf-pithos-outline" |
140 |
}, |
141 |
{ |
142 |
destination: "images", |
143 |
title: "Images", |
144 |
icon: "snf-image-outline" |
145 |
}, |
146 |
{ |
147 |
destination: "snapshots", |
148 |
title: "Snapshots", |
149 |
icon: "snf-snapshot-outline" |
150 |
}, |
151 |
{ |
152 |
destination: "ips", |
153 |
title: "IPs", |
154 |
icon: "snf-nic-outline" |
155 |
}, |
156 |
{ |
157 |
destination: "sshkeys", |
158 |
title: "SSh Keys", |
159 |
icon: "snf-key-outline" |
160 |
}], |
161 |
|
162 |
userActions: [{
|
163 |
description:'start', |
164 |
'snf-components':['vms'], |
165 |
'enabled-status': ['off'], |
166 |
action: 'is this a function?' |
167 |
}, |
168 |
{ |
169 |
description:'destroyElement', |
170 |
'snf-components': ['vms', 'networks'], |
171 |
'enabled-status': ['all'], |
172 |
action: 'is this a function?', |
173 |
}, |
174 |
{ |
175 |
description:'shutdown', |
176 |
'snf-components': ['vms'], |
177 |
'enabled-status': ['running'], |
178 |
action: 'is this a function?' |
179 |
}, |
180 |
{ |
181 |
description:'add machine', |
182 |
'snf-components': ['networks'], |
183 |
'enabled-status': ['active'], |
184 |
action: 'is this a function?' |
185 |
}, |
186 |
{ |
187 |
description:'action for all', |
188 |
'snf-components': ['vms', 'networks'], |
189 |
'enabled-status': ['all'], |
190 |
action: 'is this a function?' |
191 |
}] |
192 |
}; |
193 |
|
194 |
Synnefo.wizards = { |
195 |
vmWizard: {
|
196 |
// each step must have a headline
|
197 |
stepsHeadlines: [
|
198 |
{ |
199 |
title:'Select an OS', |
200 |
subtitle:'Choose your preferred image' |
201 |
}, |
202 |
{ |
203 |
title:'Select CPUs, RAM and Disk Size', |
204 |
subtitle:'Available options are filtered based on the selected image' |
205 |
}, |
206 |
{ |
207 |
title:'Virtual machine custom options', |
208 |
subtitle:'tba' |
209 |
}, |
210 |
{ |
211 |
title:'Confirm your settings', |
212 |
subtitle:'Confirm that the options you have selected are correct' |
213 |
}, |
214 |
], |
215 |
stepsSubmenus: [
|
216 |
{ |
217 |
options:['System', 'My images', 'Shared with me', 'Public'] |
218 |
}, |
219 |
{ |
220 |
options: ['Small', 'Medium', 'large'] |
221 |
} |
222 |
], |
223 |
stepsContent: ['step-1', 'step-2', 'step-3', 'step-4'] |
224 |
}, |
225 |
networkWizard: {}
|
226 |
};/* Mapping */
|
227 |
|
228 |
Synnefo.Router.map(function() {
|
229 |
// I defined the above resource to extend its Route
|
230 |
this.resource('sections', {'path':'/'}); |
231 |
for(var i=0; i<Synnefo.conf.sectors.length; i++) |
232 |
this.resource(Synnefo.conf.sectors[i].destination, function() { |
233 |
// this.route('grid');
|
234 |
// this.route('list');
|
235 |
this.route('create'); |
236 |
}); |
237 |
}); |
238 |
|
239 |
|
240 |
/* Routes */
|
241 |
|
242 |
Synnefo.ApplicationRoute = Ember.Route.extend({ |
243 |
model: function() { |
244 |
return {email: 'athina@mail.com'}; |
245 |
}, |
246 |
redirect: function() { |
247 |
// have to set vm navigation icon full
|
248 |
this.transitionTo('vms'); |
249 |
}, |
250 |
}); |
251 |
|
252 |
|
253 |
/* Items Routes */
|
254 |
|
255 |
Synnefo.SectionsRoute = Ember.Route.extend({ |
256 |
modelName: undefined, |
257 |
model: function() { |
258 |
return this.store.find(this.modelName); |
259 |
}, |
260 |
renderTemplate: function(controller) { |
261 |
this.render('snfElems', {controller: controller}); |
262 |
}, |
263 |
actions: {
|
264 |
openWizard: function() { |
265 |
var wizardType = this.routeName; |
266 |
this.transitionTo(wizardType+'.create') |
267 |
} |
268 |
} |
269 |
}); |
270 |
|
271 |
|
272 |
Synnefo.VmsRoute = Synnefo.SectionsRoute.extend({ |
273 |
modelName: 'vm' |
274 |
}); |
275 |
|
276 |
Synnefo.NetworksRoute = Synnefo.SectionsRoute.extend({ |
277 |
modelName: 'network' |
278 |
}); |
279 |
|
280 |
Synnefo.VolumesRoute = Synnefo.SectionsRoute.extend({ |
281 |
modelName: 'volume' |
282 |
}); |
283 |
|
284 |
Synnefo.SnapshotsRoute = Synnefo.SectionsRoute.extend({ |
285 |
modelName: 'snapshot' |
286 |
}); |
287 |
|
288 |
Synnefo.ImagesRoute = Synnefo.SectionsRoute.extend({ |
289 |
modelName: 'userImage' |
290 |
}); |
291 |
|
292 |
|
293 |
/* Wizards Routes */
|
294 |
|
295 |
Synnefo.CreateRoute = Ember.Route.extend({ |
296 |
model: function(){ |
297 |
return [{name: 'vm-wizard'}] |
298 |
}, |
299 |
renderTemplate: function(controller) { |
300 |
this.render('wizard',{controller: controller}); |
301 |
}, |
302 |
/* beforeModel: function() {
|
303 |
this._super();
|
304 |
console.log('beforeModel ',this.get('router.url'))
|
305 |
this.previousRoute = this.get('router.url'); // should return the current path but some times it returns the path where the user was before (when i dont type the url of the wizard)
|
306 |
},
|
307 |
previousRoute: undefined,*/
|
308 |
actions: {
|
309 |
closeWizard: function() { |
310 |
history.back(); |
311 |
} |
312 |
} |
313 |
}); |
314 |
|
315 |
Synnefo.VmsCreateRoute = Synnefo.CreateRoute.extend({ |
316 |
model: function() { |
317 |
return Synnefo.wizards.vmWizard;
|
318 |
} |
319 |
}); |
320 |
|
321 |
Synnefo.NetworksCreateRoute = Synnefo.CreateRoute.extend(); |
322 |
|
323 |
Synnefo.VolumesCreateRoute = Synnefo.CreateRoute.extend(); |
324 |
|
325 |
Synnefo.SnapshotsCreateRoute = Synnefo.CreateRoute.extend(); |
326 |
|
327 |
Synnefo.ImagesCreateRoute = Synnefo.CreateRoute.extend({});;/* Controllers */
|
328 |
|
329 |
Synnefo.ApplicationController = Ember.Controller.extend({ |
330 |
updateCurrentPath: function() { |
331 |
// we need the set because ElemsController gets the value of current path in every transition
|
332 |
Synnefo.set('currentPath', this.get('currentPath')) |
333 |
return this.get('currentPath'); |
334 |
}.observes('currentPath'),
|
335 |
|
336 |
pageTitle : function() { |
337 |
var currentPath =this.get('currentPath'); |
338 |
if(currentPath!== 'index') return Synnefo.conf.sectors.findBy('destination', this.get('currentPath')).title; |
339 |
else return 'Home'; |
340 |
}.property('currentPath'),
|
341 |
|
342 |
// name: "okeanos application",
|
343 |
}); |
344 |
|
345 |
|
346 |
/* Items Controllers */
|
347 |
|
348 |
Synnefo.ElemsController = Ember.ArrayController.extend({ |
349 |
type: undefined, |
350 |
itemController: function(){ |
351 |
var type = this.type; |
352 |
return type.substring(0, type.length - 1); |
353 |
}.property(), |
354 |
icon: function() { |
355 |
// should this be placed in ElemsView?
|
356 |
return Synnefo.conf.sectors.findBy('destination', this.get('type')).icon.replace('outline', 'full'); |
357 |
}.property(), |
358 |
hasOS: function(){ |
359 |
if(Synnefo.get('currentPath') === "vms" || Synnefo.get('currentPath') === "vms.index") |
360 |
return true; |
361 |
else return false; |
362 |
}.property(), |
363 |
hasTags: function(){ |
364 |
if(Synnefo.get('currentPath') == "vms" || Synnefo.get('currentPath') === "vms.index") |
365 |
return true; |
366 |
else return false; |
367 |
}.property(), |
368 |
}); |
369 |
|
370 |
Synnefo.VmsController = Synnefo.ElemsController.extend({ |
371 |
type: 'vms' |
372 |
}); |
373 |
|
374 |
|
375 |
Synnefo.NetworksController = Synnefo.ElemsController.extend({ |
376 |
type: 'networks' |
377 |
}); |
378 |
|
379 |
Synnefo.VolumesController = Synnefo.ElemsController.extend({ |
380 |
type: 'volumes' |
381 |
}); |
382 |
|
383 |
|
384 |
Synnefo.SnapshotsController = Synnefo.ElemsController.extend({ |
385 |
type: 'snapshots' |
386 |
}); |
387 |
|
388 |
Synnefo.ImagesController = Synnefo.ElemsController.extend({ |
389 |
type: 'images' |
390 |
}); |
391 |
|
392 |
|
393 |
/* Controllers for each Item */
|
394 |
|
395 |
Synnefo.ElemController = Ember.ObjectController.extend({ |
396 |
needs: [],
|
397 |
actionsList: Synnefo.conf.userActions,
|
398 |
setAvailableActions: function() { |
399 |
var parent = this.needs; |
400 |
var self = this; |
401 |
return this.actionsList.filter(function(el) { |
402 |
return _.contains(el['snf-components'], self.get('controllers.'+parent).type) &&( _.contains(el['enabled-status'], self.get('model.status')) || _.contains(el['enabled-status'], 'all')); |
403 |
}) |
404 |
}.property(), |
405 |
createBtn: false, |
406 |
actions: {
|
407 |
shutdown: function(param) { |
408 |
this.set('model.status', 'shutting'); |
409 |
}, |
410 |
destroyElement: function(param) { |
411 |
var element = this.get('model'); |
412 |
element.deleteRecord(); |
413 |
element.save(); |
414 |
} |
415 |
} |
416 |
}); |
417 |
|
418 |
Synnefo.VmController = Synnefo.ElemController.extend({ |
419 |
needs: ['vms'] |
420 |
}); |
421 |
|
422 |
Synnefo.NetworkController = Synnefo.ElemController.extend({ |
423 |
needs: ['networks'] |
424 |
}); |
425 |
|
426 |
Synnefo.VolumeController = Synnefo.ElemController.extend({ |
427 |
needs: ['volumes'] |
428 |
}); |
429 |
|
430 |
Synnefo.SnapshotController = Synnefo.ElemController.extend({ |
431 |
needs: ['snapshots'] |
432 |
}); |
433 |
|
434 |
Synnefo.ImageController = Synnefo.ElemController.extend({ |
435 |
needs: ['images'] |
436 |
}); |
437 |
|
438 |
|
439 |
/* Controllers for Wizards */
|
440 |
|
441 |
Synnefo.CreateController = Ember.ObjectController.extend({ |
442 |
currentStep: undefined, |
443 |
|
444 |
totalStep: function() { |
445 |
return this.get('stepsContent').length; |
446 |
}.property(), |
447 |
|
448 |
init: function() { |
449 |
this._super();
|
450 |
this.set('currentStep', 1) |
451 |
}, |
452 |
btnLeftLabel: function(){ |
453 |
return (this.get('currentStep') === 1)?'CANCEL':'PREVIOUS'; |
454 |
}.property('currentStep'),
|
455 |
|
456 |
btnRightLabel: function(){ |
457 |
return (this.get('currentStep') === this.get('totalStep'))?'CREATE':'NEXT'; |
458 |
}.property('currentStep'),
|
459 |
|
460 |
actions: {
|
461 |
moveNext: function() { |
462 |
var step = this.get('currentStep'); |
463 |
|
464 |
if(step!== this.get('totalStep')) { |
465 |
step++; |
466 |
this.set('currentStep', step); |
467 |
} |
468 |
else
|
469 |
this.get('target').send('closeWizard'); |
470 |
}, |
471 |
moveBack: function() { |
472 |
var step = this.get('currentStep'); |
473 |
|
474 |
if(step === 1) { |
475 |
this.get('target').send('closeWizard'); |
476 |
} |
477 |
else {
|
478 |
step--; |
479 |
this.set('currentStep', step); |
480 |
} |
481 |
} |
482 |
}, |
483 |
|
484 |
}); |
485 |
|
486 |
Synnefo.VmsCreateController =Synnefo.CreateController.extend(); |
487 |
; |
488 |
/* Views */
|
489 |
|
490 |
Synnefo.ApplicationView = Ember.View.extend({ |
491 |
classNames: ['content'] |
492 |
}); |
493 |
|
494 |
|
495 |
/* Navigation Menu */
|
496 |
|
497 |
Synnefo.NavIconView = Ember.View.extend({ |
498 |
tagName: 'span', |
499 |
click: function() { |
500 |
var parentEl = this.$().parent('a'); |
501 |
var currentEl = this.$().parents('li').siblings('li').find('a.current'); |
502 |
|
503 |
ui.replaceClass(currentEl, 'full', 'outline', 'snf-'); |
504 |
ui.replaceClass(parentEl, 'outline', 'full', 'snf-'); |
505 |
} |
506 |
|
507 |
}); |
508 |
|
509 |
Synnefo.NavigationView = Ember.CollectionView.extend({ |
510 |
tagName: "ul", |
511 |
classNames: ['icons-nav'], |
512 |
|
513 |
content: Synnefo.conf.sectors,
|
514 |
itemViewClass: Ember.View.extend({
|
515 |
templateName: "navigationItem" |
516 |
}), |
517 |
}); |
518 |
|
519 |
|
520 |
/* Items Parts */
|
521 |
|
522 |
Synnefo.ElemView = Ember.View.extend({ |
523 |
// templateName: 'elem',
|
524 |
addNewBtn: false, |
525 |
templateName: 'snfElem', |
526 |
tagName: 'li', |
527 |
selectable: true, |
528 |
initSelect: 'unchecked', |
529 |
classNameBindings: ['status'], |
530 |
attributeBindings: ['data-status'], |
531 |
'data-status': function() { |
532 |
return this.status; |
533 |
}.property(), |
534 |
status: function() { |
535 |
return this.get('controller.status'); |
536 |
}.property('controller.status')
|
537 |
}); |
538 |
|
539 |
Synnefo.ImgWrapView = Ember.View.extend({ |
540 |
templateName: 'img-wrap', |
541 |
classNames: ['img-wrap'], |
542 |
icon: function() { |
543 |
var parentView = this.get('parentView'); |
544 |
var addNewBtn = parentView.get('addNewBtn'); |
545 |
if(addNewBtn)
|
546 |
return parentView.get('icon'); |
547 |
else
|
548 |
return parentView.get('controller').get('parentController').get('icon'); |
549 |
}.property() |
550 |
}); |
551 |
|
552 |
Synnefo.LabelNameView = Ember.View.extend({ |
553 |
templateName: 'name', |
554 |
tagName: 'h4', |
555 |
name: function() { |
556 |
// the name may be defined inside the parent view or in its model or controller
|
557 |
return this.get('parentView').get('controller').get('name'); |
558 |
}.property() |
559 |
}); |
560 |
|
561 |
// to be changed
|
562 |
Synnefo.ImmediateActionView = Ember.View.extend({ |
563 |
templateName: 'actions', |
564 |
classNames: ['actions'] |
565 |
}); |
566 |
|
567 |
|
568 |
/* Wizard */
|
569 |
|
570 |
Synnefo.CollectionView = Ember.CollectionView.extend({ |
571 |
counter: 0 |
572 |
}); |
573 |
|
574 |
// to use (extend) Synnefo.CollectionItemView must a counter to be set (initialized) in the parent view
|
575 |
// so when we want to use Synnefo.CollectionItemView, the collection that includes has extend Synnefo.CollectionView
|
576 |
Synnefo.CollectionItemView = Ember.View.extend({ |
577 |
// classNameBindings: ['isCurrent:current::', 'isFirst:preselected', 'isPast:past::'],
|
578 |
index: undefined, |
579 |
isCurrent: false, |
580 |
isFirst: false, |
581 |
init: function() { |
582 |
this._super();
|
583 |
var prevIndex = this.get('parentView').get('counter'); |
584 |
var index = ++prevIndex;
|
585 |
this.get('parentView').set('counter', index); |
586 |
this.set('index', index); |
587 |
if(index === 1) { |
588 |
this.set('isFirst', true); |
589 |
} |
590 |
}, |
591 |
isCurrent: function() { |
592 |
return this.index === this.get('controller').get('currentStep'); |
593 |
}.property('controller.currentStep'),
|
594 |
isPast: function() { |
595 |
return this.index < this.get('controller').get('currentStep'); |
596 |
}.property('controller.currentStep')
|
597 |
}); |
598 |
|
599 |
|
600 |
Synnefo.WizardHeadersView = Synnefo.CollectionView.extend({ |
601 |
tagName: 'ul', |
602 |
classNames:['nums'], |
603 |
content: Synnefo.wizards.vmWizard.stepsHeadlines,
|
604 |
itemViewClass: Synnefo.CollectionItemView.extend({
|
605 |
classNameBindings: ['isCurrent:current::', 'isFirst:preselected', 'isPast:past::'], |
606 |
templateName: 'wizardStepHeader', |
607 |
}) |
608 |
}); |
609 |
|
610 |
Synnefo.WizardSubMenusView = Synnefo.CollectionView.extend({ |
611 |
classNames: ['row', 'menus'], |
612 |
content: Synnefo.wizards.vmWizard.stepsSubmenus,
|
613 |
itemViewClass: Synnefo.CollectionItemView.extend({
|
614 |
tagName: 'nav', |
615 |
classNames: ['sub-menu'], |
616 |
classNameBindings: ['isCurrent:current::', 'isFirst:preselected', 'isPast:past::'], |
617 |
templateName: 'submenu' |
618 |
}) |
619 |
|
620 |
}); |
621 |
|
622 |
Synnefo.WizardSubMenuView = Synnefo.CollectionView.extend({ |
623 |
tagName: 'ul', |
624 |
content: function() { |
625 |
var stepIndex = this.get('parentView').get('index'); |
626 |
return Synnefo.wizards.vmWizard.stepsSubmenus[--stepIndex].options;
|
627 |
}.property(), |
628 |
removeOtherCurrent: function(clickedView) { |
629 |
var childViews = this._childViews; |
630 |
|
631 |
for(var i=0; i<childViews.length; i++) |
632 |
if(childViews[i] !== clickedView)
|
633 |
childViews[i].set('isCurrent', false); |
634 |
}, |
635 |
itemViewClass: Synnefo.CollectionItemView.extend({
|
636 |
templateName: 'menuOption', |
637 |
classNameBindings:['isCurrent:current::', 'isFirst:preselected'], |
638 |
isCurrent: function(){ |
639 |
if(this.get('isFirst')) return true; |
640 |
}.property(), |
641 |
click: function() { |
642 |
this.get('parentView').removeOtherCurrent(this); |
643 |
this.set('isCurrent', true) |
644 |
} |
645 |
}) |
646 |
}); |
647 |
|
648 |
|
649 |
// The only buttons that are views are the buttons that move the wizard
|
650 |
// The reason is that they shouldn't be isolated from the surrounding
|
651 |
// (Their labels changes depanding the current step)
|
652 |
Synnefo.WizardBtnBackView = Ember.View.extend({ |
653 |
classNames: ['nav', 'prev'], |
654 |
tagName: 'a', |
655 |
templateName: 'components/btns-span', |
656 |
content: function(){ |
657 |
return this.get('controller').get('btnLeftLabel'); |
658 |
}.property('controller.btnLeftLabel'),
|
659 |
click: function() { |
660 |
this.get('controller').send('moveBack'); |
661 |
} |
662 |
}); |
663 |
|
664 |
Synnefo.WizardBtnNextView = Ember.View.extend({ |
665 |
classNames: ['nav', 'next'], |
666 |
tagName: 'a', |
667 |
templateName: 'components/btns-span', |
668 |
content: function(){ |
669 |
return this.get('controller').get('btnRightLabel'); |
670 |
}.property('controller.btnRightLabel'),
|
671 |
click: function() { |
672 |
this.get('controller').send('moveNext'); |
673 |
} |
674 |
}); |
675 |
;/* Components */
|
676 |
|
677 |
Synnefo.Btn1Component = Ember.Component.extend({ |
678 |
tagName: 'a', |
679 |
click: function() { |
680 |
this.sendAction("action", this.get('param')); |
681 |
}, |
682 |
content: undefined // will be set if we want to print a message inside the span |
683 |
}); |
684 |
|
685 |
Synnefo.BtnsSpanComponent = Ember.Component.extend({ |
686 |
tagName: 'a', |
687 |
templateName: 'components/btns-span', |
688 |
click: function() { |
689 |
this.sendAction("action"); |
690 |
} |
691 |
}); |
692 |
|
693 |
|
694 |
|
695 |
/* Add New Item */
|
696 |
|
697 |
Synnefo.AddNewComponent = Ember.Component.extend({ |
698 |
templateName: 'snfElem', |
699 |
addNewBtn: true, |
700 |
selectable: false, |
701 |
icon: function() { |
702 |
baseIcon = Synnefo.conf.sectors.findBy('destination', this.get('type')).icon; |
703 |
return baseIcon.replace('outline', 'create-full'); |
704 |
}.property(), |
705 |
tagName: 'li', |
706 |
status: 'add-new', |
707 |
classNameBindings: ['status'], |
708 |
attributeBindings: ['data-status, data-reveal-id'], |
709 |
'data-reveal-id': function(){ |
710 |
if(addNewBtn)
|
711 |
return /*this.get('type').substring(0, type.length - 1)+*/'-wizard'; |
712 |
else
|
713 |
return undefined; |
714 |
}.property(), |
715 |
'data-status': function() { |
716 |
return this.status; |
717 |
}.property(), |
718 |
name: function() { |
719 |
var msg = 'Create New '; |
720 |
var btnType = this.get('type') |
721 |
switch(btnType){
|
722 |
case 'vms': |
723 |
return msg + 'Machine'; |
724 |
case 'networks': |
725 |
return msg + 'Network'; |
726 |
case 'volumes': |
727 |
return msg + 'Volume'; |
728 |
case 'snapshots': |
729 |
return msg + 'Snapshot'; |
730 |
case 'images': |
731 |
return '+ Upload New Image'; |
732 |
} |
733 |
}.property(), |
734 |
click: function () { |
735 |
this.sendAction('action'); |
736 |
} |
737 |
}); |
738 |
|
739 |
|
740 |
/* Login Menu */
|
741 |
|
742 |
Synnefo.LoginMenuComponent = Ember.Component.extend({ |
743 |
classNames: ['login'], |
744 |
didInsertElement: function() { |
745 |
var self = this.$(); |
746 |
self.mouseenter(function(e){
|
747 |
self.find('ul').stop(true, true).slideDown(200); |
748 |
}); |
749 |
self.mouseleave(function(e){
|
750 |
self.find('ul').stop(true, true).slideUp(200); |
751 |
}); |
752 |
|
753 |
} |
754 |
}); |
755 |
|
756 |
|
757 |
/* Checkboxes and Radiobuttons */
|
758 |
|
759 |
Synnefo.SnfCheckboxComponent = Ember.Component.extend({ |
760 |
tagName: 'a', |
761 |
classNames: ['check'], |
762 |
templateName: 'components/select-btn', |
763 |
initState: function() { |
764 |
return this.get('initState'); |
765 |
}.property(), |
766 |
didInsertElement: function() { |
767 |
var el = this.$(); |
768 |
var self =this; |
769 |
this.setInitClasses();
|
770 |
el.click(function(e) {
|
771 |
e.preventDefault(); |
772 |
e.stopPropagation(); |
773 |
self.changeState(el); |
774 |
// ui.entitiesActionsEnabled();
|
775 |
}); |
776 |
}, |
777 |
setInitClasses: function() { |
778 |
var self =this.$(); |
779 |
switch(this.initState){ |
780 |
case 'unchecked': { |
781 |
this.uncheck(self);
|
782 |
break;
|
783 |
} |
784 |
case 'prechecked': { |
785 |
self.find('span').addClass('prechecked') |
786 |
this.check(self);
|
787 |
break;
|
788 |
} |
789 |
} |
790 |
}, |
791 |
// used to be in ui.checkbox
|
792 |
changeState : function(checkbox_link) { |
793 |
$(checkbox_link).find('.snf-checkbox-unchecked, .snf-checkbox-checked').toggleClass('snf-checkbox-unchecked snf-checkbox-checked'); |
794 |
$(checkbox_link).closest('li').toggleClass('selected'); |
795 |
}, |
796 |
check : function(checkbox_link) { |
797 |
$(checkbox_link).find('span').removeClass('snf-checkbox-unchecked').addClass('snf-checkbox-checked'); |
798 |
$(checkbox_link).closest('li').addClass('selected'); |
799 |
}, |
800 |
uncheck : function(checkbox_link) { |
801 |
$(checkbox_link).find('span').removeClass('snf-checkbox-checked').addClass('snf-checkbox-unchecked'); |
802 |
$(checkbox_link).closest('li').removeClass('selected'); |
803 |
}, |
804 |
|
805 |
reset: function(area) { |
806 |
$(area).find('.snf-radio-checked').not('.prechecked').toggleClass('snf-radio-checked snf-radio-unchecked'); |
807 |
$(area).find('.snf-radio-unchecked.prechecked').toggleClass('snf-radio-checked snf-radio-unchecked'); |
808 |
}, |
809 |
}); |
810 |
|
811 |
|
812 |
/* Wizard Buttons */
|
813 |
|
814 |
Synnefo.Close1Component = Synnefo.BtnsSpanComponent.extend({ |
815 |
classNames: ['close'], |
816 |
spanClass: 'snf-close' // has to be modified to array of strings |
817 |
}); |
818 |
|
819 |
// there's another close icon to confirm/info modals
|
820 |
|
821 |
|
822 |
/*
|
823 |
|
824 |
Back and Next buttons are constructed as views and not as components
|
825 |
|
826 |
{{cancel-1 action="moveBack" step=currentStep minStep=1}}
|
827 |
{{next-1 action="moveNext" step=currentStep maxStep=totalStep}}
|
828 |
|
829 |
Synnefo.Cancel1Component = Synnefo.BtnsSpanComponent.extend({
|
830 |
// classNameBindings: ['el3'], the element that should be focused when the user goes to the next step
|
831 |
content: 'CANCEL',
|
832 |
click: function(){
|
833 |
var currentStep =this.get('step');
|
834 |
var minStep =this.get('minStep');
|
835 |
console.log('minStep ', minStep);
|
836 |
this.sendAction();
|
837 |
if(currentStep === minStep)
|
838 |
this.set('content', 'CANCEL');
|
839 |
else
|
840 |
this.set('content', 'PREVIOUS');
|
841 |
|
842 |
}
|
843 |
|
844 |
// there's another close to modals
|
845 |
|
846 |
Synnefo.Cancel1Component = Synnefo.BtnsSpanComponent.extend({
|
847 |
classNames: ['nav', 'prev'],
|
848 |
// classNameBindings: ['el3'], the element that should be focused when the user goes to the next step
|
849 |
content: 'CANCEL'
|
850 |
});
|
851 |
|
852 |
Synnefo.Next1Component = Synnefo.BtnsSpanComponent.extend({
|
853 |
classNames: ['nav', 'next'],
|
854 |
// classNameBindings: ['el3'], the element that should be focused when the user goes to the next step
|
855 |
content: 'NEXT',
|
856 |
click: function() {
|
857 |
var currentStep =this.get('step');
|
858 |
var maxStep =this.get('maxStep');
|
859 |
this.sendAction('action');
|
860 |
if(currentStep === maxStep)
|
861 |
this.set('content', 'CREATE');
|
862 |
else
|
863 |
this.set('content', 'NEXT');
|
864 |
}
|
865 |
}); */
|