Statistics
| Branch: | Tag: | Revision:

root / snf-cyclades-app / synnefo / ui / new_ui / ui / javascripts / okeanos-ember / ember-all.js @ b058f1fe

History | View | Annotate | Download (9.1 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
});
25

    
26
Synnefo.SectionsRoute = Ember.Route.extend({
27
        modelName: undefined,
28
        model: function() {
29
                return this.store.find(this.modelName);
30
        },
31
        renderTemplate: function(controller) {
32
                this.render('snfElems', {controller: controller});
33
        }
34
});
35

    
36
Synnefo.VmsRoute = Synnefo.SectionsRoute.extend({
37
        modelName: 'vm'
38
});
39

    
40
Synnefo.NetsRoute = Synnefo.SectionsRoute.extend({
41
        modelName: 'network'
42
});
43

    
44
Synnefo.VolumesRoute = Synnefo.SectionsRoute.extend({
45
        modelName: 'volume'
46
});
47

    
48
Synnefo.SnapshotsRoute = Synnefo.SectionsRoute.extend({
49
        modelName: 'snapshot'
50
});
51

    
52
Synnefo.ImagesRoute = Synnefo.SectionsRoute.extend({
53
        modelName: 'userImage'
54
});
55

    
56

    
57

    
58

    
59

    
60
/* Controllers */
61

    
62
Synnefo.ApplicationController = Ember.Controller.extend({
63
        updateCurrentPath: function() {
64
                // we need the set because ElemsController gets the value of current path in every transition
65
                Synnefo.set('currentPath', this.get('currentPath'))
66
                return this.get('currentPath');
67
        }.observes('currentPath'),
68
        actions: {
69
                test: function() {
70
                        console.log('This is test from Synnefo.ApplicationController');
71
                        return 0;
72
                }
73
        },
74

    
75
        pageTitle : function() {
76
                var currentPath =this.get('currentPath');
77
                if(currentPath!== 'index') return Synnefo.conf.sectors.findBy('destination', this.get('currentPath')).title;
78
                        else return 'Home';
79
        }.property('currentPath'),
80

    
81
        // name: "okeanos application",
82
});
83

    
84

    
85

    
86
Synnefo.ElemsController = Ember.ArrayController.extend({
87
        type: undefined,
88
        itemController: function(){
89
                var type = this.type;
90
                return type.substring(0, type.length - 1);
91
        }.property(),
92
        icon: function() {
93
                // should this be placed in ElemsView?
94
                return        Synnefo.conf.sectors.findBy('destination', this.get('type')).icon.replace('outline', 'full');
95
        }.property(),
96
        hasOS: function(){
97
                        if(Synnefo.get('currentPath') == "vms")
98
                                return true;
99
                        else return false;
100
        }.property(),
101
                hasTags: function(){
102
                        if(Synnefo.get('currentPath') == "vms")
103
                                return true;
104
                        else return false;
105
        }.property(),
106
});
107

    
108
Synnefo.VmsController = Synnefo.ElemsController.extend({
109
        type: 'vms'
110
});
111

    
112

    
113
Synnefo.NetsController = Synnefo.ElemsController.extend({
114
        type: 'nets'
115
});
116

    
117
Synnefo.VolumesController = Synnefo.ElemsController.extend({
118
        type: 'volumes'
119
});
120

    
121

    
122
Synnefo.SnapshotsController = Synnefo.ElemsController.extend({
123
        type: 'snapshots'
124
});
125

    
126
Synnefo.ImagesController = Synnefo.ElemsController.extend({
127
        type: 'images'
128
});
129

    
130

    
131

    
132
Synnefo.ElemController = Ember.ObjectController.extend({
133
        needs: [],
134
        actionsList: Synnefo.conf.userActions,
135
        setAvailableActions: function() {
136
                var parent = this.needs;
137
                var self = this;
138
                return this.actionsList.filter(function(el) {
139
                        return _.contains(el['snf-components'], self.get('controllers.'+parent).type) &&( _.contains(el['enabled-status'], self.get('model.status')) || _.contains(el['enabled-status'], 'all'));
140
                })
141
        }.property(),
142
        createBtn: false,        
143
        actions: {
144
                shutdown: function(param) {
145
                        console.log(this.get('model.status'));
146
                        this.set('model.status', 'shutting');
147
                },
148
                destroyElement: function(param) {
149
                        var element = this.get('model');
150
                        element.deleteRecord();
151
                        element.save();
152
                }
153
        }
154
});
155

    
156
Synnefo.VmController = Synnefo.ElemController.extend({
157
        needs: ['vms']
158
});
159

    
160
Synnefo.NetController = Synnefo.ElemController.extend({
161
        needs: ['nets']
162
});
163

    
164
Synnefo.VolumeController = Synnefo.ElemController.extend({
165
        needs: ['volumes']
166
});
167

    
168
Synnefo.SnapshotController = Synnefo.ElemController.extend({
169
        needs: ['snapshots']
170
});
171

    
172
Synnefo.ImageController = Synnefo.ElemController.extend({
173
        needs: ['images']
174
});
175

    
176

    
177
/* Views */
178

    
179
Synnefo.NavIconView = Ember.View.extend({
180
        tagName: 'span',
181
        click: function(e) {
182
                var parentEl = this.$().parent('a');
183
                var currentEl = this.$().parents('li').siblings('li').find('a.current');
184

    
185
                ui.replaceClass(currentEl, 'full', 'outline', 'snf-');
186
                ui.replaceClass(parentEl, 'outline', 'full', 'snf-');
187
        }
188

    
189
});
190

    
191
Synnefo.NavigationView = Ember.CollectionView.extend({
192
  tagName: "ul",
193
  classNames: ['icons-nav'],
194

    
195
  content: Synnefo.conf.sectors,
196
  itemViewClass: Ember.View.extend({
197
    templateName: "navigationItem"
198
  }),
199
});
200

    
201

    
202
Synnefo.ElemView = Ember.View.extend({
203
        // templateName: 'elem',
204
        addNewBtn: false,
205
        templateName: 'snfElem',
206
        tagName: 'li',
207
        selectable: true,
208
        initSelect: 'unchecked',
209
        classNameBindings: ['status'],
210
        attributeBindings: ['data-status'],
211
        'data-status': function() {
212
                return this.status;
213
        }.property(),
214
        status: function() {
215
                return this.get('controller.status');
216
        }.property('controller.status')
217
});
218

    
219
Synnefo.ImgWrapView = Ember.View.extend({
220
        templateName: 'img-wrap',
221
        classNames: ['img-wrap'],
222
        icon: function() {
223
                var parentView = this.get('parentView');
224
                var addNewBtn = parentView.get('addNewBtn');
225
                if(addNewBtn)
226
                        return parentView.get('icon');
227
                else
228
                        return parentView.get('controller').get('parentController').get('icon');
229
        }.property()
230
});
231

    
232
Synnefo.NameView = Ember.View.extend({
233
        templateName: 'name',
234
        tagName: 'h4',
235
        name: function() {
236
                // the name may be defined inside the parent view or in its model or controller
237
                return this.get('parentView').get('controller').get('name');
238
        }.property()
239
});
240

    
241
// to be changed
242
Synnefo.ImmediateActionView = Ember.View.extend({
243
        templateName: 'actions',
244
        classNames: ['actions']
245
})
246

    
247
/* Components */
248

    
249
Synnefo.Btn1Component = Ember.Component.extend({
250
        tagName: 'a',
251
        click: function() {
252
                this.sendAction("action", this.get('param'));
253
        }
254
});
255

    
256
Synnefo.AddNewComponent = Ember.Component.extend({
257
        templateName: 'snfElem',
258
        addNewBtn: true,
259
        selectable: false,
260
        icon: function() {
261
                baseIcon = Synnefo.conf.sectors.findBy('destination', this.get('type')).icon;
262
                return        baseIcon.replace('outline', 'create-full');
263
        }.property(),
264
        tagName: 'li',
265
        status: 'add-new',
266
        classNameBindings: ['status'],
267
        attributeBindings: ['data-status, data-reveal-id'],
268
        'data-reveal-id': function(){
269
                if(addNewBtn)
270
                        return /*this.get('type').substring(0, type.length - 1)+*/'-wizard';
271
                else
272
                        return undefined;
273
        }.property(),
274
        'data-status': function() {
275
                return this.status;
276
        }.property(),
277
        name: function() {
278
                var msg = 'Create New ';
279
                var btnType = this.get('type')
280
                switch(btnType){
281
                        case 'vms':
282
                                return msg + 'Machine';
283
                        case 'nets':
284
                                return msg + 'Network';
285
                        case 'volumes':
286
                                return msg + 'Volume';
287
                        case 'snapshots':
288
                                return msg + 'Snapshot';
289
                        case 'images':
290
                                return '+ Upload New Image';
291
                }
292
        }.property(),
293
                click: function (e) {
294
                        console.log('clicked create new');
295
                        console.log($('.wizard').length);
296
                e.preventDefault();
297
                $('.overlay-area-custom').fadeIn(100);
298
                $('body').addClass('with-overlay');
299

    
300
                        $('#vm-wizard').foundation('reveal', 'open');
301
                $('#vm-wizard').fadeIn('slow');
302
                }
303
});
304

    
305
Synnefo.LoginMenuComponent = Ember.Component.extend({
306
        classNames: ['login'],
307
        didInsertElement: function() {
308
                console.log('didInsertElement');
309
                var self = this.$();
310
                self.mouseenter(function(e){
311
                self.find('ul').stop(true, true).slideDown(200);
312
            });
313
            self.mouseleave(function(e){
314
        self.find('ul').stop(true, true).slideUp(200);
315
    });
316

    
317
        }
318
});
319

    
320
Synnefo.SnfCheckboxComponent = Ember.Component.extend({
321
        tagName: 'a',
322
        classNames: ['check'],
323
        templateName: 'components/select-btn',
324
        initState: function() {
325
                return this.get('initState');
326
        }.property(),
327
        didInsertElement: function() {
328
                var el = this.$();
329
                var self =this;
330
                this.setInitClasses();
331
                el.click(function(e) {
332
            e.preventDefault();
333
            e.stopPropagation();
334
            self.changeState(el);
335
            // ui.entitiesActionsEnabled();
336
        });
337
        },
338
        setInitClasses: function() {
339
                var self =this.$();
340
                switch(this.initState){
341
                        case 'unchecked': {
342
                                this.uncheck(self);
343
                                break;
344
                        }
345
                        case 'prechecked': {
346
                                self.find('span').addClass('prechecked')
347
                                this.check(self);
348
                                break;
349
                        }
350
                }
351
        },
352
        // used to be in ui.checkbox
353
        changeState : function(checkbox_link) {
354
        $(checkbox_link).find('.snf-checkbox-unchecked, .snf-checkbox-checked').toggleClass('snf-checkbox-unchecked snf-checkbox-checked');
355
        $(checkbox_link).closest('li').toggleClass('selected');
356
    },
357
    check : function(checkbox_link) {
358
        $(checkbox_link).find('span').removeClass('snf-checkbox-unchecked').addClass('snf-checkbox-checked');
359
        $(checkbox_link).closest('li').addClass('selected');
360
    },
361
    uncheck : function(checkbox_link) {
362
        $(checkbox_link).find('span').removeClass('snf-checkbox-checked').addClass('snf-checkbox-unchecked');
363
        $(checkbox_link).closest('li').removeClass('selected');
364
    },
365

    
366
    reset: function(area) {
367
        $(area).find('.snf-radio-checked').not('.prechecked').toggleClass('snf-radio-checked snf-radio-unchecked');
368
        $(area).find('.snf-radio-unchecked.prechecked').toggleClass('snf-radio-checked snf-radio-unchecked');
369
    },
370
});