Blame view

js/app/views/DefaultTreeGrid.js 8.94 KB
851cf2f0   Erdogan Furkan   For now
1
2
3
4
5
6
7
8
Ext.define('amdaUI.DefaultTreeGrid', {
    extend: 'Ext.tree.Panel',
    
    requires: [
        'Ext.data.*',
        'Ext.grid.*',
        'Ext.tree.*',
        'amdaModel.DefaultValuesModel',
58780dd2   Benjamin Renard   Fix bug with Colo...
9
        'amdaUI.GridColorPicker',
28ce2479   Erdogan Furkan   Last modification...
10
        'amdaUI.ColorMap'
851cf2f0   Erdogan Furkan   For now
11
12
13
14
15
16
17
18
19
20
21
    ],    
    xtype: 'tree-grid',
    
    reserveScrollbar: true,
    
    height: 300,
    useArrows: true,
    rootVisible: false,
    multiSelect: true,
    singleExpand: true,

239d9f8f   Erdogan Furkan   First Working ver...
22
23
    modifiedDefaults : {},

851cf2f0   Erdogan Furkan   For now
24
25
26
27
28
    constructor: function() {
		this.init();
		this.callParent();
	},

28ce2479   Erdogan Furkan   Last modification...
29
30
31
32
33
34
35
36
37
38
39
    getFullParentName:function(record){
        var parentNode = record;
        var parameter ="";
        while (parentNode.parentNode) {
            parentNode = parentNode.parentNode;
            if(parentNode.get('parameter'))
                parameter = parentNode.get('parameter')+'.'.concat(parameter);
        }
        return parameter;
    },

239d9f8f   Erdogan Furkan   First Working ver...
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
    extractData : function(node=null,parentName = '',) {
        var me =this;
        if(node === null){
            node = me.store.getRootNode();
        }
        if(node.data.leaf && node.data.modified){
            if(node.data.value !== node.data.default){
                me.modifiedDefaults[parentName] = node.data.value;
            }
        }
        else{
            Ext.each(node.childNodes, function(childNode) {
                me.extractData(childNode, (parentName !== '') ? parentName+'.'+childNode.data.parameter : childNode.data.parameter );
            });
        }
    },

851cf2f0   Erdogan Furkan   For now
57
58
59
60
61
62
63
64
65
66
67
68
69
70
    isHexCode: function(str) {
        return /^#[0-9a-fA-F]{6}$/.test(str);
    },
    init: function() {
        var me = this;
        me.cellEditing = Ext.create('Ext.grid.plugin.CellEditing', {clicksToEdit: 1,
            listeners:{
                beforeedit:function(editor, context,e){
                    if(!context.record.data.leaf)
                    {
                        return false;
                    }
                    var value = context.record.get(context.field);
                    if (me.isHexCode(value)) {
58780dd2   Benjamin Renard   Fix bug with Colo...
71
                        var colorPicker = Ext.create('amdaUI.GridColorPicker', {
851cf2f0   Erdogan Furkan   For now
72
73
74
75
76
77
78
79
80
81
82
                            pickerField: context.field,
                            value: value,
                            listeners: {
                                select: function(picker, color) {
                                    context.record.set(context.field, '#' + color);
                                    me.getView().refresh();
                                }
                            }
                        });
                        editor.field = colorPicker;
                    }
0e07ef6c   Erdogan Furkan   Keep going
83
84
                },
                afteredit:function(editor, context,e){
239d9f8f   Erdogan Furkan   First Working ver...
85
86
87
88
89
90
91
                    if(context.record.get('value') !== context.record.get('default')){
                        context.record.set('modified',true);
                    }
                    else{
                        context.record.set('modified',false);
                    }
                    me.getView().refresh();
851cf2f0   Erdogan Furkan   For now
92
93
94
                }
            }
        });
851cf2f0   Erdogan Furkan   For now
95
96
97
98
99
100

        Ext.apply(this, {
            store: new Ext.data.TreeStore({
                model: amdaModel.DefaultValuesModel,
                proxy: {
                    type: 'direct',
4f728fd9   Erdogan Furkan   For now 2
101
                    directFn: AmdaAction.getDefaultValueTree   
851cf2f0   Erdogan Furkan   For now
102
103
104
105
				},
                folderSort: true
            }),
            plugins: [me.cellEditing],
4f728fd9   Erdogan Furkan   For now 2
106
107
108
109
110
111
112
113
114
115
116
            columns: [
                {
                    xtype: 'treecolumn', //this is so we know which column will show the tree
                    text: 'Parameters',
                    flex: 2,
                    sortable: true,
                    dataIndex: 'parameter',
                    renderer: function(value, metaData, record) {
                        if (record.get('modified')) {
                            return '<b style="color: blue;">'+value+'</b>';
                        }
851cf2f0   Erdogan Furkan   For now
117
118
                        return value;
                    }
4f728fd9   Erdogan Furkan   For now 2
119
120
121
122
123
124
125
126
127
128
129
130
131
                },{
                    xtype: 'gridcolumn',
                    getEditor: function(record) {
                        var grid = this.up().grid,
                            cellediting = grid.findPlugin('cellediting'),
                            editors = cellediting.editors,
                            editor = editors.getByKey(this.id),
                            fieldType;
                        
                        if (editor) {
                            // Do this to avoid memory leaks
                            editors.remove(editor);
                        }
28ce2479   Erdogan Furkan   Last modification...
132
133

                        var option = amdaDefaultOptions[me.getFullParentName(record)+record.get('parameter')];
239d9f8f   Erdogan Furkan   First Working ver...
134
135
                        var value = record.get('value');
                        var store = null;
4f728fd9   Erdogan Furkan   For now 2
136
137
138

                        if (option && option.type){
                            fieldType = option.type;
58780dd2   Benjamin Renard   Fix bug with Colo...
139
140
                            if (fieldType == 'colorpicker')
                                fieldType = 'gridcolorpicker';
4f728fd9   Erdogan Furkan   For now 2
141
142
143
144
145
146
147
                            var myStore = Ext.create('Ext.data.Store', {
                                fields: ['key', 'value'],
                                data: option.store
                            });
                            store = myStore;

                        }
239d9f8f   Erdogan Furkan   First Working ver...
148
149
                        else{
                            if(me.isHexCode(value)){
58780dd2   Benjamin Renard   Fix bug with Colo...
150
                                fieldType = 'gridcolorpicker'
239d9f8f   Erdogan Furkan   First Working ver...
151
152
153
                            }
                            else if(value === true || value === false){
                                fieldType = 'combobox'
28ce2479   Erdogan Furkan   Last modification...
154
                                store= [[true, 'True'], [false, 'False']];
239d9f8f   Erdogan Furkan   First Working ver...
155
156
157
158
159
                            }
                            else{
                                fieldType = isNaN(parseFloat(record.get('value'))) ? 'textfield' : 'numberfield';
                            }
                        }
4f728fd9   Erdogan Furkan   For now 2
160
161
                        return {
                            xtype: fieldType,
239d9f8f   Erdogan Furkan   First Working ver...
162
163
                            store: store, 
                            queryMode: 'local',
4f728fd9   Erdogan Furkan   For now 2
164
165
166
167
168
169
170
171
172
173
174
                            displayField: 'value',
                            valueField: 'key',
                            value: (fieldType=='combobox') ? value : null,
                            allowBlank: false
                        };
                    },
                    text: 'Values',
                    flex: 1,
                    sortable: true,
                    dataIndex: 'value',
                    align: 'center',
28ce2479   Erdogan Furkan   Last modification...
175
                    renderer: function(value, meta,record) {
4f728fd9   Erdogan Furkan   For now 2
176
177
178
179
180
                        if (me.isHexCode(value)){
                            value = value.substring(1, 7);
                            return '<div style="background-color:#' + value + '; margin-left: auto; \
                                margin-right: auto;width:15px;height:15px;"></div>';
                        }
28ce2479   Erdogan Furkan   Last modification...
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
                        if( record.get('parameter') === 'colorMap'){
                            var iconUrl="";
                            var colorMap = Ext.create('amdaUI.ColorMap');
                            colorMap.data.forEach(function(colorData){
                                if(colorData.key == value ){
                                    iconUrl= colorData.iconUrl;
                                }
                            });
                            return '<div style="background-image:url(' + iconUrl + ');background-size:100%;\
                                    background-repeat:no-repeat; background-position:center; \
                                    font-size:0;width:90px;height:15px;"></div>';
                        }
                        
                        var option = amdaDefaultOptions[me.getFullParentName(record)+record.get('parameter')];

                        if(option){
                            Ext.each(option.store, function(line){
                                if (line.key === value)
                                    value = line.value;
                            })
4f728fd9   Erdogan Furkan   For now 2
201
                        }
28ce2479   Erdogan Furkan   Last modification...
202
                        return value;
4f728fd9   Erdogan Furkan   For now 2
203
204
205
206
207
208
209
210
211
212
                    },
                },{
                    text: 'Reset',
                    width: 55,
                    menuDisabled: true,
                    xtype: 'actioncolumn',
                    tooltip: 'Reset to the default value',
                    align: 'center',
                    icon: 'js/resources/images/16x16/arrow_circle_double.png',
                    handler: function(grid, rowIndex, colIndex, actionItem, event, record, row) {
0e07ef6c   Erdogan Furkan   Keep going
213
                        record.set('value', record.get('default'));
239d9f8f   Erdogan Furkan   First Working ver...
214
215
                        record.set('modified', false);
                        me.getView().refresh();
4f728fd9   Erdogan Furkan   For now 2
216
217
218
                    },
                    // Only leaf level tasks may be edited
                    isDisabled: function(view, rowIdx, colIdx, item, record) {
0e07ef6c   Erdogan Furkan   Keep going
219
                        return !record.data.leaf || !record.data.modified;
4f728fd9   Erdogan Furkan   For now 2
220
                    }
851cf2f0   Erdogan Furkan   For now
221
                }
4f728fd9   Erdogan Furkan   For now 2
222
            ],
239d9f8f   Erdogan Furkan   First Working ver...
223
224
225
            viewConfig: {
                preserveScrollOnRefresh: true
            }
851cf2f0   Erdogan Furkan   For now
226
227
228
        });
    }
});