root / snf-cyclades-app / synnefo / ui / new_ui / ui / javascripts / okeanos-ember / views.js @ 3b698137
History | View | Annotate | Download (8.2 kB)
1 |
|
---|---|
2 |
/* Views */
|
3 |
|
4 |
Ember.View.reopen({ |
5 |
didInsertElement: function() { |
6 |
this._super();
|
7 |
this.set('elIsInserted', true); |
8 |
}, |
9 |
|
10 |
willDestroyElement: function() { |
11 |
this._super();
|
12 |
this.set('elIsInserted', false); |
13 |
} |
14 |
}); |
15 |
|
16 |
|
17 |
Synnefo.ApplicationView = Ember.View.extend({ |
18 |
classNames: ['content'] |
19 |
}); |
20 |
|
21 |
|
22 |
/* Navigation Menu */
|
23 |
|
24 |
Synnefo.NavIconView = Ember.View.extend({ |
25 |
tagName: 'span', |
26 |
click: function() { |
27 |
var parentEl = this.$().parent('a'); |
28 |
var currentEl = this.$().parents('li').siblings('li').find('a.current'); |
29 |
|
30 |
ui.replaceClass(currentEl, 'full', 'outline', 'snf-'); |
31 |
ui.replaceClass(parentEl, 'outline', 'full', 'snf-'); |
32 |
} |
33 |
|
34 |
}); |
35 |
|
36 |
Synnefo.NavigationView = Ember.CollectionView.extend({ |
37 |
tagName: "ul", |
38 |
classNames: ['icons-nav'], |
39 |
|
40 |
content: Synnefo.conf.sectors,
|
41 |
itemViewClass: Ember.View.extend({
|
42 |
templateName: "navigationItem" |
43 |
}), |
44 |
}); |
45 |
|
46 |
|
47 |
/* Items Parts */
|
48 |
|
49 |
Synnefo.ElemView = Ember.View.extend({ |
50 |
// templateName: 'elem',
|
51 |
addNewBtn: false, |
52 |
templateName: 'snfElem', |
53 |
tagName: 'li', |
54 |
selectable: true, |
55 |
initSelect: 'unchecked', |
56 |
classNameBindings: ['status'], |
57 |
attributeBindings: ['data-status'], |
58 |
'data-status': function() { |
59 |
return this.status; |
60 |
}.property(), |
61 |
status: function() { |
62 |
return this.get('controller.status'); |
63 |
}.property('controller.status')
|
64 |
}); |
65 |
|
66 |
Synnefo.ImgWrapView = Ember.View.extend({ |
67 |
templateName: 'img-wrap', |
68 |
classNames: ['img-wrap'], |
69 |
icon: function() { |
70 |
var parentView = this.get('parentView'); |
71 |
var addNewBtn = parentView.get('addNewBtn'); |
72 |
if(addNewBtn)
|
73 |
return parentView.get('icon'); |
74 |
else
|
75 |
return parentView.get('controller').get('parentController').get('icon'); |
76 |
}.property() |
77 |
}); |
78 |
|
79 |
Synnefo.LabelNameView = Ember.View.extend({ |
80 |
templateName: 'name', |
81 |
tagName: 'h4', |
82 |
name: function() { |
83 |
// the name may be defined inside the parent view or in its model or controller
|
84 |
return this.get('parentView').get('controller').get('name'); |
85 |
}.property() |
86 |
}); |
87 |
|
88 |
// to be changed
|
89 |
Synnefo.ImmediateActionView = Ember.View.extend({ |
90 |
templateName: 'actions', |
91 |
classNames: ['actions'] |
92 |
}); |
93 |
|
94 |
|
95 |
/* Wizard */
|
96 |
|
97 |
|
98 |
Synnefo.CollectionView = Ember.CollectionView.extend({ |
99 |
counter: 0 |
100 |
}); |
101 |
|
102 |
// to use (extend) Synnefo.CollectionItemView must a counter to be set (initialized) in the parent view
|
103 |
// so when we want to use Synnefo.CollectionItemView, the collection that includes has extend Synnefo.CollectionView
|
104 |
Synnefo.CollectionItemView = Ember.View.extend({ |
105 |
// classNameBindings: ['isCurrent:current::', 'isFirst:preselected', 'isPast:past::'],
|
106 |
index: undefined, // index>=1 |
107 |
isCurrent: false, |
108 |
isFirst: false, |
109 |
isPrev: false, |
110 |
init: function() { |
111 |
this._super();
|
112 |
var prevIndex = this.get('parentView').get('counter'); |
113 |
var index = ++prevIndex;
|
114 |
this.get('parentView').set('counter', index); |
115 |
this.set('index', index); |
116 |
if(index === 1) { |
117 |
this.set('isFirst', true); |
118 |
} |
119 |
}, |
120 |
isCurrent: function() { |
121 |
return this.index === this.get('controller').get('currentStep'); |
122 |
}.property('controller.currentStep'),
|
123 |
isPast: function() { |
124 |
return this.index < this.get('controller').get('currentStep'); |
125 |
}.property('controller.currentStep'),
|
126 |
isNext: function() { |
127 |
return this.index === (this.get('controller').get('currentStep')+1); |
128 |
}.property('controller.currentStep'),
|
129 |
isPrev: function() { |
130 |
return this.index === (this.get('controller').get('currentStep')-1); |
131 |
}.property('controller.currentStep')
|
132 |
}); |
133 |
|
134 |
|
135 |
Synnefo.WizardStepView = Synnefo.CollectionItemView.extend({ |
136 |
classNames: ['step'], |
137 |
classNameBindings: ['isFirst:current::', 'isFirst:preselected', 'isNext:next::', 'isPrev:prev::'], |
138 |
templateName: function() { |
139 |
return 'wizardSteps/step-'+this.get('index'); |
140 |
}.property(), |
141 |
}); |
142 |
|
143 |
Synnefo.WizardStepsView = Synnefo.CollectionView.extend({ |
144 |
classNames: 'middle', |
145 |
content: Synnefo.wizards.vmWizard.stepsContent,
|
146 |
itemViewClass: Synnefo.WizardStepView,
|
147 |
move: function() { |
148 |
if(this.get('elIsInserted')) { |
149 |
var onMove = this.get('controller').get('onMove'); |
150 |
if(onMove) {
|
151 |
var el = this.$(); |
152 |
var self = this; |
153 |
// I find the current step from the view's property
|
154 |
// not from dom's class to be sure that there will be no sychronisation problem?
|
155 |
var direction = this.get('controller').get('directionMove'); |
156 |
var viewCurrent = this._childViews.findBy('isCurrent', true); |
157 |
var totalSteps = this.get('controller').get('totalSteps') |
158 |
|
159 |
if(!(direction === 'next' && viewCurrent.get('index') === totalSteps) && !(direction === 'prev' && viewCurrent.get('index') === 1)) { |
160 |
var elCurrent = el.find('.current'); |
161 |
var elSteps = el.find('.step'); |
162 |
var pos = (direction==='next')?(100):(-100); |
163 |
var viewToDisplay;
|
164 |
var elToDisplay
|
165 |
|
166 |
if(direction === 'next') { |
167 |
viewToDisplay = this._childViews.findBy('isNext', true); |
168 |
elToDisplay = el.find('.next');
|
169 |
} |
170 |
else {
|
171 |
viewToDisplay = this._childViews.findBy('isPrev', true); |
172 |
elToDisplay = el.find('.prev');
|
173 |
} |
174 |
|
175 |
$('body').css('overflow', 'hidden'); |
176 |
|
177 |
elToDisplay.css({ |
178 |
left: pos.toString()+'%' |
179 |
}).addClass('current');
|
180 |
|
181 |
elToDisplay.css({ |
182 |
top: document.body.scrollTop + 'px' |
183 |
}); |
184 |
|
185 |
elSteps.animate({ |
186 |
marginLeft: (-pos).toString() + '%' |
187 |
},{ |
188 |
complete: _.bind(function() { |
189 |
elCurrent.removeClass('current');
|
190 |
window.scroll(0, 0); |
191 |
elToDisplay.css({ |
192 |
left: '0', |
193 |
top: '0' |
194 |
}); |
195 |
elSteps.css({ |
196 |
marginLeft: '0' |
197 |
}); |
198 |
$('body').css('overflow', 'visible'); |
199 |
|
200 |
viewCurrent.set('isCurrent', false); |
201 |
viewToDisplay.set('isCurrent', true); |
202 |
self.get('controller').set('currentStep',viewToDisplay.get('index')); |
203 |
this.get('controller').set('onMove', false); |
204 |
}, this)
|
205 |
}); |
206 |
} |
207 |
} |
208 |
} |
209 |
}.observes('controller.onMove'),
|
210 |
didInsertElement: function() { |
211 |
this._super();
|
212 |
$('body').addClass('with-overlay'); |
213 |
}, |
214 |
willDestroyElement: function() { |
215 |
this._super();
|
216 |
$('body').removeClass('with-overlay'); |
217 |
} |
218 |
}); |
219 |
|
220 |
|
221 |
|
222 |
Synnefo.WizardHeadersView = Synnefo.CollectionView.extend({ |
223 |
tagName: 'ul', |
224 |
classNames:['nums'], |
225 |
content: Synnefo.wizards.vmWizard.stepsHeadlines,
|
226 |
itemViewClass: Synnefo.CollectionItemView.extend({
|
227 |
classNameBindings: ['isCurrent:current::', 'isFirst:preselected', 'isPast:past::'], |
228 |
templateName: 'wizardStepHeader', |
229 |
}) |
230 |
}); |
231 |
|
232 |
Synnefo.WizardSubMenusView = Synnefo.CollectionView.extend({ |
233 |
classNames: ['row', 'menus'], |
234 |
content: Synnefo.wizards.vmWizard.stepsSubmenus,
|
235 |
itemViewClass: Synnefo.CollectionItemView.extend({
|
236 |
tagName: 'nav', |
237 |
classNames: ['sub-menu'], |
238 |
classNameBindings: ['isCurrent:current::', 'isFirst:preselected', 'isPast:past::'], |
239 |
templateName: 'submenu' |
240 |
}) |
241 |
|
242 |
}); |
243 |
|
244 |
Synnefo.WizardSubMenuView = Synnefo.CollectionView.extend({ |
245 |
tagName: 'ul', |
246 |
content: function() { |
247 |
var stepIndex = this.get('parentView').get('index'); |
248 |
return Synnefo.wizards.vmWizard.stepsSubmenus[--stepIndex].options;
|
249 |
}.property(), |
250 |
removeOtherCurrent: function(clickedView) { |
251 |
var childViews = this._childViews; |
252 |
|
253 |
for(var i=0; i<childViews.length; i++) |
254 |
if(childViews[i] !== clickedView)
|
255 |
childViews[i].set('isCurrent', false); |
256 |
}, |
257 |
itemViewClass: Synnefo.CollectionItemView.extend({
|
258 |
templateName: 'menuOption', |
259 |
classNameBindings:['isCurrent:current::', 'isFirst:preselected'], |
260 |
isCurrent: function(){ |
261 |
if(this.get('isFirst')) return true; |
262 |
}.property(), |
263 |
move: function() { |
264 |
if(this.get('controller').get('onMove')) { |
265 |
this.get('parentView').removeOtherCurrent(this); |
266 |
this.set('isCurrent', true); |
267 |
} |
268 |
}.observes('controller.onMove')
|
269 |
}) |
270 |
}); |
271 |
|
272 |
|
273 |
// The only buttons that are views are the buttons that move the wizard
|
274 |
// The reason is that they shouldn't be isolated from the surrounding
|
275 |
// (Their labels changes depanding the current step)
|
276 |
Synnefo.WizardBtnBackView = Ember.View.extend({ |
277 |
classNames: ['nav', 'prev'], |
278 |
tagName: 'a', |
279 |
templateName: 'components/btns-span', |
280 |
content: function(){ |
281 |
return this.get('controller').get('btnLeftLabel'); |
282 |
}.property('controller.btnLeftLabel'),
|
283 |
click: function() { |
284 |
this.get('controller').send('moveBack'); |
285 |
} |
286 |
}); |
287 |
|
288 |
Synnefo.WizardBtnNextView = Ember.View.extend({ |
289 |
classNames: ['nav', 'next'], |
290 |
tagName: 'a', |
291 |
templateName: 'components/btns-span', |
292 |
content: function(){ |
293 |
return this.get('controller').get('btnRightLabel'); |
294 |
}.property('controller.btnRightLabel'),
|
295 |
click: function() { |
296 |
this.get('controller').send('moveNext'); |
297 |
} |
298 |
}); |