diff --git a/js/app/models/DefaultValuesModel.js b/js/app/models/DefaultValuesModel.js index b132f78..55048f4 100644 --- a/js/app/models/DefaultValuesModel.js +++ b/js/app/models/DefaultValuesModel.js @@ -2,7 +2,7 @@ Ext.define('amdaModel.DefaultValuesModel', { extend: 'Ext.data.TreeModel', fields: [ { name: 'parameter', type: 'string'}, - { name: 'value', type: 'string'}, + { name: 'value'}, { name: 'modified', type: 'boolean' }, { name: 'default'} ] diff --git a/js/app/views/DefaultTreeGrid.js b/js/app/views/DefaultTreeGrid.js index 7c745b9..ef85755 100644 --- a/js/app/views/DefaultTreeGrid.js +++ b/js/app/views/DefaultTreeGrid.js @@ -18,11 +18,30 @@ Ext.define('amdaUI.DefaultTreeGrid', { multiSelect: true, singleExpand: true, + modifiedDefaults : {}, + constructor: function() { this.init(); this.callParent(); }, + 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 ); + }); + } + }, + isHexCode: function(str) { return /^#[0-9a-fA-F]{6}$/.test(str); }, @@ -51,7 +70,13 @@ Ext.define('amdaUI.DefaultTreeGrid', { } }, afteredit:function(editor, context,e){ - console.log(context.record.get('default')); + if(context.record.get('value') !== context.record.get('default')){ + context.record.set('modified',true); + } + else{ + context.record.set('modified',false); + } + me.getView().refresh(); } } }); @@ -100,18 +125,8 @@ Ext.define('amdaUI.DefaultTreeGrid', { parameter = parentNode.get('parameter')+'.'.concat(parameter); } option = amdaDefaultOptions[parameter+record.get('parameter')]; - value = record.get('value'); - store = null; - if(me.isHexCode(value)){ - fieldType = 'colorpicker' - } - else if(value === 'true' || value == 'false'){ - fieldType = 'combobox' - store= [[true, 'true'], [false, 'false']]; - } - else{ - fieldType = isNaN(parseFloat(record.get('value'))) ? 'textfield' : 'numberfield'; - } + var value = record.get('value'); + var store = null; if (option && option.type){ fieldType = option.type; @@ -122,10 +137,22 @@ Ext.define('amdaUI.DefaultTreeGrid', { store = myStore; } + else{ + if(me.isHexCode(value)){ + fieldType = 'colorpicker' + } + else if(value === true || value === false){ + fieldType = 'combobox' + store= [[true, 'true'], [false, 'false']]; + } + else{ + fieldType = isNaN(parseFloat(record.get('value'))) ? 'textfield' : 'numberfield'; + } + } return { xtype: fieldType, - store: store, - editable: false, queryMode: 'local', + store: store, + queryMode: 'local', displayField: 'value', valueField: 'key', value: (fieldType=='combobox') ? value : null, @@ -157,6 +184,8 @@ Ext.define('amdaUI.DefaultTreeGrid', { icon: 'js/resources/images/16x16/arrow_circle_double.png', handler: function(grid, rowIndex, colIndex, actionItem, event, record, row) { record.set('value', record.get('default')); + record.set('modified', false); + me.getView().refresh(); }, // Only leaf level tasks may be edited isDisabled: function(view, rowIdx, colIdx, item, record) { @@ -164,6 +193,9 @@ Ext.define('amdaUI.DefaultTreeGrid', { } } ], + viewConfig: { + preserveScrollOnRefresh: true + } }); } }); diff --git a/js/app/views/DefaultValuesWindow.js b/js/app/views/DefaultValuesWindow.js index 0dbf48e..1b7b935 100644 --- a/js/app/views/DefaultValuesWindow.js +++ b/js/app/views/DefaultValuesWindow.js @@ -41,37 +41,28 @@ Ext.define('amdaUI.DefaultValuesWindow',{ text: 'Save', handler: function() { - // Check to be sure that max > min - - // if(config.type != "cat"){ - // var records = me.statusGrid.store.getRange(); - // for (var i = 0; i < records.length; i++) { - // var record = records[i]; - // if (record.get('maxVal') < record.get('minVal')) { - // invalidRecord = record; - // break; - // } - // } - // if (invalidRecord) { - // Ext.Msg.alert('Error', 'Max value must be greater than Min value', function() { - // me.statusGrid.cellEditing.startEditByPosition({row: invalidRecord, column: 0}); - // invalidRecord = null; - // }); - // return; - // } - // } - - // // Saving part - - // config.object.set('status',me.statusGrid.getStatusString()); - // me.statusGrid.clearStore(); - // me.close(); + me.defaultValuesGrid.modifiedDefaults = {}; + me.defaultValuesGrid.extractData(); + if (Object.keys(me.defaultValuesGrid.modifiedDefaults).length >= 1){ + AmdaAction.setUserDefaultValues(me.defaultValuesGrid.modifiedDefaults, function(res) { + if(res['success']){ + AmdaAction.getDefaultValueTree(false, function(defaults){ + amdaDefaultValues=defaults; + }); + me.defaultValuesGrid.removeAll(); + me.defaultValuesGrid.destroy(); + me.close(); + } + }); + } }, }, { // To quit the window text: 'Cancel', handler: function() { + me.defaultValuesGrid.removeAll(); + me.defaultValuesGrid.destroy(); me.close(); } }] diff --git a/php/classes/AmdaAction.php b/php/classes/AmdaAction.php index 63232e5..50ac821 100644 --- a/php/classes/AmdaAction.php +++ b/php/classes/AmdaAction.php @@ -1764,8 +1764,6 @@ class AmdaAction $results = &$json_o; // Use a reference to update the original array foreach($keys as $parameter){ $results = &$results[$parameter]; - - error_log(print_r($results,true)); } if($isTree) $results = array("value" => $value, "modified" => true, "defaultValue" => $results); @@ -1793,5 +1791,12 @@ class AmdaAction } return $childrenToReturn; } + + public function setUserDefaultValues($data){ + $json_user = json_encode($data, true); + file_put_contents(USERDIR.'userDefaults.json',$json_user); + + return array('success' => true); + } } ?> diff --git a/php/config.php b/php/config.php index fd4d30d..2a45aff 100644 --- a/php/config.php +++ b/php/config.php @@ -209,7 +209,8 @@ $API = array( // Default Values options 'getDefaultValueLinks' => array('len' => 0), 'getDefaultValueTree' => array('len'=>1), - 'getDefaultValueConfigs' => array('len' => 0) + 'getDefaultValueConfigs' => array('len' => 0), + 'setUserDefaultValues' => array('len' => 1) ) ) ); -- libgit2 0.21.2