Statistics
| Branch: | Tag: | Revision:

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

History | View | Annotate | Download (4.8 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();
9

    
10
/* Mapping */
11

    
12
Okeanos.Router.map(function() {
13

    
14
for(var i=0; i<Okeanos.places.length; i++)
15
        this.resource(Okeanos.places[i].destination);
16
});
17

    
18

    
19
/* Routes */
20

    
21
Okeanos.ApplicationRoute = Ember.Route.extend({
22
        model: function() {
23
                
24
                return {email: 'athina@mail.com'};
25
        }
26
});
27

    
28
Okeanos.VmsRoute = Ember.Route.extend({
29
        model: function() {
30
                return this.store.find('vm');
31
        },
32
        renderTemplate: function(controller) {
33
                this.render('snfElems', {controller: controller})
34
        }
35
});
36

    
37
Okeanos.NetsRoute = Ember.Route.extend({
38
        model: function() {
39
                return [{id: '1', name:'net1', status: 'active'}, {id: '2', name:'net2', status: 'error'}];
40
        },
41
        renderTemplate: function(controller) {
42
                this.render('snfElems', {controller: controller})
43
        }
44
});
45

    
46

    
47
/* Controllers */
48

    
49
Okeanos.ApplicationController = Ember.Controller.extend({
50
        updateCurrentPath: function() {
51
                Okeanos.set('currentPath', this.get('currentPath'))
52
                console.log('AppController: CurrentPath ->', this.get('currentPath'));
53
                return this.get('currentPath');
54
        }.observes('currentPath'),
55
        actions: {
56
                test: function() {
57
                        console.log('This is test from Okeanos.ApplicationController');
58
                        return 0;
59
                }
60
        },
61

    
62
        pageTitle : function() {
63
                var currentPath =this.get('currentPath');
64
                if(currentPath!== 'index') return Okeanos.places.findBy('destination', this.get('currentPath')).title;
65
                        else return 'Home';
66
        }.property('currentPath'),
67

    
68
        // name: "okeanos application",
69
});
70

    
71

    
72
Okeanos.ElemsController = Ember.ArrayController.extend({
73
        // ElementController: 'vm',
74
        type: undefined,
75
        itemController: function(){
76
                var type = this.type;
77
                console.log('type ', type.substring(0, type.length - 1))
78
                return type.substring(0, type.length - 1);
79
        }.property(),
80
        icon: function() {
81
                return        Okeanos.places.findBy('destination', this.get('type')).icon.replace('outline', 'full');
82
        }.property(),
83
        iconCreate: function() {
84
                return this.icon.replace('full', 'create-full')
85
        }.property(),
86
        hasOS: function(){
87
                        if(Okeanos.get('currentPath') == "vms")
88
                                return true;
89
                        else return false;
90
        }.property(),
91
});
92

    
93
Okeanos.VmsController = Okeanos.ElemsController.extend({
94
        type: 'vms'
95
});
96

    
97

    
98
Okeanos.NetsController = Okeanos.ElemsController.extend({
99
        type: 'nets'
100
});
101

    
102

    
103
Okeanos.ElemController = Ember.ObjectController.extend({
104
        needs: [],
105
        actionsList: Okeanos.AllActions,
106
        setAvailableActions: function() {
107
                var parent = this.needs;
108
                var self = this;
109
                return this.actionsList.filter(function(el) {
110
                        return _.contains(el['snf-components'], self.get('controllers.'+parent).type) &&( _.contains(el['enabled-status'], self.get('model.status')) || _.contains(el['enabled-status'], 'all'));
111
                })
112
                // return this.actionsList
113
        }.property(),
114
        createBtn: false,        
115
        actions: {
116
                shutdown: function(param) {
117
                        console.log(this.get('model.status'));
118
                        this.set('model.status', 'shutting')
119
                        console.log(this.get('model.status'));
120
                        // this.set('building')
121
                },
122
                destroyElement: function(param) {
123
                        var element = this.get('model');
124
                        element.deleteRecord();
125
                        element.save();
126
                }
127
        }
128
});
129

    
130
Okeanos.VmController = Okeanos.ElemController.extend({
131
        needs: ['vms']
132
});
133

    
134
Okeanos.NetController = Okeanos.ElemController.extend({
135
        needs: ['nets']
136
});
137

    
138

    
139
/* Views */
140

    
141
Okeanos.NavIconView = Ember.View.extend({
142
        tagName: 'span',
143
        click: function(e) {
144
                var parentEl = this.$().parent('a');
145
                var currentEl = this.$().parents('li').siblings('li').find('a.current');
146

    
147
                ui.replaceClass(currentEl, 'full', 'outline', 'snf-');
148
                ui.replaceClass(parentEl, 'outline', 'full', 'snf-');
149
        }
150

    
151
});
152

    
153
Okeanos.NavigationView = Ember.CollectionView.extend({
154
  tagName: "ul",
155
  classNames: ['icons-nav'],
156

    
157
  content: Okeanos.places,
158
  itemViewClass: Ember.View.extend({
159
    template: Ember.TEMPLATES["navigationItem"]
160
  }),
161
});
162

    
163

    
164
Okeanos.ElemView = Ember.View.extend({
165
        // templateName: 'elem',
166
        template: Ember.TEMPLATES['snfElem'],
167
        tagName: 'li',
168
        classNameBindings: ['status'],
169
        attributeBindings: ['data-status'],
170
        'data-status': function() {
171
                return this.status;
172
        }.property(),
173
        status: function() {
174
                return this.get('controller.status');
175
        }.property('controller.status')
176
})
177

    
178

    
179
/* Components */
180

    
181
Okeanos.ActionBtnsSimpleComponent = Ember.Component.extend({
182
        tagName: 'a',
183
        click: function() {
184
                this.sendAction("action", this.get('param'));
185
        }
186
});
187

    
188

    
189
Okeanos.LoginMenuComponent = Ember.Component.extend({
190
        classNames: ['login'],
191
        didInsertElement: function() {
192
                console.log('didInsertElement');
193
                var self = this.$();
194
                self.mouseenter(function(e){
195
                self.find('ul').stop(true, true).slideDown(200);
196
            });
197
            self.mouseleave(function(e){
198
        self.find('ul').stop(true, true).slideUp(200);
199
    });
200

    
201
        }
202
});
203