TimeTableNode.js 4.53 KB
/** 
 * Project  : AMDA-NG4
 * Name     : TimeTableNode.js
 * @class   amdaModel.TimeTableNode
 * @extends amdaModel.InteractiveNode
 * @brief   Basic Model of Node corresponding to a amda Time Table
 * @author  
 * @version $Id: TimeTableNode.js 1904 2013-11-25 12:42:02Z elena $
 */

Ext.define('amdaModel.TimeTableNode', {

    extend: 'amdaModel.InteractiveNode',
    
    statics: {
        nodeType: 'timeTable',
        objectName: 'TimeTable'
    },

    constructor : function(config)
    {	
        this.callParent(arguments);
        this.set('moduleId',myDesktopApp.dynamicModules.tt.id);
        this.set('objectDataModel','amdaModel.TimeTable');       
        if (this.get('leaf')) this.set('iconCls', 'icon-timetable');
    },
  
    localMenuItems : function() 
    {
        var menuItems =
         [
        {
            fnId : 'leaf-shareLeaf',
            text : 'Share Time Table',
            hidden : true
        },{
            fnId : 'leaf-download',
            text : 'Download Time Table',
            hidden : true
        },{
            fnId : 'leaf-plot',
            text : 'Plot Time Table',
            hidden : true
        },{
            fnId : 'leaf-operations',
            text : 'Operations',
            hidden : true
        },{
            fnId : 'leaf-generateCatalog',
            text : 'Generate Catalog',
            hidden : true
        }];
     
        return menuItems;
    },

    localMultiMenuItems : function() {
        var menuItems =
         [
        {
            fnId : 'mult-downloadMulti',
            text : 'Download selected '+ this.self.objectName + 's'
        }, {
            fnId : 'mult-plotMulti',
            text : 'Plot selected '+ this.self.objectName + 's'
        }, {
            fnId : 'mult-operationsMulti',
            text : 'Operations'
        }];
     
        return menuItems;
    },
    
    getAllContextMenuItems: function(){
        
        var menuItems = this.allMenuItems();
        var locMenuItems = this.localMenuItems();
        
        return  Ext.Array.merge(menuItems,locMenuItems);       
    },
    
     getMultiContextMenuItems: function(){
        
        var menuItems = this.allMenuMultiItems();
        var locMenuItems = this.localMultiMenuItems();
        
        return  Ext.Array.merge(menuItems,locMenuItems);       
    },
    
    onMenuItemClick : function(menu,item,event) {
 
        this.callParent(arguments);
        
	    var fnId = Ext.util.Format.substr(item.fnId, 5, item.fnId.length);
 
	    switch (fnId) {
	    
 	    case 'shareLeaf':   
 	        this.shareNode(this); 
 	        break;

	    case 'download':
	    	this.ttDownload();
	    	break;
                
	    case 'plot':
	    	this.createPlot(this);
	    	break;	
	    case 'operations':
	        this.ttOperations();
	        break;

	    case 'generateCatalog':
	        this.generateCatalog(this);
	        break;

//	    case 'deleteMulti':
//	        this.deleteMulti();
//	        break;

	    case 'downloadMulti':
	        this.downloadMulti();
	        break;
                
                      case 'plotMulti':
	        this.plotMulti();
	        break;

	    case 'operationsMulti':
	        this.operationsMulti();
	        break;
	   
	    case 'visu':
	        this.visu();
	        break;

	    default:
	        break;
	    } // switch end 	 
     },
 
	ttDownload : function() {
		// download Module	 
		var me = this;
		myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.download.id, true, function (module) {
			module.createWindow();
			var uidownload = module.getUiContent();
			uidownload.addTTdownload(me.get('text'), me.get('id'));
		});
	},     
	ttOperations : function() {	 
		var me = this;   
		myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.tt_op.id, true, function (module) {
			module.createWindow();
			module.getUiContent().addTT(me.get('text'), me.get('id'), me.get('nodeType'));
		});
	},
 
	shareNode: function(node) {  
		myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.tt.id, true, function (module) {
			module.shareTT({'name' : node.get('text'), 'id' : node.get('id')});
		});
	},
     
	downloadMulti: function(){
		var selection = this.myGetOwnerTree().getSelectionModel().selected.items;
		Ext.Array.each(selection,function(item,index,allItems){
			item.ttDownload();
		})
	},
     
	operationsMulti: function(){
		var selection = this.myGetOwnerTree().getSelectionModel().selected.items;
		alert(selection.length+' time tables to send into operationsTT module!');
		Ext.Array.each(selection,function(item,index,allItems){
			item.ttOperations();
		})
	} 
});