root / snf-cyclades-app / synnefo / ui / new_ui / ui / javascripts / okeanos-ember / ember-all.js @ 812b1e8d
History | View | Annotate | Download (9.3 kB)
1 |
/* Mapping */
|
---|---|
2 |
|
3 |
Synnefo.Router.map(function() {
|
4 |
// I defined the above resource to extend its Route
|
5 |
this.resource('sections', {'path':'/'}); |
6 |
for(var i=0; i<Synnefo.conf.sectors.length; i++) |
7 |
this.resource(Synnefo.conf.sectors[i].destination/*, function() { |
8 |
this.route('grid');
|
9 |
this.route('list');
|
10 |
}*/);
|
11 |
}); |
12 |
|
13 |
|
14 |
/* Routes */
|
15 |
|
16 |
Synnefo.ApplicationRoute = Ember.Route.extend({ |
17 |
model: function() { |
18 |
return {email: 'athina@mail.com'}; |
19 |
}, |
20 |
redirect: function() { |
21 |
// have to set vm navigation icon full
|
22 |
this.transitionTo('vms'); |
23 |
}, |
24 |
actions: {
|
25 |
openWizard: function() { |
26 |
console.log('2');
|
27 |
return this.render('wizard', { |
28 |
into: 'application', |
29 |
outlet: 'wizard' |
30 |
}); |
31 |
} |
32 |
} |
33 |
}); |
34 |
|
35 |
Synnefo.SectionsRoute = Ember.Route.extend({ |
36 |
modelName: undefined, |
37 |
model: function() { |
38 |
return this.store.find(this.modelName); |
39 |
}, |
40 |
renderTemplate: function(controller) { |
41 |
this.render('snfElems', {controller: controller}); |
42 |
} |
43 |
}); |
44 |
|
45 |
|
46 |
Synnefo.VmsRoute = Synnefo.SectionsRoute.extend({ |
47 |
modelName: 'vm' |
48 |
}); |
49 |
|
50 |
Synnefo.NetworksRoute = Synnefo.SectionsRoute.extend({ |
51 |
modelName: 'network' |
52 |
}); |
53 |
|
54 |
Synnefo.VolumesRoute = Synnefo.SectionsRoute.extend({ |
55 |
modelName: 'volume' |
56 |
}); |
57 |
|
58 |
Synnefo.SnapshotsRoute = Synnefo.SectionsRoute.extend({ |
59 |
modelName: 'snapshot' |
60 |
}); |
61 |
|
62 |
Synnefo.ImagesRoute = Synnefo.SectionsRoute.extend({ |
63 |
modelName: 'userImage' |
64 |
}); |
65 |
|
66 |
|
67 |
|
68 |
|
69 |
|
70 |
/* Controllers */
|
71 |
|
72 |
Synnefo.ApplicationController = Ember.Controller.extend({ |
73 |
updateCurrentPath: function() { |
74 |
// we need the set because ElemsController gets the value of current path in every transition
|
75 |
Synnefo.set('currentPath', this.get('currentPath')) |
76 |
return this.get('currentPath'); |
77 |
}.observes('currentPath'),
|
78 |
actions: {
|
79 |
test: function() { |
80 |
console.log('This is test from Synnefo.ApplicationController');
|
81 |
return 0; |
82 |
} |
83 |
}, |
84 |
|
85 |
pageTitle : function() { |
86 |
var currentPath =this.get('currentPath'); |
87 |
if(currentPath!== 'index') return Synnefo.conf.sectors.findBy('destination', this.get('currentPath')).title; |
88 |
else return 'Home'; |
89 |
}.property('currentPath'),
|
90 |
|
91 |
// name: "okeanos application",
|
92 |
}); |
93 |
|
94 |
|
95 |
|
96 |
Synnefo.ElemsController = Ember.ArrayController.extend({ |
97 |
type: undefined, |
98 |
itemController: function(){ |
99 |
var type = this.type; |
100 |
return type.substring(0, type.length - 1); |
101 |
}.property(), |
102 |
icon: function() { |
103 |
// should this be placed in ElemsView?
|
104 |
return Synnefo.conf.sectors.findBy('destination', this.get('type')).icon.replace('outline', 'full'); |
105 |
}.property(), |
106 |
hasOS: function(){ |
107 |
if(Synnefo.get('currentPath') == "vms") |
108 |
return true; |
109 |
else return false; |
110 |
}.property(), |
111 |
hasTags: function(){ |
112 |
if(Synnefo.get('currentPath') == "vms") |
113 |
return true; |
114 |
else return false; |
115 |
}.property(), |
116 |
}); |
117 |
|
118 |
Synnefo.VmsController = Synnefo.ElemsController.extend({ |
119 |
type: 'vms' |
120 |
}); |
121 |
|
122 |
|
123 |
Synnefo.NetworksController = Synnefo.ElemsController.extend({ |
124 |
type: 'networks' |
125 |
}); |
126 |
|
127 |
Synnefo.VolumesController = Synnefo.ElemsController.extend({ |
128 |
type: 'volumes' |
129 |
}); |
130 |
|
131 |
|
132 |
Synnefo.SnapshotsController = Synnefo.ElemsController.extend({ |
133 |
type: 'snapshots' |
134 |
}); |
135 |
|
136 |
Synnefo.ImagesController = Synnefo.ElemsController.extend({ |
137 |
type: 'images' |
138 |
}); |
139 |
|
140 |
|
141 |
|
142 |
Synnefo.ElemController = Ember.ObjectController.extend({ |
143 |
needs: [],
|
144 |
actionsList: Synnefo.conf.userActions,
|
145 |
setAvailableActions: function() { |
146 |
var parent = this.needs; |
147 |
var self = this; |
148 |
return this.actionsList.filter(function(el) { |
149 |
return _.contains(el['snf-components'], self.get('controllers.'+parent).type) &&( _.contains(el['enabled-status'], self.get('model.status')) || _.contains(el['enabled-status'], 'all')); |
150 |
}) |
151 |
}.property(), |
152 |
createBtn: false, |
153 |
actions: {
|
154 |
shutdown: function(param) { |
155 |
console.log(this.get('model.status')); |
156 |
this.set('model.status', 'shutting'); |
157 |
}, |
158 |
destroyElement: function(param) { |
159 |
var element = this.get('model'); |
160 |
element.deleteRecord(); |
161 |
element.save(); |
162 |
} |
163 |
} |
164 |
}); |
165 |
|
166 |
Synnefo.VmController = Synnefo.ElemController.extend({ |
167 |
needs: ['vms'] |
168 |
}); |
169 |
|
170 |
Synnefo.NetworkController = Synnefo.ElemController.extend({ |
171 |
needs: ['networks'] |
172 |
}); |
173 |
|
174 |
Synnefo.VolumeController = Synnefo.ElemController.extend({ |
175 |
needs: ['volumes'] |
176 |
}); |
177 |
|
178 |
Synnefo.SnapshotController = Synnefo.ElemController.extend({ |
179 |
needs: ['snapshots'] |
180 |
}); |
181 |
|
182 |
Synnefo.ImageController = Synnefo.ElemController.extend({ |
183 |
needs: ['images'] |
184 |
}); |
185 |
|
186 |
|
187 |
/* Views */
|
188 |
|
189 |
Synnefo.NavIconView = Ember.View.extend({ |
190 |
tagName: 'span', |
191 |
click: function(e) { |
192 |
var parentEl = this.$().parent('a'); |
193 |
var currentEl = this.$().parents('li').siblings('li').find('a.current'); |
194 |
|
195 |
ui.replaceClass(currentEl, 'full', 'outline', 'snf-'); |
196 |
ui.replaceClass(parentEl, 'outline', 'full', 'snf-'); |
197 |
} |
198 |
|
199 |
}); |
200 |
|
201 |
Synnefo.NavigationView = Ember.CollectionView.extend({ |
202 |
tagName: "ul", |
203 |
classNames: ['icons-nav'], |
204 |
|
205 |
content: Synnefo.conf.sectors,
|
206 |
itemViewClass: Ember.View.extend({
|
207 |
templateName: "navigationItem" |
208 |
}), |
209 |
}); |
210 |
|
211 |
|
212 |
Synnefo.ElemView = Ember.View.extend({ |
213 |
// templateName: 'elem',
|
214 |
addNewBtn: false, |
215 |
templateName: 'snfElem', |
216 |
tagName: 'li', |
217 |
selectable: true, |
218 |
initSelect: 'unchecked', |
219 |
classNameBindings: ['status'], |
220 |
attributeBindings: ['data-status'], |
221 |
'data-status': function() { |
222 |
return this.status; |
223 |
}.property(), |
224 |
status: function() { |
225 |
return this.get('controller.status'); |
226 |
}.property('controller.status')
|
227 |
}); |
228 |
|
229 |
Synnefo.ImgWrapView = Ember.View.extend({ |
230 |
templateName: 'img-wrap', |
231 |
classNames: ['img-wrap'], |
232 |
icon: function() { |
233 |
var parentView = this.get('parentView'); |
234 |
var addNewBtn = parentView.get('addNewBtn'); |
235 |
if(addNewBtn)
|
236 |
return parentView.get('icon'); |
237 |
else
|
238 |
return parentView.get('controller').get('parentController').get('icon'); |
239 |
}.property() |
240 |
}); |
241 |
|
242 |
Synnefo.NameView = Ember.View.extend({ |
243 |
templateName: 'name', |
244 |
tagName: 'h4', |
245 |
name: function() { |
246 |
// the name may be defined inside the parent view or in its model or controller
|
247 |
return this.get('parentView').get('controller').get('name'); |
248 |
}.property() |
249 |
}); |
250 |
|
251 |
// to be changed
|
252 |
Synnefo.ImmediateActionView = Ember.View.extend({ |
253 |
templateName: 'actions', |
254 |
classNames: ['actions'] |
255 |
}) |
256 |
|
257 |
/* Components */
|
258 |
|
259 |
Synnefo.Btn1Component = Ember.Component.extend({ |
260 |
tagName: 'a', |
261 |
click: function() { |
262 |
this.sendAction("action", this.get('param')); |
263 |
} |
264 |
}); |
265 |
|
266 |
Synnefo.AddNewComponent = Ember.Component.extend({ |
267 |
templateName: 'snfElem', |
268 |
addNewBtn: true, |
269 |
selectable: false, |
270 |
icon: function() { |
271 |
baseIcon = Synnefo.conf.sectors.findBy('destination', this.get('type')).icon; |
272 |
return baseIcon.replace('outline', 'create-full'); |
273 |
}.property(), |
274 |
tagName: 'li', |
275 |
status: 'add-new', |
276 |
classNameBindings: ['status'], |
277 |
attributeBindings: ['data-status, data-reveal-id'], |
278 |
'data-reveal-id': function(){ |
279 |
if(addNewBtn)
|
280 |
return /*this.get('type').substring(0, type.length - 1)+*/'-wizard'; |
281 |
else
|
282 |
return undefined; |
283 |
}.property(), |
284 |
'data-status': function() { |
285 |
return this.status; |
286 |
}.property(), |
287 |
name: function() { |
288 |
var msg = 'Create New '; |
289 |
var btnType = this.get('type') |
290 |
switch(btnType){
|
291 |
case 'vms': |
292 |
return msg + 'Machine'; |
293 |
case 'networks': |
294 |
return msg + 'Network'; |
295 |
case 'volumes': |
296 |
return msg + 'Volume'; |
297 |
case 'snapshots': |
298 |
return msg + 'Snapshot'; |
299 |
case 'images': |
300 |
return '+ Upload New Image'; |
301 |
} |
302 |
}.property(), |
303 |
click: function () { |
304 |
// var type = this.get('type');
|
305 |
// var wizardEl = $('#'+ type.substring(0, type.length - 1)+'-wizard');
|
306 |
// $('.overlay-area-custom').fadeIn(100);
|
307 |
// $('body').addClass('with-overlay');
|
308 |
// wizardEl.fadeIn('slow');
|
309 |
console.log('1');
|
310 |
this.sendAction('action'); |
311 |
} |
312 |
}); |
313 |
|
314 |
Synnefo.LoginMenuComponent = Ember.Component.extend({ |
315 |
classNames: ['login'], |
316 |
didInsertElement: function() { |
317 |
console.log('didInsertElement');
|
318 |
var self = this.$(); |
319 |
self.mouseenter(function(e){
|
320 |
self.find('ul').stop(true, true).slideDown(200); |
321 |
}); |
322 |
self.mouseleave(function(e){
|
323 |
self.find('ul').stop(true, true).slideUp(200); |
324 |
}); |
325 |
|
326 |
} |
327 |
}); |
328 |
|
329 |
Synnefo.SnfCheckboxComponent = Ember.Component.extend({ |
330 |
tagName: 'a', |
331 |
classNames: ['check'], |
332 |
templateName: 'components/select-btn', |
333 |
initState: function() { |
334 |
return this.get('initState'); |
335 |
}.property(), |
336 |
didInsertElement: function() { |
337 |
var el = this.$(); |
338 |
var self =this; |
339 |
this.setInitClasses();
|
340 |
el.click(function(e) {
|
341 |
e.preventDefault(); |
342 |
e.stopPropagation(); |
343 |
self.changeState(el); |
344 |
// ui.entitiesActionsEnabled();
|
345 |
}); |
346 |
}, |
347 |
setInitClasses: function() { |
348 |
var self =this.$(); |
349 |
switch(this.initState){ |
350 |
case 'unchecked': { |
351 |
this.uncheck(self);
|
352 |
break;
|
353 |
} |
354 |
case 'prechecked': { |
355 |
self.find('span').addClass('prechecked') |
356 |
this.check(self);
|
357 |
break;
|
358 |
} |
359 |
} |
360 |
}, |
361 |
// used to be in ui.checkbox
|
362 |
changeState : function(checkbox_link) { |
363 |
$(checkbox_link).find('.snf-checkbox-unchecked, .snf-checkbox-checked').toggleClass('snf-checkbox-unchecked snf-checkbox-checked'); |
364 |
$(checkbox_link).closest('li').toggleClass('selected'); |
365 |
}, |
366 |
check : function(checkbox_link) { |
367 |
$(checkbox_link).find('span').removeClass('snf-checkbox-unchecked').addClass('snf-checkbox-checked'); |
368 |
$(checkbox_link).closest('li').addClass('selected'); |
369 |
}, |
370 |
uncheck : function(checkbox_link) { |
371 |
$(checkbox_link).find('span').removeClass('snf-checkbox-checked').addClass('snf-checkbox-unchecked'); |
372 |
$(checkbox_link).closest('li').removeClass('selected'); |
373 |
}, |
374 |
|
375 |
reset: function(area) { |
376 |
$(area).find('.snf-radio-checked').not('.prechecked').toggleClass('snf-radio-checked snf-radio-unchecked'); |
377 |
$(area).find('.snf-radio-unchecked.prechecked').toggleClass('snf-radio-checked snf-radio-unchecked'); |
378 |
}, |
379 |
}); |