Statistics
| Branch: | Tag: | Revision:

root / snf-cyclades-app / synnefo / ui / new_ui / ui / javascripts / okeanos-ember.js @ 49342f82

History | View | Annotate | Download (12.6 kB)

1
/* Init Application */
2

    
3
window.Synnefo = Ember.Application.create({
4
        currentPath: 'vms',
5
         LOG_TRANSITIONS: true, // To have Ember write out transition events to the log (it can be helpful to see exactly what is going on with the router)
6
});
7

    
8
Synnefo.ApplicationAdapter = DS.FixtureAdapter.extend();;Ember.Inflector.inflector.uncountable('account');
9

    
10
Synnefo.Account = DS.Model.extend({
11
        email: DS.attr('string')
12
});
13

    
14
// CHECK can i use a single obj and not an array of obj
15
Synnefo.Account.FIXTURES = {
16
        id: 001,
17
        email: "athina@mail.com"
18
};
19

    
20

    
21

    
22
Synnefo.Vm = DS.Model.extend({
23
        // id: DS.attr('number'),         we do not define it ;)
24
        name: DS.attr('string'),
25
        hostname: DS.attr('string'),
26
        status: DS.attr('string'),
27
        os: DS.attr()
28
});
29

    
30
Synnefo.Vm.FIXTURES =
31
[{
32
        id: 125355,
33
        name: "web-server",
34
        hostname: "user@snf-38389.vm.okeanos.grnet.gr",
35
        status: "running",
36
        os: "kubuntu"
37
},
38
{
39
        id: 12,
40
        name: "another-server",
41
        hostname: "user@snf-33333.vm.okeanos.grnet.gr",
42
        status: "off",
43
        os: "fedora"
44
}];
45

    
46
Synnefo.Network = DS.Model.extend({
47
        name: DS.attr('string'),
48
        status: DS.attr('string'),
49
});
50

    
51
Synnefo.Network.FIXTURES =
52
[{
53
  id: 11,
54
  name: 'Network-1',
55
  status: 'running'
56
},
57
{
58
  id: 22,
59
  name: 'Network-2',
60
  status: 'error'
61
}];
62

    
63

    
64
Synnefo.Volume = DS.Model.extend({
65
  name: DS.attr('string'),
66
  status: DS.attr('string'),
67
});
68

    
69
Synnefo.Volume.FIXTURES =
70
[{
71
  id: 111,
72
  name: 'Volume-1',
73
  status: 'running'
74
},
75
{
76
  id: 222,
77
  name: 'Volume-2',
78
  status: 'building'
79
}];
80

    
81
Synnefo.Snapshot = DS.Model.extend({
82
  name: DS.attr('string'),
83
  status: DS.attr('string'),
84
});
85

    
86
Synnefo.Snapshot.FIXTURES =
87
[{
88
  id: 33,
89
  name: 'Snapshot-1',
90
  status: 'running'
91
},
92
{
93
  id: 44,
94
  name: 'Snapshot-2',
95
  status: 'building'
96
}];
97

    
98

    
99
Synnefo.UserImage = DS.Model.extend({
100
  name: DS.attr('string'),
101
  status: DS.attr('string'),
102
});
103

    
104
Synnefo.UserImage.FIXTURES =
105
[{
106
  id: 55,
107
  name: 'Image-1',
108
  status: 'running'
109
},
110
{
111
  id: 66,
112
  name: 'Image-2',
113
  status: 'running'
114
}];
115

    
116

    
117
Synnefo.conf = {
118
  sectors: [{
119
          destination: "vms",
120
          title: "Virtual Machines",
121
          icon: "snf-pc-outline"
122
  },
123
  {
124
    destination: "networks",
125
    title: "Network",
126
          icon: "snf-network-outline"
127

    
128
  },
129
  {
130
          destination: "volumes",
131
          title: "Volumes",
132
          icon: "snf-volume-outline"
133
  },
134
  {
135
          destination: "pithos",
136
          title: "Pithos",
137
          icon: "snf-pithos-outline"
138
  },
139
  {
140
          destination: "images",
141
          title: "Images",
142
          icon: "snf-image-outline"
143
  },
144
  {
145
          destination: "snapshots",
146
          title: "Snapshots",
147
          icon: "snf-snapshot-outline"
148
  },
149
  {
150
          destination: "ips",
151
          title: "IPs",
152
          icon: "snf-nic-outline"
153
  },
154
  {
155
          destination: "sshkeys",
156
          title: "SSh Keys",
157
          icon: "snf-key-outline"
158
  }],
159

    
160
  userActions: [{
161
    description:'start',
162
    'snf-components':['vms'],
163
    'enabled-status': ['off'],
164
    action: 'is this a function?'
165
  },
166
  {
167
    description:'destroyElement',
168
    'snf-components': ['vms', 'networks'],
169
    'enabled-status': ['all'],
170
    action: 'is this a function?',
171
  },
172
  {
173
    description:'shutdown',
174
    'snf-components': ['vms'],
175
    'enabled-status': ['running'],
176
    action: 'is this a function?'
177
  },
178
  {
179
    description:'add machine',
180
    'snf-components': ['networks'],
181
    'enabled-status': ['active'],
182
    action: 'is this a function?'
183
  },
184
  {
185
    description:'action for all',
186
    'snf-components': ['vms', 'networks'],
187
    'enabled-status': ['all'],
188
    action: 'is this a function?'
189
}]
190
};
191
;/* Mapping */
192

    
193
Synnefo.Router.map(function() {
194
// I defined the above resource to extend its Route
195
this.resource('sections', {'path':'/'});
196
for(var i=0; i<Synnefo.conf.sectors.length; i++)
197
        this.resource(Synnefo.conf.sectors[i].destination, function() {
198
                // this.route('grid');
199
                // this.route('list');
200
                this.route('create');
201
        });
202
});
203

    
204

    
205
/* Routes */
206

    
207
Synnefo.ApplicationRoute = Ember.Route.extend({
208
        model: function() {
209
                return {email: 'athina@mail.com'};
210
        },
211
        redirect: function() {
212
                //  have to set vm navigation icon full
213
                this.transitionTo('vms');
214
        },
215
});
216

    
217
Synnefo.SectionsRoute = Ember.Route.extend({
218
        modelName: undefined,
219
        model: function() {
220
                return this.store.find(this.modelName);
221
        },
222
        renderTemplate: function(controller) {
223
                this.render('snfElems', {controller: controller});
224
        },
225
        actions: {
226
                openWizard: function() {
227
                        var wizardType = this.routeName;
228
                        this.transitionTo(wizardType+'.create')
229
                }
230
        }
231
});
232

    
233
Synnefo.CreateRoute = Ember.Route.extend({
234
        model: function(){
235
                return {name: 'vm-wizard'}
236
        },
237
        renderTemplate: function(controller) {
238
                this.render('wizard',{controller: controller});
239
        }
240
});
241

    
242
Synnefo.VmsRoute = Synnefo.SectionsRoute.extend({
243
        modelName: 'vm'
244
});
245

    
246
Synnefo.NetworksRoute = Synnefo.SectionsRoute.extend({
247
        modelName: 'network'
248
});
249

    
250
Synnefo.VolumesRoute = Synnefo.SectionsRoute.extend({
251
        modelName: 'volume'
252
});
253

    
254
Synnefo.SnapshotsRoute = Synnefo.SectionsRoute.extend({
255
        modelName: 'snapshot'
256
});
257

    
258
Synnefo.ImagesRoute = Synnefo.SectionsRoute.extend({
259
        modelName: 'userImage'
260
});
261

    
262
Synnefo.VmsCreateRoute = Synnefo.CreateRoute.extend({});
263

    
264
Synnefo.NetworksCreateRoute = Synnefo.CreateRoute.extend({});
265

    
266
Synnefo.VolumesCreateRoute = Synnefo.CreateRoute.extend({});
267

    
268
Synnefo.SnapshotsCreateRoute = Synnefo.CreateRoute.extend({});
269

    
270
Synnefo.ImagesCreateRoute = Synnefo.CreateRoute.extend({});
271

    
272

    
273

    
274

    
275
/* Controllers */
276

    
277
Synnefo.ApplicationController = Ember.Controller.extend({
278
        updateCurrentPath: function() {
279
                // we need the set because ElemsController gets the value of current path in every transition
280
                Synnefo.set('currentPath', this.get('currentPath'))
281
                return this.get('currentPath');
282
        }.observes('currentPath'),
283

    
284
        pageTitle : function() {
285
                var currentPath =this.get('currentPath');
286
                if(currentPath!== 'index') return Synnefo.conf.sectors.findBy('destination', this.get('currentPath')).title;
287
                        else return 'Home';
288
        }.property('currentPath'),
289

    
290
        // name: "okeanos application",
291
});
292

    
293

    
294

    
295
Synnefo.ElemsController = Ember.ArrayController.extend({
296
        type: undefined,
297
        itemController: function(){
298
                var type = this.type;
299
                return type.substring(0, type.length - 1);
300
        }.property(),
301
        icon: function() {
302
                // should this be placed in ElemsView?
303
                return        Synnefo.conf.sectors.findBy('destination', this.get('type')).icon.replace('outline', 'full');
304
        }.property(),
305
        hasOS: function(){
306
                        if(Synnefo.get('currentPath') == "vms")
307
                                return true;
308
                        else return false;
309
        }.property(),
310
                hasTags: function(){
311
                        if(Synnefo.get('currentPath') == "vms")
312
                                return true;
313
                        else return false;
314
        }.property(),
315
});
316

    
317
Synnefo.VmsController = Synnefo.ElemsController.extend({
318
        type: 'vms'
319
});
320

    
321

    
322
Synnefo.NetworksController = Synnefo.ElemsController.extend({
323
        type: 'networks'
324
});
325

    
326
Synnefo.VolumesController = Synnefo.ElemsController.extend({
327
        type: 'volumes'
328
});
329

    
330

    
331
Synnefo.SnapshotsController = Synnefo.ElemsController.extend({
332
        type: 'snapshots'
333
});
334

    
335
Synnefo.ImagesController = Synnefo.ElemsController.extend({
336
        type: 'images'
337
});
338

    
339

    
340

    
341
Synnefo.ElemController = Ember.ObjectController.extend({
342
        needs: [],
343
        actionsList: Synnefo.conf.userActions,
344
        setAvailableActions: function() {
345
                var parent = this.needs;
346
                var self = this;
347
                return this.actionsList.filter(function(el) {
348
                        return _.contains(el['snf-components'], self.get('controllers.'+parent).type) &&( _.contains(el['enabled-status'], self.get('model.status')) || _.contains(el['enabled-status'], 'all'));
349
                })
350
        }.property(),
351
        createBtn: false,        
352
        actions: {
353
                shutdown: function(param) {
354
                        this.set('model.status', 'shutting');
355
                },
356
                destroyElement: function(param) {
357
                        var element = this.get('model');
358
                        element.deleteRecord();
359
                        element.save();
360
                }
361
        }
362
});
363

    
364
Synnefo.VmController = Synnefo.ElemController.extend({
365
        needs: ['vms']
366
});
367

    
368
Synnefo.NetworkController = Synnefo.ElemController.extend({
369
        needs: ['networks']
370
});
371

    
372
Synnefo.VolumeController = Synnefo.ElemController.extend({
373
        needs: ['volumes']
374
});
375

    
376
Synnefo.SnapshotController = Synnefo.ElemController.extend({
377
        needs: ['snapshots']
378
});
379

    
380
Synnefo.ImageController = Synnefo.ElemController.extend({
381
        needs: ['images']
382
});
383

    
384

    
385
/* Views */
386

    
387
Synnefo.NavIconView = Ember.View.extend({
388
        tagName: 'span',
389
        click: function(e) {
390
                var parentEl = this.$().parent('a');
391
                var currentEl = this.$().parents('li').siblings('li').find('a.current');
392

    
393
                ui.replaceClass(currentEl, 'full', 'outline', 'snf-');
394
                ui.replaceClass(parentEl, 'outline', 'full', 'snf-');
395
        }
396

    
397
});
398

    
399
Synnefo.NavigationView = Ember.CollectionView.extend({
400
  tagName: "ul",
401
  classNames: ['icons-nav'],
402

    
403
  content: Synnefo.conf.sectors,
404
  itemViewClass: Ember.View.extend({
405
    templateName: "navigationItem"
406
  }),
407
});
408

    
409

    
410
Synnefo.ElemView = Ember.View.extend({
411
        // templateName: 'elem',
412
        addNewBtn: false,
413
        templateName: 'snfElem',
414
        tagName: 'li',
415
        selectable: true,
416
        initSelect: 'unchecked',
417
        classNameBindings: ['status'],
418
        attributeBindings: ['data-status'],
419
        'data-status': function() {
420
                return this.status;
421
        }.property(),
422
        status: function() {
423
                return this.get('controller.status');
424
        }.property('controller.status')
425
});
426

    
427
Synnefo.ImgWrapView = Ember.View.extend({
428
        templateName: 'img-wrap',
429
        classNames: ['img-wrap'],
430
        icon: function() {
431
                var parentView = this.get('parentView');
432
                var addNewBtn = parentView.get('addNewBtn');
433
                if(addNewBtn)
434
                        return parentView.get('icon');
435
                else
436
                        return parentView.get('controller').get('parentController').get('icon');
437
        }.property()
438
});
439

    
440
Synnefo.NameView = Ember.View.extend({
441
        templateName: 'name',
442
        tagName: 'h4',
443
        name: function() {
444
                // the name may be defined inside the parent view or in its model or controller
445
                return this.get('parentView').get('controller').get('name');
446
        }.property()
447
});
448

    
449
// to be changed
450
Synnefo.ImmediateActionView = Ember.View.extend({
451
        templateName: 'actions',
452
        classNames: ['actions']
453
})
454

    
455
/* Components */
456

    
457
Synnefo.Btn1Component = Ember.Component.extend({
458
        tagName: 'a',
459
        click: function() {
460
                this.sendAction("action", this.get('param'));
461
        }
462
});
463

    
464
Synnefo.AddNewComponent = Ember.Component.extend({
465
        templateName: 'snfElem',
466
        addNewBtn: true,
467
        selectable: false,
468
        icon: function() {
469
                baseIcon = Synnefo.conf.sectors.findBy('destination', this.get('type')).icon;
470
                return        baseIcon.replace('outline', 'create-full');
471
        }.property(),
472
        tagName: 'li',
473
        status: 'add-new',
474
        classNameBindings: ['status'],
475
        attributeBindings: ['data-status, data-reveal-id'],
476
        'data-reveal-id': function(){
477
                if(addNewBtn)
478
                        return /*this.get('type').substring(0, type.length - 1)+*/'-wizard';
479
                else
480
                        return undefined;
481
        }.property(),
482
        'data-status': function() {
483
                return this.status;
484
        }.property(),
485
        name: function() {
486
                var msg = 'Create New ';
487
                var btnType = this.get('type')
488
                switch(btnType){
489
                        case 'vms':
490
                                return msg + 'Machine';
491
                        case 'networks':
492
                                return msg + 'Network';
493
                        case 'volumes':
494
                                return msg + 'Volume';
495
                        case 'snapshots':
496
                                return msg + 'Snapshot';
497
                        case 'images':
498
                                return '+ Upload New Image';
499
                }
500
        }.property(),
501
                click: function () {
502
                this.sendAction('action');
503
                }
504
});
505

    
506
Synnefo.LoginMenuComponent = Ember.Component.extend({
507
        classNames: ['login'],
508
        didInsertElement: function() {
509
                var self = this.$();
510
                self.mouseenter(function(e){
511
                self.find('ul').stop(true, true).slideDown(200);
512
            });
513
            self.mouseleave(function(e){
514
        self.find('ul').stop(true, true).slideUp(200);
515
    });
516

    
517
        }
518
});
519

    
520
Synnefo.SnfCheckboxComponent = Ember.Component.extend({
521
        tagName: 'a',
522
        classNames: ['check'],
523
        templateName: 'components/select-btn',
524
        initState: function() {
525
                return this.get('initState');
526
        }.property(),
527
        didInsertElement: function() {
528
                var el = this.$();
529
                var self =this;
530
                this.setInitClasses();
531
                el.click(function(e) {
532
            e.preventDefault();
533
            e.stopPropagation();
534
            self.changeState(el);
535
            // ui.entitiesActionsEnabled();
536
        });
537
        },
538
        setInitClasses: function() {
539
                var self =this.$();
540
                switch(this.initState){
541
                        case 'unchecked': {
542
                                this.uncheck(self);
543
                                break;
544
                        }
545
                        case 'prechecked': {
546
                                self.find('span').addClass('prechecked')
547
                                this.check(self);
548
                                break;
549
                        }
550
                }
551
        },
552
        // used to be in ui.checkbox
553
        changeState : function(checkbox_link) {
554
        $(checkbox_link).find('.snf-checkbox-unchecked, .snf-checkbox-checked').toggleClass('snf-checkbox-unchecked snf-checkbox-checked');
555
        $(checkbox_link).closest('li').toggleClass('selected');
556
    },
557
    check : function(checkbox_link) {
558
        $(checkbox_link).find('span').removeClass('snf-checkbox-unchecked').addClass('snf-checkbox-checked');
559
        $(checkbox_link).closest('li').addClass('selected');
560
    },
561
    uncheck : function(checkbox_link) {
562
        $(checkbox_link).find('span').removeClass('snf-checkbox-checked').addClass('snf-checkbox-unchecked');
563
        $(checkbox_link).closest('li').removeClass('selected');
564
    },
565

    
566
    reset: function(area) {
567
        $(area).find('.snf-radio-checked').not('.prechecked').toggleClass('snf-radio-checked snf-radio-unchecked');
568
        $(area).find('.snf-radio-unchecked.prechecked').toggleClass('snf-radio-checked snf-radio-unchecked');
569
    },
570
});