MyDataNode.js 7.02 KB
/** 
 * Project  : AMDA-NG4
 * Name     : MyDataParamNode.js
 * @class   amdaModel.MyDataParamNode
 * @extends amdaModel.InteractiveNode
 * @brief    
 * @author  
 * @version $Id: MyDataNode.js 2267 2014-04-03 10:13:16Z elena $
 * @todo
 *******************************************************************************
 *    FT Id     :   Date   : Name - Description
 *******************************************************************************
 * 
 */

Ext.define('amdaModel.MyDataNode', {
  
    extend: 'amdaModel.InteractiveNode',
    
    fields: 
    [
        {name: 'globalStart', type: 'string', persist: false},
        {name: 'globalStop', type: 'string', persist: false}
    ],
    
    constructor : function(config){
        this.callParent(arguments);
        this.set('moduleId',myDesktopApp.dynamicModules.my_data.id);
        this.set('objectDataModel','amdaModel.FileObject');
        this.set('ownerTreeId',amdaUI.ExplorerUI.RESRC_TAB.TREE_ID);
        this.set('nodeType',amdaModel.MyDataNode.nodeType);
    },

    statics:{
        nodeType: 'myData'
    },

    dependentRootNodeId :  'myDataParam-treeRootNode',
    
    localMenuItems : function() {
        var menuItems =
            [{
                fnId : 'root-upload',
                text : 'Upload File',
                hidden : true
            },  {
                fnId : 'dire-upload',
                text : 'Upload File', 
                hidden : true
            },  {
                fnId : 'dire-deleteNode',
                text : 'Delete Folder', 
                hidden : true
            }, {
                fnId : 'leaf-editLeaf',
                text : 'Edit File'
            }, {
                fnId : 'leaf-deleteNode',
                text : 'Delete File'
	    }
	    ];     
        return menuItems;
    },

    getAllContextMenuItems: function(){

       // var menuItems = this.allMenuItems('File');
        var locMenuItems = this.localMenuItems();

       // return  Ext.Array.merge(menuItems,locMenuItems);
	 return locMenuItems;
    },

    onMenuItemClick : function(menu,item,event) {

        var fnId = Ext.util.Format.substr(item.fnId, 5, item.fnId.length);

        switch (fnId) {

        case 'deleteNode':
            this.deleteMyDataNode(); 
            break;
         
        case 'editLeaf':   
            this.editLeaf(this); 
            break;

        case 'upload':   
            this.uploadFile(); 
            break;

        default:
            break;
        } // switch end 

    },


    uploadFile: function() {
       var module = myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.upload.id, true, function (module) {
    	   module.createWindow();
       });
    },

    // delete empty folders
    deleteMyDataNode : function() {
        
       if (this.isLeaf()) { 
           if (this.parentNode) {
            var emptyFolder = this.parentNode.childNodes.length == 1;
            if (emptyFolder && this.parentNode.getDepth() == 2) {
                        this.parentNode.realDelete();
            }
            else {
                    this.deleteNode();
            }              
        }
       }
       else  {
           this.deleteNode();
       }
    },
        
// file has been already added at server side!!!
   create : function(folderName, fileDesc, folderDesc)  {
                     
                   // if ownerTree panel is not active
    	            if (this.myGetOwnerTree().ownerCt.getActiveTab()!==this.myGetOwnerTree()){
                        // set ownerTree panel as the active tab
                        this.myGetOwnerTree().ownerCt.setActiveTab(this.myGetOwnerTree());
                        // to enable selection of this node his ownerTree must have a view
                    }
                    
                   this.getRootNode().expand(false, function() { 
                    
                        if (!this.get('contextNode')) {
                            // set the root node of 'my data' tree as contextNode
                            var folder = folderName ? this.getRootNode().findChild('text', folderName) : this.getRootNode();
                            this.set('contextNode', folder);
                        } 		   		    
    
                        // expand the contextNode - new node will be added automatically
                        if (!this.get('contextNode').isExpanded()){
                                this.get('contextNode').expand(false); 
                        }
                        else {		     
                            if (!this.get('contextNode').findChild('text', this.get('text')))  
                                           this.get('contextNode').appendChild(this);
                        }
                        
                        if (folderDesc) this.get('contextNode').set('info',folderDesc);
                        if (fileDesc) this.set('info',fileDesc);                     
                        // select the new node                  
                        this.myGetOwnerTree().getSelectionModel().select(this);
                   }, this);
    },
    
/*
 *   Delete  myDataParams
 */
    deleteDependence : function(params) {
        
        // CLOSE MyDataUI      
        var myDataModule = myDesktopApp.desktop.getWindow(myDesktopApp.dynamicModules.my_data.id);        
        if (myDataModule) {            
            myDataModule.close();         
        }   
        
        var myParamRootNode = this.myGetOwnerTree().getRootNode().firstChild.findChild('id',this.dependentRootNodeId);	
        if (myParamRootNode.isExpanded) {					
            Ext.Array.each(params, function(param) {
                var paramNode = myParamRootNode.findChild('id', param, true);
                if (paramNode) paramNode.parentNode.removeChild(paramNode);
            });	    	      	 
        }
        else {
            myParamRootNode.expand(true,true);
        }
       
        myDesktopApp.warningMsg("Attention! Parameters which are made from these files have been deleted");
    },
    
/*
 *   Update  myDataParams Info only if node is exapnded
 */    
    updateMyDataParam : function(mask, maskDesc){
        
        var myParamRootNode = this.myGetOwnerTree().getRootNode().firstChild.findChild('id',this.dependentRootNodeId); 
  
        if (myParamRootNode.isExpanded) {                                       
            Ext.Array.each(myParamRootNode.childNodes, function(node) {
                if (node.get('linkedMask')  &&  node.get('linkedMask') == mask) {
                    var globalStart =  maskDesc.substr(0,16);
                    var globalStop = maskDesc.substr(17,16);
                                        
                    node.set('globalStart', globalStart);
                    node.set('globalStop', globalStop); 
                    if (node.get('info')) {
                        var info = node.get('info').split("<br/>");
                        node.set('info',info[0] + "<br/>" + globalStart + "-" + globalStop + "<br/> Mask: " + mask);
                    }
                }
                
            });                  
      }
    }
});