Commit 65ac4a9d48a44ca3a4adfef93bdedaa3505ab73f

Authored by Nathanaël Jourdane
1 parent 46ac3264

Fix folders debugging (wip)

js/app/models/AmdaNode.js
... ... @@ -25,7 +25,7 @@ Ext.define('amdaModel.AmdaNode', {
25 25 ],
26 26  
27 27 statics : {
28   - NEW_DIR_NAME : 'new Folder',
  28 + NEW_DIR_NAME : 'new_folder',
29 29 MULTI_PREFIX : 'mult'
30 30 },
31 31  
... ...
js/app/models/InteractiveNode.js
... ... @@ -167,7 +167,7 @@ Ext.define('amdaModel.InteractiveNode', {
167 167 isValidName : function(name, callBackFn)
168 168 {
169 169 var dataToSend = {name: name, nodeType: this.get('nodeType'), leaf: this.isLeaf()};
170   - AmdaAction.validNameObject(dataToSend, callBackFn);
  170 + AmdaAction.validNameObject(dataToSend, callBackFn);
171 171 },
172 172  
173 173 /**
... ... @@ -696,19 +696,22 @@ Ext.define('amdaModel.InteractiveNode', {
696 696 * Create Folder
697 697 */
698 698 createDir: function() {
  699 + console.log('create folder')
699 700 var me = this;
700 701 amdaModel.InteractiveNode.preloadNodes(this.getRootNode(),
701 702 function()
702 703 {
703 704 var newNode = Ext.create(me.$className,
704 705 {
705   - leaf : false, nodeType : me.get('nodeType'),
706   - text : amdaModel.AmdaNode.NEW_DIR_NAME,
  706 + leaf : false,
  707 + nodeType : me.get('nodeType'),
  708 + text : amdaModel.AmdaNode.NEW_DIR_NAME,
707 709 children : []
708 710 });
709 711  
710 712 // insert the new node as a child of node
711   - newNode = me.insertChild(0, newNode);
  713 + // newNode = me.insertChild(0, newNode);
  714 + me.insertChild(0, newNode);
712 715 // start text edition on this new directory node
713 716 me.expand(false);
714 717 newNode.expand(false);
... ... @@ -737,7 +740,8 @@ Ext.define('amdaModel.InteractiveNode', {
737 740 },
738 741  
739 742 renameNode: function()
740   - {
  743 + {
  744 + console.log('renameNode');
741 745 if (this.myGetOwnerTree())
742 746 {
743 747 // load the rootNode and recursively all its child nodes if not already loaded
... ...
js/app/views/ExplorerUI.js
... ... @@ -696,58 +696,38 @@ Ext.define('amdaUI.ExplorerUI', {
696 696 return false;
697 697 },
698 698 field: {
699   - validFlag: false,
  699 + validFlag: true,
700 700 validator : function(value) {
701   - // get explorerModule
702   - var explModule = myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.explorer.id);
703   - var explUI = explModule.getUiContent();
704   - var activeTreePanel = explUI.getActiveTab();
705   -
706   - var editedNode = activeTreePanel.getSelectionModel().selected.items[0];
707   - if (editedNode) {
708   - if (!editedNode.get('id') && value === amdaModel.AmdaNode.NEW_DIR_NAME){
709   - return false;
710   - } else {
711   - return this.validFlag;
712   - }
713   - } else {
714   - return true;
715   - }
  701 + console.log('validator');
  702 + return this.validFlag;
716 703 },
717 704 listeners: {
718 705 change : function( field, newValue, oldValue, eOpts )
719 706 {
  707 + console.log('changing...');
720 708 var explModule = myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.explorer.id);
721   - var explUI = explModule.getUiContent();
722   - var activeTreePanel = explUI.getActiveTab();
  709 + var activeTreePanel = explModule.getUiContent().getActiveTab();
723 710  
724 711 var editedNode = activeTreePanel.getSelectionModel().selected.items[0];
725 712 if (editedNode) {
726 713 editedNode.isValidName(newValue, function (res) {
727   - if (!res)
728   - {
729   - field.validFlag = 'Error during object validation';
730   - field.validate();
731   - return;
732   - }
733   - if (!res.valid)
734   - {
735   - if (res.error)
736   - {
737   - field.validFlag = res.error;
738   - field.validate();
739   - return;
740   - }
741   - else
742   - {
743   - field.validFlag = 'Invalid object name';
744   - field.validate();
745   - return;
  714 + var validFlag = true;
  715 + if (!res) {
  716 + validFlag = 'Error during object validation';
  717 + } else if (!res.valid) {
  718 + if (res.error) {
  719 + validFlag = res.error;
  720 + } else {
  721 + validFlag = 'Invalid object name';
746 722 }
747 723 }
748   -
749   - field.validFlag = true;
750   - field.validate();
  724 + if (validFlag === true) {
  725 + // field.fireEvent('validitychange', true);
  726 + } else {
  727 + field.markInvalid(validFlag);
  728 + // field.setValue(oldValue);
  729 + // field.fireEvent('validitychange', false, validFlag);
  730 + }
751 731 });
752 732 }
753 733 }
... ... @@ -755,16 +735,48 @@ Ext.define('amdaUI.ExplorerUI', {
755 735 scope: this
756 736 }
757 737 }],
758   - //add our custom editor plugin
  738 + // add our custom editor plugin
759 739 plugins: [ new MyTreeEditor({
760 740 pluginId: 'treeEditor',
761 741 listeners: {
762 742 'canceledit' : function(editor, context) {
763   - if (editor && editor.startValue===amdaModel.AmdaNode.NEW_DIR_NAME) {
  743 + console.log('canceledit event');
  744 + // if (editor && editor.startValue===amdaModel.AmdaNode.NEW_DIR_NAME) {
764 745 context.record.remove(true);
765   - }
766   - }
767   - }
  746 + // }
  747 + },
  748 + 'edit': function (editor, e) {
  749 + var me = this;
  750 + console.log('edit event');
  751 + var explModule = myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.explorer.id);
  752 + var activeTreePanel = explModule.getUiContent().getActiveTab();
  753 +
  754 + var editedNode = activeTreePanel.getSelectionModel().selected.items[0];
  755 + if (editedNode) {
  756 + editedNode.isValidName(e.value, function (res) {
  757 + var validFlag = true;
  758 + if (!res) {
  759 + validFlag = 'Error during object validation';
  760 + } else if (!res.valid) {
  761 + if (res.error) {
  762 + validFlag = res.error;
  763 + } else {
  764 + validFlag = 'Invalid object name';
  765 + }
  766 + }
  767 + if (validFlag === true) {
  768 + console.log('valid');
  769 + } else {
  770 + console.log('not valid');
  771 + me.cancelEdit();
  772 + }
  773 + });
  774 + }
  775 +
  776 +
  777 + }
  778 + },
  779 + scope: this
768 780 })],
769 781  
770 782 setNodesVisibility : function(node,forceHide)
... ... @@ -987,7 +999,7 @@ Ext.define( 'MyTreeEditor', {
987 999 edition : {
988 1000 delay: 50,
989 1001 fn : function(view, record, item, index, e){
990   - view.getHeaderAtIndex(0).field.validFlag = 'Not modified';
  1002 + // view.getHeaderAtIndex(0).field.validFlag = 'Not modified';
991 1003 // call the start edition method
992 1004 me.startEdit(record, view.getHeaderAtIndex(0));
993 1005 },
... ... @@ -1001,10 +1013,11 @@ Ext.define( 'MyTreeEditor', {
1001 1013 * Cancel any active editing.
1002 1014 */
1003 1015 cancelEdit: function() {
  1016 + console.log('cancelEdit');
1004 1017 var me = this,
1005 1018 activeEd = me.getActiveEditor(),
1006 1019 viewEl = me.grid.getView().getEl(me.getActiveColumn());
1007   -
  1020 + // console.log('activeEd:', activeEd);
1008 1021 me.setActiveEditor(null);
1009 1022 me.setActiveColumn(null);
1010 1023 me.setActiveRecord(null);
... ... @@ -1026,12 +1039,23 @@ Ext.define( 'MyTreeEditor', {
1026 1039  
1027 1040 me.on({
1028 1041 edit: function(editor,event){
1029   - // if there is a modification
  1042 + console.log('edited');
  1043 + // console.log('grid:', event.grid.validate());
  1044 + // console.log('record:', event.record.validate());
  1045 + // console.log('field:', event.field);
  1046 + // console.log('grid:', event.grid.validFlag);
  1047 + // console.log('record:', event.record.validFlag);
  1048 + // console.log('field:', event.field.validFlag);
  1049 + // // console.log('row:', event.row.validFlag);
  1050 + // console.log('column:', event.column.validFlag);
  1051 + // me.cancelEdit();
  1052 + // if there is a modification
1030 1053 if (event.originalValue !== event.value) {
1031 1054 // delegate rename action on model
1032 1055 event.record.rename(event.value,function(result){
1033 1056 // if a result has been returned : success
1034 1057 if(result) {
  1058 + console.log('renaming, success');
1035 1059 // delegate commit action to delete modification flag
1036 1060 event.record.commit();
1037 1061 var rec = event.record.data;
... ... @@ -1041,9 +1065,10 @@ Ext.define( 'MyTreeEditor', {
1041 1065 rec.id = result.id;
1042 1066 }
1043 1067 } else { // in case of transaction error
  1068 + console.log('renaming, oops');
1044 1069 // reset originalValue
1045 1070 event.record.value = event.originalValue;
1046   - event.record.get('text') = event.originalValue;
  1071 + event.record.set('text', event.originalValue);
1047 1072 event.record.commit();
1048 1073 }
1049 1074 });
... ...