root / snf-cyclades-app / synnefo / ui / new_ui / ui / javascripts / okeanos-ember / ember-all.js @ 3342f8ce
History | View | Annotate | Download (7.4 kB)
1 |
/* Mapping */
|
---|---|
2 |
|
3 |
Okeanos.Router.map(function() {
|
4 |
|
5 |
for(var i=0; i<Okeanos.places.length; i++) |
6 |
this.resource(Okeanos.places[i].destination);
|
7 |
}); |
8 |
|
9 |
|
10 |
/* Routes */
|
11 |
|
12 |
Okeanos.ApplicationRoute = Ember.Route.extend({ |
13 |
model: function() { |
14 |
|
15 |
return {email: 'athina@mail.com'}; |
16 |
} |
17 |
}); |
18 |
|
19 |
Okeanos.VmsRoute = Ember.Route.extend({ |
20 |
model: function() { |
21 |
return this.store.find('vm'); |
22 |
}, |
23 |
renderTemplate: function(controller) { |
24 |
this.render('snfElems', {controller: controller}) |
25 |
} |
26 |
}); |
27 |
|
28 |
Okeanos.NetsRoute = Ember.Route.extend({ |
29 |
model: function() { |
30 |
return [{id: '1', name:'net1', status: 'active'}, {id: '2', name:'net2', status: 'error'}]; |
31 |
}, |
32 |
renderTemplate: function(controller) { |
33 |
this.render('snfElems', {controller: controller}) |
34 |
} |
35 |
}); |
36 |
|
37 |
|
38 |
/* Controllers */
|
39 |
|
40 |
Okeanos.ApplicationController = Ember.Controller.extend({ |
41 |
updateCurrentPath: function() { |
42 |
// we need the set because ElemsController gets the value of current path in every transition
|
43 |
Okeanos.set('currentPath', this.get('currentPath')) |
44 |
return this.get('currentPath'); |
45 |
}.observes('currentPath'),
|
46 |
actions: {
|
47 |
test: function() { |
48 |
console.log('This is test from Okeanos.ApplicationController');
|
49 |
return 0; |
50 |
} |
51 |
}, |
52 |
|
53 |
pageTitle : function() { |
54 |
var currentPath =this.get('currentPath'); |
55 |
if(currentPath!== 'index') return Okeanos.places.findBy('destination', this.get('currentPath')).title; |
56 |
else return 'Home'; |
57 |
}.property('currentPath'),
|
58 |
|
59 |
// name: "okeanos application",
|
60 |
}); |
61 |
|
62 |
|
63 |
Okeanos.ElemsController = Ember.ArrayController.extend({ |
64 |
type: undefined, |
65 |
itemController: function(){ |
66 |
var type = this.type; |
67 |
return type.substring(0, type.length - 1); |
68 |
}.property(), |
69 |
icon: function() { |
70 |
return Okeanos.places.findBy('destination', this.get('type')).icon.replace('outline', 'full'); |
71 |
}.property(), |
72 |
hasOS: function(){ |
73 |
if(Okeanos.get('currentPath') == "vms") |
74 |
return true; |
75 |
else return false; |
76 |
}.property(), |
77 |
hasTags: function(){ |
78 |
if(Okeanos.get('currentPath') == "vms") |
79 |
return true; |
80 |
else return false; |
81 |
}.property(), |
82 |
}); |
83 |
|
84 |
Okeanos.VmsController = Okeanos.ElemsController.extend({ |
85 |
type: 'vms' |
86 |
}); |
87 |
|
88 |
|
89 |
Okeanos.NetsController = Okeanos.ElemsController.extend({ |
90 |
type: 'nets' |
91 |
}); |
92 |
|
93 |
|
94 |
Okeanos.ElemController = Ember.ObjectController.extend({ |
95 |
needs: [],
|
96 |
actionsList: Okeanos.AllActions,
|
97 |
setAvailableActions: function() { |
98 |
var parent = this.needs; |
99 |
var self = this; |
100 |
return this.actionsList.filter(function(el) { |
101 |
return _.contains(el['snf-components'], self.get('controllers.'+parent).type) &&( _.contains(el['enabled-status'], self.get('model.status')) || _.contains(el['enabled-status'], 'all')); |
102 |
}) |
103 |
}.property(), |
104 |
createBtn: false, |
105 |
actions: {
|
106 |
shutdown: function(param) { |
107 |
console.log(this.get('model.status')); |
108 |
this.set('model.status', 'shutting'); |
109 |
}, |
110 |
destroyElement: function(param) { |
111 |
var element = this.get('model'); |
112 |
element.deleteRecord(); |
113 |
element.save(); |
114 |
} |
115 |
} |
116 |
}); |
117 |
|
118 |
Okeanos.VmController = Okeanos.ElemController.extend({ |
119 |
needs: ['vms'] |
120 |
}); |
121 |
|
122 |
Okeanos.NetController = Okeanos.ElemController.extend({ |
123 |
needs: ['nets'] |
124 |
}); |
125 |
|
126 |
|
127 |
/* Views */
|
128 |
|
129 |
Okeanos.NavIconView = Ember.View.extend({ |
130 |
tagName: 'span', |
131 |
click: function(e) { |
132 |
var parentEl = this.$().parent('a'); |
133 |
var currentEl = this.$().parents('li').siblings('li').find('a.current'); |
134 |
|
135 |
ui.replaceClass(currentEl, 'full', 'outline', 'snf-'); |
136 |
ui.replaceClass(parentEl, 'outline', 'full', 'snf-'); |
137 |
} |
138 |
|
139 |
}); |
140 |
|
141 |
Okeanos.NavigationView = Ember.CollectionView.extend({ |
142 |
tagName: "ul", |
143 |
classNames: ['icons-nav'], |
144 |
|
145 |
content: Okeanos.places,
|
146 |
itemViewClass: Ember.View.extend({
|
147 |
template: Ember.TEMPLATES["navigationItem"] |
148 |
}), |
149 |
}); |
150 |
|
151 |
|
152 |
Okeanos.ElemView = Ember.View.extend({ |
153 |
// templateName: 'elem',
|
154 |
addNewBtn: false, |
155 |
template: Ember.TEMPLATES['snfElem'], |
156 |
tagName: 'li', |
157 |
selectable: true, |
158 |
initSelect: 'unchecked', |
159 |
classNameBindings: ['status'], |
160 |
attributeBindings: ['data-status'], |
161 |
'data-status': function() { |
162 |
return this.status; |
163 |
}.property(), |
164 |
status: function() { |
165 |
return this.get('controller.status'); |
166 |
}.property('controller.status')
|
167 |
}); |
168 |
|
169 |
Okeanos.ImgWrapView = Ember.View.extend({ |
170 |
template: Ember.TEMPLATES['img-wrap'], |
171 |
classNames: ['img-wrap'], |
172 |
icon: function() { |
173 |
var addNewBtn = this.get('parentView').get('addNewBtn'); |
174 |
console.log('addNewBtn: ' + addNewBtn);
|
175 |
if(addNewBtn)
|
176 |
return this.get('parentView').get('icon'); |
177 |
else
|
178 |
return this.get('parentView').get('controller').get('parentController').get('icon'); |
179 |
}.property() |
180 |
}); |
181 |
|
182 |
|
183 |
// to evala ws view gt thelw na kanw diaxeirisi tou interaction tou xristi
|
184 |
Okeanos.ElementSidebarView = Ember.View.extend({ |
185 |
tagName: 'ul', |
186 |
classNames: ['side-actions'], |
187 |
template: Ember.TEMPLATES['elementSidebar'] |
188 |
}); |
189 |
|
190 |
/* Components */
|
191 |
|
192 |
Okeanos.Btn1Component = Ember.Component.extend({ |
193 |
tagName: 'a', |
194 |
click: function() { |
195 |
this.sendAction("action", this.get('param')); |
196 |
} |
197 |
}); |
198 |
|
199 |
Okeanos.AddNewComponent = Ember.Component.extend({ |
200 |
template: Ember.TEMPLATES['snfElem'], |
201 |
addNewBtn: true, |
202 |
selectable: false, |
203 |
icon: function() { |
204 |
baseIcon = Okeanos.places.findBy('destination', this.get('type')).icon; |
205 |
return baseIcon.replace('outline', 'create-full'); |
206 |
}.property(), |
207 |
tagName: 'li', |
208 |
status: 'add-new', |
209 |
classNameBindings: ['status'], |
210 |
attributeBindings: ['data-status'], |
211 |
'data-status': function() { |
212 |
return this.status; |
213 |
}.property(), |
214 |
name: function() { |
215 |
var msg = 'Add New '; |
216 |
var btnType = this.get('type') |
217 |
if(btnType === 'vms') |
218 |
return msg + 'Machine'; |
219 |
else if(btnType === 'nets') |
220 |
return msg + 'Network'; |
221 |
}.property() |
222 |
|
223 |
}); |
224 |
|
225 |
Okeanos.LoginMenuComponent = Ember.Component.extend({ |
226 |
classNames: ['login'], |
227 |
didInsertElement: function() { |
228 |
console.log('didInsertElement');
|
229 |
var self = this.$(); |
230 |
self.mouseenter(function(e){
|
231 |
self.find('ul').stop(true, true).slideDown(200); |
232 |
}); |
233 |
self.mouseleave(function(e){
|
234 |
self.find('ul').stop(true, true).slideUp(200); |
235 |
}); |
236 |
|
237 |
} |
238 |
}); |
239 |
|
240 |
Okeanos.SnfCheckboxComponent = Ember.Component.extend({ |
241 |
tagName: 'a', |
242 |
classNames: ['check'], |
243 |
initState: function() { |
244 |
return this.get('initState'); |
245 |
}.property(), |
246 |
template: Ember.TEMPLATES['snf-checkbox'], |
247 |
didInsertElement: function() { |
248 |
var domRef = this.$(); |
249 |
var self =this; |
250 |
this.setInitClasses();
|
251 |
domRef.click(function(e) {
|
252 |
e.preventDefault(); |
253 |
e.stopPropagation(); |
254 |
self.changeState(domRef); |
255 |
// ui.entitiesActionsEnabled();
|
256 |
console.log(self.get('elementID'))
|
257 |
}); |
258 |
}, |
259 |
setInitClasses: function() { |
260 |
var self =this.$(); |
261 |
switch(this.initState){ |
262 |
case 'unchecked': { |
263 |
this.uncheck(self);
|
264 |
break;
|
265 |
} |
266 |
case 'prechecked': { |
267 |
self.find('span').addClass('prechecked') |
268 |
this.check(self);
|
269 |
break;
|
270 |
} |
271 |
} |
272 |
}, |
273 |
// used to be in ui.checkbox
|
274 |
changeState : function(checkbox_link) { |
275 |
$(checkbox_link).find('.snf-checkbox-unchecked, .snf-checkbox-checked').toggleClass('snf-checkbox-unchecked snf-checkbox-checked'); |
276 |
$(checkbox_link).closest('li').toggleClass('selected'); |
277 |
}, |
278 |
check : function(checkbox_link) { |
279 |
$(checkbox_link).find('span').removeClass('snf-checkbox-unchecked').addClass('snf-checkbox-checked'); |
280 |
$(checkbox_link).closest('li').addClass('selected'); |
281 |
}, |
282 |
uncheck : function(checkbox_link) { |
283 |
$(checkbox_link).find('span').removeClass('snf-checkbox-checked').addClass('snf-checkbox-unchecked'); |
284 |
$(checkbox_link).closest('li').removeClass('selected'); |
285 |
}, |
286 |
|
287 |
reset: function(area) { |
288 |
$(area).find('.snf-radio-checked').not('.prechecked').toggleClass('snf-radio-checked snf-radio-unchecked'); |
289 |
$(area).find('.snf-radio-unchecked.prechecked').toggleClass('snf-radio-checked snf-radio-unchecked'); |
290 |
}, |
291 |
}); |