diff --git a/js/app/models/AmdaNode.js b/js/app/models/AmdaNode.js index 14fc4e5..a3c5236 100644 --- a/js/app/models/AmdaNode.js +++ b/js/app/models/AmdaNode.js @@ -25,7 +25,7 @@ Ext.define('amdaModel.AmdaNode', { ], statics : { - NEW_DIR_NAME : 'new Folder', + NEW_DIR_NAME : 'new_folder', MULTI_PREFIX : 'mult' }, diff --git a/js/app/models/InteractiveNode.js b/js/app/models/InteractiveNode.js index ff3f0fe..8c52229 100644 --- a/js/app/models/InteractiveNode.js +++ b/js/app/models/InteractiveNode.js @@ -167,7 +167,7 @@ Ext.define('amdaModel.InteractiveNode', { isValidName : function(name, callBackFn) { var dataToSend = {name: name, nodeType: this.get('nodeType'), leaf: this.isLeaf()}; - AmdaAction.validNameObject(dataToSend, callBackFn); + AmdaAction.validNameObject(dataToSend, callBackFn); }, /** @@ -696,19 +696,22 @@ Ext.define('amdaModel.InteractiveNode', { * Create Folder */ createDir: function() { + console.log('create folder') var me = this; amdaModel.InteractiveNode.preloadNodes(this.getRootNode(), function() { var newNode = Ext.create(me.$className, { - leaf : false, nodeType : me.get('nodeType'), - text : amdaModel.AmdaNode.NEW_DIR_NAME, + leaf : false, + nodeType : me.get('nodeType'), + text : amdaModel.AmdaNode.NEW_DIR_NAME, children : [] }); // insert the new node as a child of node - newNode = me.insertChild(0, newNode); + // newNode = me.insertChild(0, newNode); + me.insertChild(0, newNode); // start text edition on this new directory node me.expand(false); newNode.expand(false); @@ -737,7 +740,8 @@ Ext.define('amdaModel.InteractiveNode', { }, renameNode: function() - { + { + console.log('renameNode'); if (this.myGetOwnerTree()) { // load the rootNode and recursively all its child nodes if not already loaded diff --git a/js/app/views/ExplorerUI.js b/js/app/views/ExplorerUI.js index 65e5bb2..5935827 100644 --- a/js/app/views/ExplorerUI.js +++ b/js/app/views/ExplorerUI.js @@ -696,58 +696,38 @@ Ext.define('amdaUI.ExplorerUI', { return false; }, field: { - validFlag: false, + validFlag: true, validator : function(value) { - // get explorerModule - var explModule = myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.explorer.id); - var explUI = explModule.getUiContent(); - var activeTreePanel = explUI.getActiveTab(); - - var editedNode = activeTreePanel.getSelectionModel().selected.items[0]; - if (editedNode) { - if (!editedNode.get('id') && value === amdaModel.AmdaNode.NEW_DIR_NAME){ - return false; - } else { - return this.validFlag; - } - } else { - return true; - } + console.log('validator'); + return this.validFlag; }, listeners: { change : function( field, newValue, oldValue, eOpts ) { + console.log('changing...'); var explModule = myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.explorer.id); - var explUI = explModule.getUiContent(); - var activeTreePanel = explUI.getActiveTab(); + var activeTreePanel = explModule.getUiContent().getActiveTab(); var editedNode = activeTreePanel.getSelectionModel().selected.items[0]; if (editedNode) { editedNode.isValidName(newValue, function (res) { - if (!res) - { - field.validFlag = 'Error during object validation'; - field.validate(); - return; - } - if (!res.valid) - { - if (res.error) - { - field.validFlag = res.error; - field.validate(); - return; - } - else - { - field.validFlag = 'Invalid object name'; - field.validate(); - return; + var validFlag = true; + if (!res) { + validFlag = 'Error during object validation'; + } else if (!res.valid) { + if (res.error) { + validFlag = res.error; + } else { + validFlag = 'Invalid object name'; } } - - field.validFlag = true; - field.validate(); + if (validFlag === true) { + // field.fireEvent('validitychange', true); + } else { + field.markInvalid(validFlag); + // field.setValue(oldValue); + // field.fireEvent('validitychange', false, validFlag); + } }); } } @@ -755,16 +735,48 @@ Ext.define('amdaUI.ExplorerUI', { scope: this } }], - //add our custom editor plugin + // add our custom editor plugin plugins: [ new MyTreeEditor({ pluginId: 'treeEditor', listeners: { 'canceledit' : function(editor, context) { - if (editor && editor.startValue===amdaModel.AmdaNode.NEW_DIR_NAME) { + console.log('canceledit event'); + // if (editor && editor.startValue===amdaModel.AmdaNode.NEW_DIR_NAME) { context.record.remove(true); - } - } - } + // } + }, + 'edit': function (editor, e) { + var me = this; + console.log('edit event'); + var explModule = myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.explorer.id); + var activeTreePanel = explModule.getUiContent().getActiveTab(); + + var editedNode = activeTreePanel.getSelectionModel().selected.items[0]; + if (editedNode) { + editedNode.isValidName(e.value, function (res) { + var validFlag = true; + if (!res) { + validFlag = 'Error during object validation'; + } else if (!res.valid) { + if (res.error) { + validFlag = res.error; + } else { + validFlag = 'Invalid object name'; + } + } + if (validFlag === true) { + console.log('valid'); + } else { + console.log('not valid'); + me.cancelEdit(); + } + }); + } + + + } + }, + scope: this })], setNodesVisibility : function(node,forceHide) @@ -987,7 +999,7 @@ Ext.define( 'MyTreeEditor', { edition : { delay: 50, fn : function(view, record, item, index, e){ - view.getHeaderAtIndex(0).field.validFlag = 'Not modified'; + // view.getHeaderAtIndex(0).field.validFlag = 'Not modified'; // call the start edition method me.startEdit(record, view.getHeaderAtIndex(0)); }, @@ -1001,10 +1013,11 @@ Ext.define( 'MyTreeEditor', { * Cancel any active editing. */ cancelEdit: function() { + console.log('cancelEdit'); var me = this, activeEd = me.getActiveEditor(), viewEl = me.grid.getView().getEl(me.getActiveColumn()); - + // console.log('activeEd:', activeEd); me.setActiveEditor(null); me.setActiveColumn(null); me.setActiveRecord(null); @@ -1026,12 +1039,23 @@ Ext.define( 'MyTreeEditor', { me.on({ edit: function(editor,event){ - // if there is a modification + console.log('edited'); + // console.log('grid:', event.grid.validate()); + // console.log('record:', event.record.validate()); + // console.log('field:', event.field); + // console.log('grid:', event.grid.validFlag); + // console.log('record:', event.record.validFlag); + // console.log('field:', event.field.validFlag); + // // console.log('row:', event.row.validFlag); + // console.log('column:', event.column.validFlag); + // me.cancelEdit(); + // if there is a modification if (event.originalValue !== event.value) { // delegate rename action on model event.record.rename(event.value,function(result){ // if a result has been returned : success if(result) { + console.log('renaming, success'); // delegate commit action to delete modification flag event.record.commit(); var rec = event.record.data; @@ -1041,9 +1065,10 @@ Ext.define( 'MyTreeEditor', { rec.id = result.id; } } else { // in case of transaction error + console.log('renaming, oops'); // reset originalValue event.record.value = event.originalValue; - event.record.get('text') = event.originalValue; + event.record.set('text', event.originalValue); event.record.commit(); } }); -- libgit2 0.21.2