Statistics
| Branch: | Tag: | Revision:

root / snf-cyclades-app / synnefo / ui / new_ui / ui / javascripts / okeanos-ember / views.js @ cc5d0e0e

History | View | Annotate | Download (5.1 kB)

1

    
2
/* Views */
3

    
4
Synnefo.ApplicationView = Ember.View.extend({
5
        classNames: ['content']
6
});
7

    
8

    
9
/* Navigation Menu */
10

    
11
Synnefo.NavIconView = Ember.View.extend({
12
        tagName: 'span',
13
        click: function() {
14
                var parentEl = this.$().parent('a');
15
                var currentEl = this.$().parents('li').siblings('li').find('a.current');
16

    
17
                ui.replaceClass(currentEl, 'full', 'outline', 'snf-');
18
                ui.replaceClass(parentEl, 'outline', 'full', 'snf-');
19
        }
20

    
21
});
22

    
23
Synnefo.NavigationView = Ember.CollectionView.extend({
24
  tagName: "ul",
25
  classNames: ['icons-nav'],
26

    
27
  content: Synnefo.conf.sectors,
28
  itemViewClass: Ember.View.extend({
29
    templateName: "navigationItem"
30
  }),
31
});
32

    
33

    
34
/* Items Parts */
35

    
36
Synnefo.ElemView = Ember.View.extend({
37
        // templateName: 'elem',
38
        addNewBtn: false,
39
        templateName: 'snfElem',
40
        tagName: 'li',
41
        selectable: true,
42
        initSelect: 'unchecked',
43
        classNameBindings: ['status'],
44
        attributeBindings: ['data-status'],
45
        'data-status': function() {
46
                return this.status;
47
        }.property(),
48
        status: function() {
49
                return this.get('controller.status');
50
        }.property('controller.status')
51
});
52

    
53
Synnefo.ImgWrapView = Ember.View.extend({
54
        templateName: 'img-wrap',
55
        classNames: ['img-wrap'],
56
        icon: function() {
57
                var parentView = this.get('parentView');
58
                var addNewBtn = parentView.get('addNewBtn');
59
                if(addNewBtn)
60
                        return parentView.get('icon');
61
                else
62
                        return parentView.get('controller').get('parentController').get('icon');
63
        }.property()
64
});
65

    
66
Synnefo.LabelNameView = Ember.View.extend({
67
        templateName: 'name',
68
        tagName: 'h4',
69
        name: function() {
70
                // the name may be defined inside the parent view or in its model or controller
71
                return this.get('parentView').get('controller').get('name');
72
        }.property()
73
});
74

    
75
// to be changed
76
Synnefo.ImmediateActionView = Ember.View.extend({
77
        templateName: 'actions',
78
        classNames: ['actions']
79
});
80

    
81

    
82
/* Wizard */
83

    
84
Synnefo.CollectionView = Ember.CollectionView.extend({
85
        counter: 0
86
});
87

    
88
// to use (extend) Synnefo.CollectionItemView must a counter to be set (initialized) in the parent view
89
//  so when we want to use Synnefo.CollectionItemView, the collection that includes has extend Synnefo.CollectionView
90
Synnefo.CollectionItemView = Ember.View.extend({
91
        // classNameBindings: ['isCurrent:current::', 'isFirst:preselected', 'isPast:past::'],
92
                index: undefined,
93
                isCurrent: false,
94
                isFirst: false,
95
                init: function() {
96
                        this._super();
97
                        var prevIndex = this.get('parentView').get('counter');
98
                        var index = ++prevIndex;
99
                        this.get('parentView').set('counter', index);
100
                        this.set('index', index);
101
                        if(index === 1) {
102
                                this.set('isFirst', true);
103
                        }
104
                },
105
                isCurrent: function() {
106
                        return this.index === this.get('controller').get('currentStep');
107
                }.property('controller.currentStep'),
108
                isPast: function() {
109
                        return this.index < this.get('controller').get('currentStep');
110
                }.property('controller.currentStep')
111
        });
112

    
113

    
114
Synnefo.WizardHeadersView = Synnefo.CollectionView.extend({
115
        tagName: 'ul',
116
        classNames:['nums'],
117
        content: Synnefo.wizards.vmWizard.stepsHeadlines,
118
        itemViewClass: Synnefo.CollectionItemView.extend({
119
                classNameBindings: ['isCurrent:current::', 'isFirst:preselected', 'isPast:past::'],
120
                templateName: 'wizardStepHeader',
121
        })
122
});
123

    
124
Synnefo.WizardSubMenusView = Synnefo.CollectionView.extend({
125
        classNames: ['row', 'menus'],
126
        content: Synnefo.wizards.vmWizard.stepsSubmenus,
127
        itemViewClass: Synnefo.CollectionItemView.extend({
128
                tagName: 'nav',
129
                classNames: ['sub-menu'],
130
                classNameBindings: ['isCurrent:current::', 'isFirst:preselected', 'isPast:past::'],
131
                templateName: 'submenu'
132
        })
133

    
134
});
135

    
136
Synnefo.WizardSubMenuView = Synnefo.CollectionView.extend({
137
        tagName: 'ul',
138
        content: function() {
139
                var stepIndex = this.get('parentView').get('index');
140
                return Synnefo.wizards.vmWizard.stepsSubmenus[--stepIndex].options;
141
        }.property(),
142
        removeOtherCurrent: function(clickedView) {
143
                var childViews = this._childViews;
144

    
145
                for(var i=0; i<childViews.length; i++)
146
                        if(childViews[i] !== clickedView)
147
                                childViews[i].set('isCurrent', false);
148
        },
149
        itemViewClass: Synnefo.CollectionItemView.extend({
150
                templateName: 'menuOption',
151
                classNameBindings:['isCurrent:current::', 'isFirst:preselected'],
152
                isCurrent: function(){
153
                        if(this.get('isFirst')) return true;
154
                }.property(),
155
                click: function() {
156
                        this.get('parentView').removeOtherCurrent(this);
157
                        this.set('isCurrent', true)
158
                }
159
        })
160
});
161

    
162

    
163
// The only buttons that are views are the buttons that move the wizard
164
// The reason is that they shouldn't be isolated from the surrounding
165
// (Their labels changes depanding the current step)
166
Synnefo.WizardBtnBackView = Ember.View.extend({
167
        classNames: ['nav', 'prev'],
168
        tagName: 'a',
169
        templateName: 'components/btns-span',
170
        content: function(){
171
                return this.get('controller').get('btnLeftLabel');
172
        }.property('controller.btnLeftLabel'),
173
        click: function() {
174
                this.get('controller').send('moveBack');
175
        }
176
});
177

    
178
Synnefo.WizardBtnNextView = Ember.View.extend({
179
        classNames: ['nav', 'next'],
180
        tagName: 'a',
181
        templateName: 'components/btns-span',
182
        content: function(){
183
                return this.get('controller').get('btnRightLabel');
184
        }.property('controller.btnRightLabel'),
185
        click: function() {
186
                this.get('controller').send('moveNext');
187
        }
188
});