MyDataParamNode.js 10.4 KB
/** 
 * Project  : AMDA-NG4
 * Name     : MyDataNode.js
 * @class   amdaModel.MyDataNode
 * @extends amdaModel.InteractiveNode
 * @brief    
 * @author  
 * @version $Id: MyDataParamNode.js 2683 2014-12-02 10:58:53Z elena
 */

Ext.define('amdaModel.MyDataParamComponentNode', {
        extend: 'amdaModel.InteractiveNode',

        text: '',

        constructor : function(config)
        {
            this.callParent(arguments);
            this.set('text', config && config.text ? config.text : this.text);
            this.set('iconCls', 'icon-scalar');
            this.set('leaf',true);
            this.set('isParameter',true);
        },
         localMenuItems : function(){
    var menuItems=
    [{
            fnId : 'leaf-plotParam',
            text : 'Plot Parameter',
            hidden : true
        }, {
            fnId : 'leaf-downParam',
            text : 'Download Parameter',
            hidden : true
        }]
    return menuItems;
 },
  getAllContextMenuItems: function(){
    return  this.localMenuItems ();
},
});


Ext.define('amdaModel.MyDataParamNode', {

    extend: 'amdaModel.InteractiveNode',

    fields: [// { name : 'linkedFile', persist: false}, 
        {name: 'linkedMask', persist: false},
        {name: 'fileObject', persist: false},
        {name: 'size', persist: false},
        {name: 'isSpectra', type: 'boolean', defaultValue: false, persist: false}
    ],

    statics: {
        nodeType: 'myDataParam',
        objectName: 'Parameter'
    },

    constructor: function (config)
    {
        this.callParent(arguments);
        this.set('moduleId', myDesktopApp.dynamicModules.my_data.id);
        this.set('objectDataModel', 'amdaModel.FileParamObject');
        if (this.get('isParameter')) {
            if (this.get('size') == 1)
                this.set('iconCls', 'icon-scalar');
            else if (this.get('size') == 3)
                this.set('iconCls', 'icon-vector');
            else
                this.set('iconCls', 'icon-unknowntype');
        }
       if (this.get('size') > 1){
            this.updateComponents();
        }

        if (this.get('isSpectra'))
            this.set('iconCls', 'icon-spectra');
    },
    updateComponents: function () {
        this.removeAll();
        if (!this.get('isParameter')) {
            return;
        }
        for (var i = 0; i < this.get('size'); ++i) {
            var ch = new amdaModel.MyDataParamComponentNode({text: this.get('text') + '(' + i + ')'
            });
            ch.set('nodeType', 'myDataParam');
            ch.set('globalStart', this.get('globalStart'));
             ch.set('globalStop', this.get('globalStop'));
            this.appendChild(ch);
        }

    },
    

    localMenuItems: function ()
    {
        var menuItems =
                [{
                        fnId: 'root-upload',
                        text: 'Upload File',
                        hidden: true
                    }, {
                        fnId: 'dire-upload',
                        text: 'Upload File',
                        hidden: true
                    }, {
                        fnId: 'leaf-upload',
                        text: 'Upload File',
                        hidden: true
                    }, {
                        fnId: 'leaf-plotParam',
                        text: 'Plot Parameter',
                        hidden: true
                    }, {
                        fnId: 'leaf-downParam',
                        text: 'Download Parameter',
                        hidden: true
                    }, {
                        fnId: 'para-plotParam',
                        text: 'Plot Parameter',
                        hidden: true
                    }, {
                        fnId: 'para-downParam',
                        text: 'Download Parameter',
                        hidden: true
                    }];
        return menuItems;
    },

    getAllContextMenuItems: function ()
    {
        var menuItems = this.allMenuItems('Parameter');
        var locMenuItems = this.localMenuItems();

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

    onMenuItemClick: function (menu, item, event)
    {
        var fnId = Ext.util.Format.substr(item.fnId, 5, item.fnId.length);

        switch (fnId)
        {
            case 'deleteNode':
                this.deleteNode();
                break;

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

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

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

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

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

            case 'plotParam':
                this.createPlot(this);
                break;

            case 'downParam':
                this.createDownload(this);
                break;

            default:
                break;
        } // switch end 
    },

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

    editLeaf: function ()
    {
        // load the rootNode and recursively all its child nodes
        // to know all names of DerivedParameters
        var me = this;
        amdaModel.InteractiveNode.preloadNodes(this.getRootNode(),
                function ()
                {
                    if (me.get('object'))
                    {
                        if (me.get('fileObject'))
                            // launch edition of parameter into parameter module
                            me.editInModule();
                        else
                            AmdaAction.getObject(me.get('object').get('file'), amdaModel.MyDataNode.nodeType, me.getFileObjectCallback, me);
                    } else
                    {
                        // call the ext method to get the details of parameter
                        // the edition of real parameter is done into callback method getObjectCallback            
                        AmdaAction.getObject(me.get('id'), me.get('nodeType'), me.getObjectCallback, me);
                    }
                });
    },

    // special case file object should be also loaded
    getObjectCallback: function (result, remoteEvent) {//result, e) {
        var t = remoteEvent.getTransaction();
        if (result) {
            if (result.id) {
                var paramObj = Ext.create(this.get('objectDataModel'), result);
                // set parameter into node
                this.set('object', paramObj);

                paramObj.set('tableDef', result['tableDef']);

                if (paramObj.get('mask'))
                    var file = paramObj.get('mask');
                else
                    var file = paramObj.get('file');

                AmdaAction.getObject(file, amdaModel.MyDataNode.nodeType,
                        this.getFileObjectCallback, this);
            } else {
                myDesktopApp.errorMsg(result.error);
            }
        } else {
            // EXCEPTION : parameter not found !?
            myDesktopApp.errorMsg(t.action + "." + t.method + " : No parameter '"
                    + this.get('name') + "' found!");
            //TODO: adding an error log
        }
    },

    getFileObjectCallback: function (result, remoteEvent) {//result, e) {
        var t = remoteEvent.getTransaction();
        if (result) {
            if (result.success) {
                var paramObj = Ext.create('amdaModel.FileObject', result);
                this.set('fileObject', paramObj);
                // Edition of parameter into parameter Module	    
                this.editInModule();
            } else {
                myDesktopApp.errorMsg(result.error);
            }
        } else {
            // EXCEPTION : parameter not found !?
            myDesktopApp.errorMsg(t.action + "." + t.method + " : No parameter '"
                    + this.get('name') + "' found!");
        }
    },

    /*
     * Mask was possibly changed update this info
     */
    updateMask: function (mask)
    {
        var myParamRootNode = this.getRootNode();
        if (myParamRootNode.isExpanded) {
            Ext.Array.each(myParamRootNode.childNodes, function (node) {
                if (node.get('linkedMask') && node.get('linkedMask').indexOf(mask) != -1) {
                    node.set('linkedMask', mask);
                    if (node.get('info')) {
                        var info = node.get('info').split("<br/>");
                        node.set('info', info[0] + "<br/>" + info[1] + "<br/> Mask: " + mask);
                    }
                }

            });
        }
    },

    updateMyData: function () {
        // reload myFiles Tree in explorer
        var explorerTree = Ext.getCmp(amdaUI.ExplorerUI.RESRC_TAB.TREE_ID);
        if (explorerTree) {
            var explorerTreeStore = explorerTree.getStore();
            var explorerRoot = explorerTreeStore.getRootNode().findChild('text', 'My Files');

            var explorerPath = '/root/myData-treeRootNode/';

            explorerTreeStore.reload({node: explorerRoot,
                params: {nodeType: 'myData'},
                callback: function () {
                    explorerTree.selectPath(explorerPath);
                }
            });
        }
    },

    isParameter: function () {
        return this.get('isParameter');
    },

    specialUpdate: function (res, timeUpdate)
    {
        if (timeUpdate && res.info)
        {
            var startStop = res.info.split("<br/>");
            var globalStart = startStop[1].substr(0, 19);
            var globalStop = startStop[1].substr(20);

            this.set('globalStart', globalStart);
            this.set('globalStop', globalStop);

            if (res.mask)
                this.set('linkedMask', res.mask);
            if (res.size)
                this.set('size', res.size);
        }

        if (res.isSpectra) {
            this.set('iconCls', 'icon-spectra');
        } else if (res.size == 3) {
            this.set('iconCls', 'icon-vector');
        } else if (res.size > 1) {
            this.set('iconCls', 'icon-unknowntype');
        }
    //      if (res.size > 1)
     //         this.updateComponents();
        // update my data on possible mask change		    
        if (res.updateMyData) {
            this.updateMyData();
            this.updateMask(res.mask);
        }
    }

});