ExplorerModule.js 11.9 KB
/** 
 * Project  : AMDA-NG
 * Name     : ExplorerModule.js
 * @class   amdaDesktop.ExplorerModule 
 * @extends amdaDesktop.AmdaModule
 * @brief   Explorer Module controller definition
 * @author  CDA
 */

Ext.define('amdaDesktop.ExplorerModule', {

    extend: 'amdaDesktop.AmdaModule',
    
    requires : [
        'amdaUI.ExplorerUI',
        'amdaUI.AliasUI',
        // Node Models
        'amdaModel.BkgJobNode',
        'amdaModel.DerivedParamNode',
        'amdaModel.LocalParamNode',
        'amdaModel.RemoteParamNode',
        'amdaModel.RemoteSimuParamNode',
        'amdaModel.AliasNode',
        'amdaModel.TimeTableNode',
	'amdaModel.CatalogNode',
        'amdaModel.sharedTimeTableNode',
        'amdaModel.MyDataParamNode',
        'amdaModel.MyDataNode',
        'amdaModel.PlotNode',
        'amdaModel.DownloadNode',       // singleton; not shown in the tree
        'amdaModel.SearchNode',
        // Object Models
        'amdaModel.Parameter',
        'amdaModel.Search',
        'amdaModel.Plot', 
        'amdaModel.Download',
        'amdaModel.TimeTable',
	'amdaModel.Catalog',
        'amdaModel.FileObject',
        'amdaModel.FileParamObject',
        'amdaModel.FilterInfo'
    ],
    
    contentId : 'explorerUI',
   
    filter : null,
    filtersStore : null,
    
    constructor : function(config){
                this.callParent(arguments);
                if (!this.filtersStore) {
                  this.filtersStore = Ext.create('Ext.data.Store', {
                        model: 'amdaModel.FilterList' 
                });                 
               this.filtersStore.load(); 
             //  amdaDesktop.ExplorerModule.filtersStore = this.filtersStore;
            }                
        },
        
        
    createWindow : function() {
        var desktop = this.app.getDesktop();
        
        var win = desktop.getWindow(this.id);
        if (!win) {            
    	win = desktop.createWindow( {
                id : this.id,
                title : this.title,
                width : 340,
                height : 500,
                iconCls : this.icon,
                animCollapse : false,
                border : false,
       //         constrainHeader : true,
                closable: false,
                stateful : true,
                stateId  : this.id,
                stateEvents: ['move','show','resize'],
                constrain: true,
                layout   :
                {
                    type : 'border',
                    align : 'stretch'
                },
                x : 5,
                y : 5,
                items : [
                    {
                        xtype: 'panelExplorer',
                        id : this.contentId,
                        region: 'center'
                    },
                    {
                        xtype: 'panel', 
                        id : 'LogPanel',
                        region: 'south',
                        height : 150,
                        split : true,
                        layout: {
                                type: 'vbox',
                                align : 'stretch',
                                autoSize : true
                        }, 
                        autoScroll : true,
                        stateful : true,
                        stateId  : 'LogPanel',
                        buttons : [{
                                scope: this,
                                text : 'Clear',
                                handler: function(){	
                                        win.items.get('LogPanel').removeAll();  
                                        this.addLogMessage('<b>Log</b>');
                                }
                        }]
                    }
                ]
            });
        
    		
        }
        
        win.on({
                activate: {
                        fn : function() 
                        {
                                myDesktopApp.getLoadedModule(this.id, true, function (module) {
                                	// on activation when there's a pinedModule 'null'
                                    if (module.pinedModule===null) {
                                            // get the ZIndex manager
                                            var manager = myDesktopApp.desktop.getDesktopZIndexManager();
                                            // ordering to send back this window
                                            manager.sendToBack(win);
                                    } 
                                });
                                                               
                        },
                        scope: this
                } 
        });
        
        win.on({
                show : 
                {
                        fn : function(o)
                        {
                                //set current filter
                                this.setCrtFilter();    				
                                //resize the explorer in relation with the desktop size
                                if (win.y + win.height > myDesktopApp.desktop.el.getHeight())
                                        win.setHeight(myDesktopApp.desktop.el.getHeight() - win.y);
                        },
                        scope : this
                }
        });
        
        win.addCls('window-active');
        win.show();
        this.addLogMessage('<b>Log</b>');
        return win;
        
    },
    
    pinedModule : null,
    
    /**
     * Getter of pinedModule
     * @return {amdaDesktop.InteractiveModule} The pined module
     */
    getPinedModule : function() 
    {
        // get the pined Module
        return this.pinedModule;
    },

    /**
     * Setter of pinedModule
     * @param {amdaDesktop.InteractiveModule} The pined module
     */
    setPinedModule : function(amdaModule) 
    {
        // set the pined Module
        this.pinedModule = amdaModule;
    },
    
    /**
     * Module Attachment Method
     * @param {amdaDesktop.InteractiveModule} The module to attach
     */
    pinMechanism : function(amdaModule) 
    {
        // if there is an old pined module
        if (this.getPinedModule()!=null) {
                // get old pined module :
                var oldPinedModule = this.getPinedModule();
                // call uncolor method on the old pined Module
                myDesktopApp.getLoadedModule(oldPinedModule).uncolorHeaderModule();
        }
        // set pined module
        this.setPinedModule(amdaModule);
        // call color method on pined Module
        myDesktopApp.getLoadedModule(amdaModule).colorHeaderModule();
    },
    
    
    addLogMessage : function(message)
    {
        var height = 40;
        var msg = Ext.create('Ext.Component', {
            height: height,
            html: message,
            style: { color : '#555555'}
        });
        var desktop = myDesktopApp.getDesktop();
        var win = desktop.getWindow(this.id);
        var panel = win.items.get('LogPanel');
        panel.add(msg);
    },
     
     //
     setCrtFilter : function()
     {
            var me = this;
                //get current filter to apply
                AmdaAction.getCrtFilterResult(function (result, e)
                                {
                                    var t = e.getTransaction();
                                    if (e.status) 
                                    {	
                                            if (result)
                                            {
                                                    //apply current filter
                                                    this.filter = result;
                                                    
                                                    // add saved filter to Explorer List
                                                    if (!this.filtersStore.getById(this.filter.id)) 
                                                        this.filtersStore.add({id : this.filter.id, name : this.filter.name});
                                                    
                                                    //apply filter to the tree
                                                    var desktop = myDesktopApp.getDesktop();
                                                    var win = desktop.getWindow(this.id);
                                                    if (win)
                                                    {
                                                            var explorerUI = win.query('#'+this.contentId);
                                                            explorerUI[0].updateFilter();
                                                    }
                                            }
                                            else
                                                    Ext.Msg.show( {
                                                            title : 'Filter', 
                                                            msg : 'Cannot apply filter',
                                                            modal : true,
                                                            icon : Ext.Msg.ERROR,
                                                            buttons : Ext.Msg.OK
                                                    });
                                    }
                                    else
                                    {
                                        // FAILURE
                                    Ext.Msg.show({title:'Error System', msg: e.message, icon: Ext.MessageBox.ERROR, buttons: Ext.Msg.OK});
                                    } 
                            },this);
     },
     
        resetFilter : function()
        {
            AmdaAction.resetFilter( 
                                function (result, e)
                                {
                                        var t = e.getTransaction();
                                        if (e.status) 
                                        {	
                                                if (result)
                                                {
                                                        this.setCrtFilter();
                                                        
                                                        //update filter win
                                                        var desktop = myDesktopApp.getDesktop();
                                                        var win = desktop.getWindow(myDesktopApp.dynamicModules.filters.id);
                                                        if (win)
                                                        {
                                                                var filterUI = win.query('panelFilters');
                                                                filterUI[0].reloadFilter();
                                                        }
                                                }
                                                else
                                                        Ext.Msg.show( {
                                                                title : 'Filter', 
                                                                msg : 'Cannot reset filter',
                                                                modal : true,
                                                                icon : Ext.Msg.ERROR,
                                                                buttons : Ext.Msg.OK
                                                        });
                                        }
                                        else
                                        {
                                                // FAILURE
                                                Ext.Msg.show({title:'Error System', msg: e.message, icon: Ext.MessageBox.ERROR, buttons: Ext.Msg.OK});
                                        } 
                        },this);
     }
});