Statistics
| Branch: | Tag: | Revision:

root / snf-cyclades-app / synnefo / ui / new_ui / ui / javascripts / okeanos-ember / components.js @ 0467b6cd

History | View | Annotate | Download (4.9 kB)

1
/* Components */
2

    
3
Synnefo.Btn1Component = Ember.Component.extend({
4
        tagName: 'a',
5
        click: function() {
6
                this.sendAction("action", this.get('param'));
7
        },
8
        content: undefined // will be set if we want to print a message inside the span
9
});
10

    
11
Synnefo.BtnsSpanComponent = Ember.Component.extend({
12
        tagName: 'a',
13
        templateName: 'components/btns-span',
14
        click: function() {
15
                this.sendAction("action");
16
        }
17
});
18

    
19

    
20

    
21
/* Add New Item */
22

    
23
Synnefo.AddNewComponent = Ember.Component.extend({
24
        templateName: 'snfElem',
25
        addNewBtn: true,
26
        selectable: false,
27
        icon: function() {
28
                baseIcon = Synnefo.conf.sectors.findBy('destination', this.get('type')).icon;
29
                return        baseIcon.replace('outline', 'create-full');
30
        }.property(),
31
        tagName: 'li',
32
        status: 'add-new',
33
        classNameBindings: ['status'],
34
        attributeBindings: ['data-status, data-reveal-id'],
35
        'data-status': function() {
36
                return this.status;
37
        }.property(),
38
        name: function() {
39
                var msg = 'Create New ';
40
                var btnType = this.get('type')
41
                switch(btnType){
42
                        case 'vms':
43
                                return msg + 'Machine';
44
                        case 'networks':
45
                                return msg + 'Network';
46
                        case 'volumes':
47
                                return msg + 'Volume';
48
                        case 'snapshots':
49
                                return msg + 'Snapshot';
50
                        case 'images':
51
                                return '+ Upload New Image';
52
                }
53
        }.property(),
54
                click: function () {
55
                this.sendAction('action');
56
                }
57
});
58

    
59

    
60
/* Login Menu */
61

    
62
Synnefo.LoginMenuComponent = Ember.Component.extend({
63
        classNames: ['login'],
64
        didInsertElement: function() {
65
                var self = this.$();
66
                self.mouseenter(function(e){
67
                self.find('ul').stop(true, true).slideDown(200);
68
            });
69
            self.mouseleave(function(e){
70
        self.find('ul').stop(true, true).slideUp(200);
71
    });
72

    
73
        }
74
});
75

    
76

    
77
/* Checkboxes and Radiobuttons */
78

    
79
Synnefo.SnfCheckboxComponent = Ember.Component.extend({
80
        tagName: 'a',
81
        classNames: ['check'],
82
        templateName: 'components/select-btn',
83
        initState: function() {
84
                return this.get('initState');
85
        }.property(),
86
        didInsertElement: function() {
87
                var el = this.$();
88
                var self =this;
89
                this.setInitClasses();
90
                el.click(function(e) {
91
            e.preventDefault();
92
            e.stopPropagation();
93
            self.changeState(el);
94
            // ui.entitiesActionsEnabled();
95
        });
96
        },
97
        setInitClasses: function() {
98
                var self =this.$();
99
                switch(this.initState){
100
                        case 'unchecked': {
101
                                this.uncheck(self);
102
                                break;
103
                        }
104
                        case 'prechecked': {
105
                                self.find('span').addClass('prechecked')
106
                                this.check(self);
107
                                break;
108
                        }
109
                }
110
        },
111
        // used to be in ui.checkbox
112
        changeState : function(checkbox_link) {
113
        $(checkbox_link).find('.snf-checkbox-unchecked, .snf-checkbox-checked').toggleClass('snf-checkbox-unchecked snf-checkbox-checked');
114
        $(checkbox_link).closest('li').toggleClass('selected');
115
    },
116
    check : function(checkbox_link) {
117
        $(checkbox_link).find('span').removeClass('snf-checkbox-unchecked').addClass('snf-checkbox-checked');
118
        $(checkbox_link).closest('li').addClass('selected');
119
    },
120
    uncheck : function(checkbox_link) {
121
        $(checkbox_link).find('span').removeClass('snf-checkbox-checked').addClass('snf-checkbox-unchecked');
122
        $(checkbox_link).closest('li').removeClass('selected');
123
    },
124

    
125
    reset: function(area) {
126
        $(area).find('.snf-radio-checked').not('.prechecked').toggleClass('snf-radio-checked snf-radio-unchecked');
127
        $(area).find('.snf-radio-unchecked.prechecked').toggleClass('snf-radio-checked snf-radio-unchecked');
128
    },
129
});
130

    
131

    
132
/* Wizard Buttons */
133

    
134
Synnefo.Close1Component = Synnefo.BtnsSpanComponent.extend({
135
        classNames: ['close'],
136
        spanClass: 'snf-close' // has to be modified to array of strings
137
});
138

    
139
        //  there's another close icon to confirm/info modals
140

    
141

    
142
/*
143

144
Back and Next buttons are constructed as views and not as components
145

146
{{cancel-1 action="moveBack" step=currentStep minStep=1}}
147
{{next-1 action="moveNext" step=currentStep maxStep=totalStep}}
148

149
Synnefo.Cancel1Component = Synnefo.BtnsSpanComponent.extend({
150
        // classNameBindings: ['el3'], the element that should be focused when the user goes to the next step
151
        content: 'CANCEL',
152
        click: function(){
153
                var currentStep =this.get('step');
154
                var minStep =this.get('minStep');
155
                console.log('minStep ', minStep);
156
                this.sendAction();
157
                if(currentStep === minStep)
158
                        this.set('content', 'CANCEL');
159
                else
160
                        this.set('content', 'PREVIOUS');
161

162
        }
163

164
//  there's another close to modals
165

166
Synnefo.Cancel1Component = Synnefo.BtnsSpanComponent.extend({
167
        classNames: ['nav', 'prev'],
168
        // classNameBindings: ['el3'], the element that should be focused when the user goes to the next step
169
        content: 'CANCEL'
170
});
171

172
Synnefo.Next1Component = Synnefo.BtnsSpanComponent.extend({
173
        classNames: ['nav', 'next'],
174
        // classNameBindings: ['el3'], the element that should be focused when the user goes to the next step
175
        content: 'NEXT',
176
        click: function() {
177
                var currentStep =this.get('step');
178
                var maxStep =this.get('maxStep');
179
                this.sendAction('action');
180
                if(currentStep === maxStep)
181
                        this.set('content', 'CREATE');
182
                else
183
                        this.set('content', 'NEXT');
184
        }
185
}); */