diff --git a/js/app/models/AmdaNode.js b/js/app/models/AmdaNode.js index ee71e0c..4d2c7f9 100644 --- a/js/app/models/AmdaNode.js +++ b/js/app/models/AmdaNode.js @@ -5,193 +5,191 @@ * @extends Ext.data.Model * @brief Generic Model of Node for AMDA project * @author CDA - * @version $Id: AmdaNode.js 2544 2014-10-03 10:21:56Z elena $ - * @todo - ******************************************************************************* - * FT Id : Date : Name - Description - ******************************************************************************* - * : :08/06/2011: CDA - Migration extjs4 */ Ext.define('amdaModel.AmdaNode', { - extend: 'Ext.data.TreeModel', - - requires: ['amdaReader.ExplorerReader'], - - fields: [ - {name: 'leaf', type: 'boolean'}, - {name: 'nodeType',type:'string'}, - {name: 'id', type: 'string'}, - {name:'text',type: 'string'}, - {name:'info',type: 'string'}, - {name: 'help', type: 'string', defaultValue: ''}, - {name:'rootNode', persist: false}, - {name: 'ownerTreeId', persist: false}, - {name: 'ownerTree', persist: false}, - {name: 'checked', defaultValue: null, persist: false} - ], - - statics : { - NEW_DIR_NAME : 'new Folder', - MULTI_PREFIX : 'mult' - }, - - /** - * @cfg proxy used to load nodes - */ - proxy: { - type: 'direct', - // directFn: AmdaAction.getTree, - api : - { - read: AmdaAction.getTree, - update: AmdaAction.saveTree, - create: AmdaAction.saveTree, - destroy: AmdaAction.doNothing + extend: 'Ext.data.TreeModel', + + requires: ['amdaReader.ExplorerReader'], + + fields: [ + {name: 'leaf', type: 'boolean'}, + {name: 'nodeType',type:'string'}, + {name: 'id', type: 'string'}, + {name:'text',type: 'string'}, + {name:'info',type: 'string'}, + {name: 'help', type: 'string', defaultValue: ''}, + {name:'rootNode', persist: false}, + {name: 'ownerTreeId', persist: false}, + {name: 'ownerTree', persist: false}, + {name: 'checked', defaultValue: null, persist: false} + ], + + statics : { + NEW_DIR_NAME : 'new Folder', + MULTI_PREFIX : 'mult' }, - paramsAsHash : true, - reader: { - type: 'explorer' - } - }, - - /** - * Abstract getter of complete array of item context menu - * @return {Ext.Array} the complete array of item context menu - */ - getAllContextMenuItems: Ext.emptyFn, - - /** - * Abstract method call on click on item of context menu - */ - onMenuItemClick: Ext.emptyFn, - - /** - * Abstract Update Data method - */ - update : Ext.emptyFn, - - /** - * Abstract Rename Data method - */ - rename : Ext.emptyFn, - - /** - * Abstract Rename D&D Data method - */ - renameDD : Ext.emptyFn, - - /** - * Abstract Create Data method - */ - create : Ext.emptyFn, - - /** - * filtering method of context menu - * @param {String} itemKind the kind of right clicked node - * @return {Ext.Array} the Array of filtered item menu - */ - getFilteredContextMenu : function(itemKind) { - var menuitems = this.getAllContextMenuItems(); - if (menuitems && menuitems.length){ - for ( var i = 0; i < menuitems.length; i++) { - var currentItem = menuitems[i]; - var myItemKind = Ext.util.Format.substr(currentItem.fnId, 0, 4); - if (myItemKind === itemKind) { - currentItem.hidden = false; - } - else { - currentItem.hidden = true; - } - } - return menuitems; - } else { - return null; - } - }, - - getMultiContextMenu : function(){ - var menuitems = this.getMultiContextMenuItems(); - if (menuitems && menuitems.length){ - return menuitems; - } else { - return null; - } - }, - - /** - * get the kind of this node - * @returns itemKind string - */ - getNodeKind : function() { - var itemKind; - // if id of this node have root subcategory suffix - if (this.id && Ext.util.Format.substr(this.id, -(amdaUI.ExplorerUI.ROOT_SUFFIX.length), this.id.length) === amdaUI.ExplorerUI.ROOT_SUFFIX ) { - itemKind = amdaUI.ExplorerUI.ITEM_KIND_ROOT; - } - // if this node is a leaf and have no child - else if (this.isLeaf()) { - itemKind = amdaUI.ExplorerUI.ITEM_KIND_LEAF; - } - else if (this.get('isParameter')) { - itemKind = amdaUI.ExplorerUI.ITEM_KIND_PARA; - } - else if (this.get('rank')) { - itemKind = amdaUI.ExplorerUI.ITEM_KIND_MISS; - } - // other case - else { - itemKind = amdaUI.ExplorerUI.ITEM_KIND_DIRE; - } - return itemKind; + + /** + * @cfg proxy used to load nodes + */ + proxy: { + type: 'direct', + api : + { + read: AmdaAction.getTree, + update: AmdaAction.saveTree, + create: AmdaAction.saveTree, + destroy: AmdaAction.doNothing + }, + paramsAsHash : true, + reader: { + type: 'explorer' + } + }, + + /** + * Abstract getter of complete array of item context menu + * @return {Ext.Array} the complete array of item context menu + */ + getAllContextMenuItems: Ext.emptyFn, + + /** + * Abstract method call on click on item of context menu + */ + onMenuItemClick: Ext.emptyFn, + + /** + * Abstract Update Data method + */ + update : Ext.emptyFn, + + /** + * Abstract Rename Data method + */ + rename : Ext.emptyFn, + + /** + * Abstract Rename D&D Data method + */ + renameDD : Ext.emptyFn, + + /** + * Abstract Create Data method + */ + create : Ext.emptyFn, + + /** + * filtering method of context menu + * @param {String} itemKind the kind of right clicked node + * @return {Ext.Array} the Array of filtered item menu + */ + getFilteredContextMenu : function(itemKind) { + var menuitems = this.getAllContextMenuItems(); + if (menuitems && menuitems.length){ + for ( var i = 0; i < menuitems.length; i++) { + var currentItem = menuitems[i]; + var myItemKind = Ext.util.Format.substr(currentItem.fnId, 0, 4); + if (myItemKind === itemKind) { + currentItem.hidden = false; + } + else { + currentItem.hidden = true; + } + } + return menuitems; + } else { + return null; + } + }, + + getMultiContextMenu : function(){ + var menuitems = this.getMultiContextMenuItems(); + if (menuitems && menuitems.length){ + return menuitems; + } else { + return null; + } + }, + + /** + * get the kind of this node + * @returns itemKind string + */ + getNodeKind : function() { + var itemKind; + // if id of this node have root subcategory suffix + if (this.id && Ext.util.Format.substr(this.id, -(amdaUI.ExplorerUI.ROOT_SUFFIX.length), this.id.length) === amdaUI.ExplorerUI.ROOT_SUFFIX ) { + itemKind = amdaUI.ExplorerUI.ITEM_KIND_ROOT; + } + // if this node is a leaf and have no child + else if (this.isLeaf()) { + itemKind = amdaUI.ExplorerUI.ITEM_KIND_LEAF; + } + else if (this.get('isParameter')) { + itemKind = amdaUI.ExplorerUI.ITEM_KIND_PARA; + } + else if (this.get('rank')) { + itemKind = amdaUI.ExplorerUI.ITEM_KIND_MISS; + } + // base + else if (this.id && Ext.util.Format.substr(this.id, -(amdaUI.ExplorerUI.BASE_SUFFIX.length), this.id.length) === amdaUI.ExplorerUI.BASE_SUFFIX ) { + itemKind = amdaUI.ExplorerUI.ITEM_KIND_BASE; + } + // other case + else { + itemKind = amdaUI.ExplorerUI.ITEM_KIND_DIRE; + } + + return itemKind; + }, + + /** + * Getter on context menu of this node + * @returns {Ext.menu.Menu} the contextMenu of this node + */ + getContextMenuItems : function() { + // set the node kind + var itemKind = this.getNodeKind(); + // filter the global context menu by node kind + var menuItems = this.getFilteredContextMenu(itemKind); + // return the context menu for this node + return menuItems; + }, + + getContextMenuMultiItems : function() { + return this.getMultiContextMenu(); + }, + + /** + * Method to retrieve the root node corresponding to the nodeType of this node + * @return {amdaModel.AmdaNode} the root node of category of this node + */ + getRootNode : function() { + if (!this.get('rootNode')) { + // if this node is the root of its category + if(this.getNodeKind() == amdaUI.ExplorerUI.ITEM_KIND_ROOT) { + this.set('rootNode',this); + } else { + // get resources tree panel + var tree = this.myGetOwnerTree(); + var treeRoot = tree.getRootNode(); + var rootNodeId = this.get('nodeType')+amdaUI.ExplorerUI.ROOT_SUFFIX; + + this.set('rootNode',treeRoot.findChild( 'id', rootNodeId, true)); + } + } + return this.get('rootNode'); }, - /** - * Getter on context menu of this node - * @returns {Ext.menu.Menu} the contextMenu of this node - */ - getContextMenuItems : function() { - // set the node kind - var itemKind = this.getNodeKind(); - // filter the global context menu by node kind - var menuItems = this.getFilteredContextMenu(itemKind); - // return the context menu for this node - return menuItems; - }, - - getContextMenuMultiItems : function() { - return this.getMultiContextMenu(); - }, - - /** - * Method to retrieve the root node corresponding to the nodeType of this node - * @return {amdaModel.AmdaNode} the root node of category of this node - */ - getRootNode : function() { - if (!this.get('rootNode')) { - // if this node is the root of its category - if(this.getNodeKind() == amdaUI.ExplorerUI.ITEM_KIND_ROOT) { - this.set('rootNode',this); - } else { - // get resources tree panel - var tree = this.myGetOwnerTree(); - var treeRoot = tree.getRootNode(); - var rootNodeId = this.get('nodeType')+amdaUI.ExplorerUI.ROOT_SUFFIX; - - this.set('rootNode',treeRoot.findChild( 'id', rootNodeId, true)); - } - } - return this.get('rootNode'); - }, - - /** - * getter on ownerTree (use ownerTreeId property) - * @return {Ext.tree.Panel} the tree which contains this node - */ - myGetOwnerTree : function() { - if (!this.get('ownerTree')) { - this.set('ownerTree',Ext.getCmp(this.get('ownerTreeId'))); - } - return this.get('ownerTree'); - } + /** + * getter on ownerTree (use ownerTreeId property) + * @return {Ext.tree.Panel} the tree which contains this node + */ + myGetOwnerTree : function() { + if (!this.get('ownerTree')) { + this.set('ownerTree',Ext.getCmp(this.get('ownerTreeId'))); + } + return this.get('ownerTree'); + } }); diff --git a/js/app/views/ExplorerUI.js b/js/app/views/ExplorerUI.js index b726034..3d5ab7b 100644 --- a/js/app/views/ExplorerUI.js +++ b/js/app/views/ExplorerUI.js @@ -96,7 +96,8 @@ Ext.define('amdaUI.ExplorerUI', { CAT_SUFFIX: '-treeBase', ROOT_SUFFIX: '-treeRootNode', SUB_ROOT_SUFFIX : 'RootNode', - + + ITEM_KIND_BASE : 'treeBase', ITEM_KIND_ROOT : 'root', ITEM_KIND_LEAF : 'leaf', ITEM_KIND_DIRE : 'dire', -- libgit2 0.21.2