Statistics
| Branch: | Tag: | Revision:

root / snf-cyclades-app / synnefo / ui / new_ui / ui / javascripts / okeanos-ember.js @ 3342f8ce

History | View | Annotate | Download (9.9 kB)

1
/* Init Application */
2

    
3
window.Okeanos = 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
Okeanos.ApplicationAdapter = DS.FixtureAdapter.extend();;Ember.Inflector.inflector.uncountable('account');
9

    
10
Okeanos.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
Okeanos.Account.FIXTURES = {
16
        id: 001,
17
        email: "athina@mail.com"
18
};
19

    
20

    
21

    
22
Okeanos.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
Okeanos.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
Okeanos.Net = DS.Model.extend({
47
        name: DS.attr('string'),
48
        status: DS.attr('string'),
49
        vms: DS.attr(),
50
        ips: DS.attr()
51
});
52

    
53
Okeanos.Net.FIXTURES = 
54
[{
55
        
56
}];
57

    
58

    
59

    
60

    
61
Okeanos.places = [{
62
          destination: "vms",
63
          title: "Virtual Machines",
64
          icon: "snf-pc-outline"
65
  },
66
  {
67
          destination: "nets",
68
          title: "Network",
69
          icon: "snf-network-outline"
70

    
71
  },
72
  {
73
          destination: "volumes",
74
          title: "Volumes",
75
          icon: "snf-volume-outline"
76
  },
77
  {
78
          destination: "pithos",
79
          title: "Pithos",
80
          icon: "snf-pithos-outline"
81
  },
82
  {
83
          destination: "images",
84
          title: "Images",
85
          icon: "snf-image-outline"
86
  },
87
  {
88
          destination: "snapshots",
89
          title: "Snapshots",
90
          icon: "snf-snapshot-outline"
91
  },
92
  {
93
          destination: "ips",
94
          title: "IPs",
95
          icon: "snf-nic-outline"
96
  },
97
  {
98
          destination: "sshkeys",
99
          title: "SSh Keys",
100
          icon: "snf-key-outline"
101
  }];
102

    
103

    
104
  Okeanos.AllActions = [{
105
          description:'start',
106
          'snf-components':['vms'],
107
          'enabled-status': ['off'],
108
          action: 'is this a function?'
109
},
110
 {
111
         description:'destroyElement',
112
         'snf-components': ['vms', 'nets'],
113
         'enabled-status': ['all'],
114
         action: 'is this a function?',
115
},
116
{
117
         description:'shutdown',
118
         'snf-components': ['vms'],
119
         'enabled-status': ['running'],
120
         action: 'is this a function?'
121
},
122
{
123
         description:'add machine',
124
         'snf-components': ['nets'],
125
         'enabled-status': ['active'],
126
         action: 'is this a function?'
127
},
128
{
129
         description:'action for all',
130
         'snf-components': ['vms', 'nets'],
131
         'enabled-status': ['all'],
132
         action: 'is this a function?'
133
}];/* Mapping */
134

    
135
Okeanos.Router.map(function() {
136

    
137
for(var i=0; i<Okeanos.places.length; i++)
138
        this.resource(Okeanos.places[i].destination);
139
});
140

    
141

    
142
/* Routes */
143

    
144
Okeanos.ApplicationRoute = Ember.Route.extend({
145
        model: function() {
146
                
147
                return {email: 'athina@mail.com'};
148
        }
149
});
150

    
151
Okeanos.VmsRoute = Ember.Route.extend({
152
        model: function() {
153
                return this.store.find('vm');
154
        },
155
        renderTemplate: function(controller) {
156
                this.render('snfElems', {controller: controller})
157
        }
158
});
159

    
160
Okeanos.NetsRoute = Ember.Route.extend({
161
        model: function() {
162
                return [{id: '1', name:'net1', status: 'active'}, {id: '2', name:'net2', status: 'error'}];
163
        },
164
        renderTemplate: function(controller) {
165
                this.render('snfElems', {controller: controller})
166
        }
167
});
168

    
169

    
170
/* Controllers */
171

    
172
Okeanos.ApplicationController = Ember.Controller.extend({
173
        updateCurrentPath: function() {
174
                // we need the set because ElemsController gets the value of current path in every transition
175
                Okeanos.set('currentPath', this.get('currentPath'))
176
                return this.get('currentPath');
177
        }.observes('currentPath'),
178
        actions: {
179
                test: function() {
180
                        console.log('This is test from Okeanos.ApplicationController');
181
                        return 0;
182
                }
183
        },
184

    
185
        pageTitle : function() {
186
                var currentPath =this.get('currentPath');
187
                if(currentPath!== 'index') return Okeanos.places.findBy('destination', this.get('currentPath')).title;
188
                        else return 'Home';
189
        }.property('currentPath'),
190

    
191
        // name: "okeanos application",
192
});
193

    
194

    
195
Okeanos.ElemsController = Ember.ArrayController.extend({
196
        type: undefined,
197
        itemController: function(){
198
                var type = this.type;
199
                return type.substring(0, type.length - 1);
200
        }.property(),
201
        icon: function() {
202
                return        Okeanos.places.findBy('destination', this.get('type')).icon.replace('outline', 'full');
203
        }.property(),
204
        hasOS: function(){
205
                        if(Okeanos.get('currentPath') == "vms")
206
                                return true;
207
                        else return false;
208
        }.property(),
209
                hasTags: function(){
210
                        if(Okeanos.get('currentPath') == "vms")
211
                                return true;
212
                        else return false;
213
        }.property(),
214
});
215

    
216
Okeanos.VmsController = Okeanos.ElemsController.extend({
217
        type: 'vms'
218
});
219

    
220

    
221
Okeanos.NetsController = Okeanos.ElemsController.extend({
222
        type: 'nets'
223
});
224

    
225

    
226
Okeanos.ElemController = Ember.ObjectController.extend({
227
        needs: [],
228
        actionsList: Okeanos.AllActions,
229
        setAvailableActions: function() {
230
                var parent = this.needs;
231
                var self = this;
232
                return this.actionsList.filter(function(el) {
233
                        return _.contains(el['snf-components'], self.get('controllers.'+parent).type) &&( _.contains(el['enabled-status'], self.get('model.status')) || _.contains(el['enabled-status'], 'all'));
234
                })
235
        }.property(),
236
        createBtn: false,        
237
        actions: {
238
                shutdown: function(param) {
239
                        console.log(this.get('model.status'));
240
                        this.set('model.status', 'shutting');
241
                },
242
                destroyElement: function(param) {
243
                        var element = this.get('model');
244
                        element.deleteRecord();
245
                        element.save();
246
                }
247
        }
248
});
249

    
250
Okeanos.VmController = Okeanos.ElemController.extend({
251
        needs: ['vms']
252
});
253

    
254
Okeanos.NetController = Okeanos.ElemController.extend({
255
        needs: ['nets']
256
});
257

    
258

    
259
/* Views */
260

    
261
Okeanos.NavIconView = Ember.View.extend({
262
        tagName: 'span',
263
        click: function(e) {
264
                var parentEl = this.$().parent('a');
265
                var currentEl = this.$().parents('li').siblings('li').find('a.current');
266

    
267
                ui.replaceClass(currentEl, 'full', 'outline', 'snf-');
268
                ui.replaceClass(parentEl, 'outline', 'full', 'snf-');
269
        }
270

    
271
});
272

    
273
Okeanos.NavigationView = Ember.CollectionView.extend({
274
  tagName: "ul",
275
  classNames: ['icons-nav'],
276

    
277
  content: Okeanos.places,
278
  itemViewClass: Ember.View.extend({
279
    template: Ember.TEMPLATES["navigationItem"]
280
  }),
281
});
282

    
283

    
284
Okeanos.ElemView = Ember.View.extend({
285
        // templateName: 'elem',
286
        addNewBtn: false,
287
        template: Ember.TEMPLATES['snfElem'],
288
        tagName: 'li',
289
        selectable: true,
290
        initSelect: 'unchecked',
291
        classNameBindings: ['status'],
292
        attributeBindings: ['data-status'],
293
        'data-status': function() {
294
                return this.status;
295
        }.property(),
296
        status: function() {
297
                return this.get('controller.status');
298
        }.property('controller.status')
299
});
300

    
301
Okeanos.ImgWrapView = Ember.View.extend({
302
        template: Ember.TEMPLATES['img-wrap'],
303
        classNames: ['img-wrap'],
304
        icon: function() {
305
                var addNewBtn = this.get('parentView').get('addNewBtn');
306
                console.log('addNewBtn: ' + addNewBtn);
307
                if(addNewBtn)
308
                        return this.get('parentView').get('icon');
309
                else
310
                        return this.get('parentView').get('controller').get('parentController').get('icon');
311
        }.property()
312
});
313

    
314

    
315
// to evala ws view gt thelw na kanw diaxeirisi tou interaction tou xristi
316
Okeanos.ElementSidebarView = Ember.View.extend({
317
        tagName: 'ul',
318
        classNames: ['side-actions'],
319
        template: Ember.TEMPLATES['elementSidebar']
320
});
321

    
322
/* Components */
323

    
324
Okeanos.Btn1Component = Ember.Component.extend({
325
        tagName: 'a',
326
        click: function() {
327
                this.sendAction("action", this.get('param'));
328
        }
329
});
330

    
331
Okeanos.AddNewComponent = Ember.Component.extend({
332
        template: Ember.TEMPLATES['snfElem'],
333
        addNewBtn: true,
334
        selectable: false,
335
        icon: function() {
336
                baseIcon = Okeanos.places.findBy('destination', this.get('type')).icon;
337
                return        baseIcon.replace('outline', 'create-full');
338
        }.property(),
339
        tagName: 'li',
340
        status: 'add-new',
341
        classNameBindings: ['status'],
342
        attributeBindings: ['data-status'],
343
        'data-status': function() {
344
                return this.status;
345
        }.property(),
346
        name: function() {
347
                var msg = 'Add New ';
348
                var btnType = this.get('type')
349
                if(btnType === 'vms')
350
                        return msg + 'Machine';
351
                else if(btnType === 'nets')
352
                        return msg + 'Network';
353
        }.property()
354

    
355
});
356

    
357
Okeanos.LoginMenuComponent = Ember.Component.extend({
358
        classNames: ['login'],
359
        didInsertElement: function() {
360
                console.log('didInsertElement');
361
                var self = this.$();
362
                self.mouseenter(function(e){
363
                self.find('ul').stop(true, true).slideDown(200);
364
            });
365
            self.mouseleave(function(e){
366
        self.find('ul').stop(true, true).slideUp(200);
367
    });
368

    
369
        }
370
});
371

    
372
Okeanos.SnfCheckboxComponent = Ember.Component.extend({
373
        tagName: 'a',
374
        classNames: ['check'],
375
        initState: function() {
376
                return this.get('initState');
377
        }.property(),
378
        template: Ember.TEMPLATES['snf-checkbox'],
379
        didInsertElement: function() {
380
                var domRef = this.$();
381
                var self =this;
382
                this.setInitClasses();
383
                domRef.click(function(e) {
384
            e.preventDefault();
385
            e.stopPropagation();
386
            self.changeState(domRef);
387
            // ui.entitiesActionsEnabled();
388
            console.log(self.get('elementID'))
389
        });
390
        },
391
        setInitClasses: function() {
392
                var self =this.$();
393
                switch(this.initState){
394
                        case 'unchecked': {
395
                                this.uncheck(self);
396
                                break;
397
                        }
398
                        case 'prechecked': {
399
                                self.find('span').addClass('prechecked')
400
                                this.check(self);
401
                                break;
402
                        }
403
                }
404
        },
405
        // used to be in ui.checkbox
406
        changeState : function(checkbox_link) {
407
        $(checkbox_link).find('.snf-checkbox-unchecked, .snf-checkbox-checked').toggleClass('snf-checkbox-unchecked snf-checkbox-checked');
408
        $(checkbox_link).closest('li').toggleClass('selected');
409
    },
410
    check : function(checkbox_link) {
411
        $(checkbox_link).find('span').removeClass('snf-checkbox-unchecked').addClass('snf-checkbox-checked');
412
        $(checkbox_link).closest('li').addClass('selected');
413
    },
414
    uncheck : function(checkbox_link) {
415
        $(checkbox_link).find('span').removeClass('snf-checkbox-checked').addClass('snf-checkbox-unchecked');
416
        $(checkbox_link).closest('li').removeClass('selected');
417
    },
418

    
419
    reset: function(area) {
420
        $(area).find('.snf-radio-checked').not('.prechecked').toggleClass('snf-radio-checked snf-radio-unchecked');
421
        $(area).find('.snf-radio-unchecked.prechecked').toggleClass('snf-radio-checked snf-radio-unchecked');
422
    },
423
});