Statistics
| Branch: | Tag: | Revision:

root / snf-cyclades-app / synnefo / ui / new_ui / ui / javascripts / okeanos-ember.js @ 1b6dd4b5

History | View | Annotate | Download (9.7 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
                // Okeanos.set('currentPath', this.get('currentPath'))
175
                // console.log('AppController: 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
        // ElementController: 'vm',
197
        type: undefined,
198
        itemController: function(){
199
                var type = this.type;
200
                console.log('type ', type.substring(0, type.length - 1))
201
                return type.substring(0, type.length - 1);
202
        }.property(),
203
        icon: function() {
204
                return        Okeanos.places.findBy('destination', this.get('type')).icon.replace('outline', 'full');
205
        }.property(),
206
        hasOS: function(){
207
                        if(Okeanos.get('currentPath') == "vms")
208
                                return true;
209
                        else return false;
210
        }.property(),
211
                hasTags: function(){
212
                        if(Okeanos.get('currentPath') == "vms")
213
                                return true;
214
                        else return false;
215
        }.property(),
216
});
217

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

    
222

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

    
227

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

    
255
Okeanos.VmController = Okeanos.ElemController.extend({
256
        needs: ['vms']
257
});
258

    
259
Okeanos.NetController = Okeanos.ElemController.extend({
260
        needs: ['nets']
261
});
262

    
263

    
264
/* Views */
265

    
266
Okeanos.NavIconView = Ember.View.extend({
267
        tagName: 'span',
268
        click: function(e) {
269
                var parentEl = this.$().parent('a');
270
                var currentEl = this.$().parents('li').siblings('li').find('a.current');
271

    
272
                ui.replaceClass(currentEl, 'full', 'outline', 'snf-');
273
                ui.replaceClass(parentEl, 'outline', 'full', 'snf-');
274
        }
275

    
276
});
277

    
278
Okeanos.NavigationView = Ember.CollectionView.extend({
279
  tagName: "ul",
280
  classNames: ['icons-nav'],
281

    
282
  content: Okeanos.places,
283
  itemViewClass: Ember.View.extend({
284
    template: Ember.TEMPLATES["navigationItem"]
285
  }),
286
});
287

    
288

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

    
306

    
307
// to evala ws view gt thelw na kanw diaxeirisi tou interaction tou xristi
308
Okeanos.ElementSidebarView = Ember.View.extend({
309
        tagName: 'ul',
310
        classNames: ['side-actions'],
311
        template: Ember.TEMPLATES['elementSidebar']
312
});
313

    
314
/* Components */
315

    
316
Okeanos.Btn1Component = Ember.Component.extend({
317
        tagName: 'a',
318
        click: function() {
319
                this.sendAction("action", this.get('param'));
320
        }
321
});
322

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

    
347
});
348

    
349
Okeanos.LoginMenuComponent = Ember.Component.extend({
350
        classNames: ['login'],
351
        didInsertElement: function() {
352
                console.log('didInsertElement');
353
                var self = this.$();
354
                self.mouseenter(function(e){
355
                self.find('ul').stop(true, true).slideDown(200);
356
            });
357
            self.mouseleave(function(e){
358
        self.find('ul').stop(true, true).slideUp(200);
359
    });
360

    
361
        }
362
});
363

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

    
411
    reset: function(area) {
412
        $(area).find('.snf-radio-checked').not('.prechecked').toggleClass('snf-radio-checked snf-radio-unchecked');
413
        $(area).find('.snf-radio-unchecked.prechecked').toggleClass('snf-radio-checked snf-radio-unchecked');
414
    },
415
});