Revision 44110e0e snf-cyclades-app/synnefo/ui/new_ui/ui/javascripts/okeanos-ember/views.js

b/snf-cyclades-app/synnefo/ui/new_ui/ui/javascripts/okeanos-ember/views.js
1 1

  
2 2
/* Views */
3 3

  
4
Ember.View.reopen({
5
    didInsertElement: function() {
6
       this.set('elIsInserted', true);
7
       this._super();
8
    },
9

  
10
    willDestroyElement: function() {
11
       this.set('elIsInserted', false);
12
       this._super();
13
    }
14
});
15

  
16

  
4 17
Synnefo.ApplicationView = Ember.View.extend({
5 18
	classNames: ['content']
6 19
});
......
81 94

  
82 95
/* Wizard */
83 96

  
97

  
84 98
Synnefo.CollectionView = Ember.CollectionView.extend({
85 99
	counter: 0
86 100
});
......
89 103
//  so when we want to use Synnefo.CollectionItemView, the collection that includes has extend Synnefo.CollectionView
90 104
Synnefo.CollectionItemView = Ember.View.extend({
91 105
	// classNameBindings: ['isCurrent:current::', 'isFirst:preselected', 'isPast:past::'],
92
		index: undefined,
106
		index: undefined, // index>=1
93 107
		isCurrent: false,
94 108
		isFirst: false,
109
		isPrev: false,
95 110
		init: function() {
96 111
			this._super();
97 112
			var prevIndex = this.get('parentView').get('counter');
......
107 122
		}.property('controller.currentStep'),
108 123
		isPast: function() {
109 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);
110 131
		}.property('controller.currentStep')
111 132
	});
112 133

  
113 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)
204
					});
205
				}
206
				this.get('controller').set('onMove', false);
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

  
114 222
Synnefo.WizardHeadersView = Synnefo.CollectionView.extend({
115 223
	tagName: 'ul',
116 224
	classNames:['nums'],

Also available in: Unified diff