Commit 239d9f8f85e3bb998546cd7912d73033b8c05b66

Authored by Erdogan Furkan
1 parent 15c9645b

First Working version

js/app/models/DefaultValuesModel.js
... ... @@ -2,7 +2,7 @@ Ext.define('amdaModel.DefaultValuesModel', {
2 2 extend: 'Ext.data.TreeModel',
3 3 fields: [
4 4 { name: 'parameter', type: 'string'},
5   - { name: 'value', type: 'string'},
  5 + { name: 'value'},
6 6 { name: 'modified', type: 'boolean' },
7 7 { name: 'default'}
8 8 ]
... ...
js/app/views/DefaultTreeGrid.js
... ... @@ -18,11 +18,30 @@ Ext.define('amdaUI.DefaultTreeGrid', {
18 18 multiSelect: true,
19 19 singleExpand: true,
20 20  
  21 + modifiedDefaults : {},
  22 +
21 23 constructor: function() {
22 24 this.init();
23 25 this.callParent();
24 26 },
25 27  
  28 + extractData : function(node=null,parentName = '',) {
  29 + var me =this;
  30 + if(node === null){
  31 + node = me.store.getRootNode();
  32 + }
  33 + if(node.data.leaf && node.data.modified){
  34 + if(node.data.value !== node.data.default){
  35 + me.modifiedDefaults[parentName] = node.data.value;
  36 + }
  37 + }
  38 + else{
  39 + Ext.each(node.childNodes, function(childNode) {
  40 + me.extractData(childNode, (parentName !== '') ? parentName+'.'+childNode.data.parameter : childNode.data.parameter );
  41 + });
  42 + }
  43 + },
  44 +
26 45 isHexCode: function(str) {
27 46 return /^#[0-9a-fA-F]{6}$/.test(str);
28 47 },
... ... @@ -51,7 +70,13 @@ Ext.define('amdaUI.DefaultTreeGrid', {
51 70 }
52 71 },
53 72 afteredit:function(editor, context,e){
54   - console.log(context.record.get('default'));
  73 + if(context.record.get('value') !== context.record.get('default')){
  74 + context.record.set('modified',true);
  75 + }
  76 + else{
  77 + context.record.set('modified',false);
  78 + }
  79 + me.getView().refresh();
55 80 }
56 81 }
57 82 });
... ... @@ -100,18 +125,8 @@ Ext.define('amdaUI.DefaultTreeGrid', {
100 125 parameter = parentNode.get('parameter')+'.'.concat(parameter);
101 126 }
102 127 option = amdaDefaultOptions[parameter+record.get('parameter')];
103   - value = record.get('value');
104   - store = null;
105   - if(me.isHexCode(value)){
106   - fieldType = 'colorpicker'
107   - }
108   - else if(value === 'true' || value == 'false'){
109   - fieldType = 'combobox'
110   - store= [[true, 'true'], [false, 'false']];
111   - }
112   - else{
113   - fieldType = isNaN(parseFloat(record.get('value'))) ? 'textfield' : 'numberfield';
114   - }
  128 + var value = record.get('value');
  129 + var store = null;
115 130  
116 131 if (option && option.type){
117 132 fieldType = option.type;
... ... @@ -122,10 +137,22 @@ Ext.define('amdaUI.DefaultTreeGrid', {
122 137 store = myStore;
123 138  
124 139 }
  140 + else{
  141 + if(me.isHexCode(value)){
  142 + fieldType = 'colorpicker'
  143 + }
  144 + else if(value === true || value === false){
  145 + fieldType = 'combobox'
  146 + store= [[true, 'true'], [false, 'false']];
  147 + }
  148 + else{
  149 + fieldType = isNaN(parseFloat(record.get('value'))) ? 'textfield' : 'numberfield';
  150 + }
  151 + }
125 152 return {
126 153 xtype: fieldType,
127   - store: store,
128   - editable: false, queryMode: 'local',
  154 + store: store,
  155 + queryMode: 'local',
129 156 displayField: 'value',
130 157 valueField: 'key',
131 158 value: (fieldType=='combobox') ? value : null,
... ... @@ -157,6 +184,8 @@ Ext.define('amdaUI.DefaultTreeGrid', {
157 184 icon: 'js/resources/images/16x16/arrow_circle_double.png',
158 185 handler: function(grid, rowIndex, colIndex, actionItem, event, record, row) {
159 186 record.set('value', record.get('default'));
  187 + record.set('modified', false);
  188 + me.getView().refresh();
160 189 },
161 190 // Only leaf level tasks may be edited
162 191 isDisabled: function(view, rowIdx, colIdx, item, record) {
... ... @@ -164,6 +193,9 @@ Ext.define('amdaUI.DefaultTreeGrid', {
164 193 }
165 194 }
166 195 ],
  196 + viewConfig: {
  197 + preserveScrollOnRefresh: true
  198 + }
167 199 });
168 200 }
169 201 });
... ...
js/app/views/DefaultValuesWindow.js
... ... @@ -41,37 +41,28 @@ Ext.define('amdaUI.DefaultValuesWindow',{
41 41 text: 'Save',
42 42 handler: function() {
43 43  
44   - // Check to be sure that max > min
45   -
46   - // if(config.type != "cat"){
47   - // var records = me.statusGrid.store.getRange();
48   - // for (var i = 0; i < records.length; i++) {
49   - // var record = records[i];
50   - // if (record.get('maxVal') < record.get('minVal')) {
51   - // invalidRecord = record;
52   - // break;
53   - // }
54   - // }
55   - // if (invalidRecord) {
56   - // Ext.Msg.alert('Error', 'Max value must be greater than Min value', function() {
57   - // me.statusGrid.cellEditing.startEditByPosition({row: invalidRecord, column: 0});
58   - // invalidRecord = null;
59   - // });
60   - // return;
61   - // }
62   - // }
63   -
64   - // // Saving part
65   -
66   - // config.object.set('status',me.statusGrid.getStatusString());
67   - // me.statusGrid.clearStore();
68   - // me.close();
  44 + me.defaultValuesGrid.modifiedDefaults = {};
  45 + me.defaultValuesGrid.extractData();
  46 + if (Object.keys(me.defaultValuesGrid.modifiedDefaults).length >= 1){
  47 + AmdaAction.setUserDefaultValues(me.defaultValuesGrid.modifiedDefaults, function(res) {
  48 + if(res['success']){
  49 + AmdaAction.getDefaultValueTree(false, function(defaults){
  50 + amdaDefaultValues=defaults;
  51 + });
  52 + me.defaultValuesGrid.removeAll();
  53 + me.defaultValuesGrid.destroy();
  54 + me.close();
  55 + }
  56 + });
  57 + }
69 58 },
70 59 },
71 60 {
72 61 // To quit the window
73 62 text: 'Cancel',
74 63 handler: function() {
  64 + me.defaultValuesGrid.removeAll();
  65 + me.defaultValuesGrid.destroy();
75 66 me.close();
76 67 }
77 68 }]
... ...
php/classes/AmdaAction.php
... ... @@ -1764,8 +1764,6 @@ class AmdaAction
1764 1764 $results = &$json_o; // Use a reference to update the original array
1765 1765 foreach($keys as $parameter){
1766 1766 $results = &$results[$parameter];
1767   -
1768   - error_log(print_r($results,true));
1769 1767 }
1770 1768 if($isTree)
1771 1769 $results = array("value" => $value, "modified" => true, "defaultValue" => $results);
... ... @@ -1793,5 +1791,12 @@ class AmdaAction
1793 1791 }
1794 1792 return $childrenToReturn;
1795 1793 }
  1794 +
  1795 + public function setUserDefaultValues($data){
  1796 + $json_user = json_encode($data, true);
  1797 + file_put_contents(USERDIR.'userDefaults.json',$json_user);
  1798 +
  1799 + return array('success' => true);
  1800 + }
1796 1801 }
1797 1802 ?>
... ...
php/config.php
... ... @@ -209,7 +209,8 @@ $API = array(
209 209 // Default Values options
210 210 'getDefaultValueLinks' => array('len' => 0),
211 211 'getDefaultValueTree' => array('len'=>1),
212   - 'getDefaultValueConfigs' => array('len' => 0)
  212 + 'getDefaultValueConfigs' => array('len' => 0),
  213 + 'setUserDefaultValues' => array('len' => 1)
213 214 )
214 215 )
215 216 );
... ...