DownloadNode.js 3.65 KB
/** 
 * Project  : AMDA-NG4
 * Name     : DownloadNode.js
 * @class   amdaModel.DownloadNode
 * @extends amdaModel.ExecutableNode
 * @brief   Basic Model of Node corresponding to a download request
 * @author  Myriam
 * @version $Id: DownloadNode.js 2949 2015-06-23 10:25:59Z elena $
 */

Ext.define('amdaModel.DownloadNode', {

    extend: 'amdaModel.ExecutableNode',	

    statics: {
        nodeType: 'download',
        objectName: 'Download'
    },
        
    constructor : function(config) {
        this.callParent(arguments);
        this.set('moduleId',myDesktopApp.dynamicModules.download.id);
        this.set('objectDataModel',amdaModel.Download.$className);
    },
    
    decodeObject: function(obj) {
        var myValues  = new Object(); 		
        myValues.list=[];

        obj.panels().each(function (panel) {
            panel.params().each(function (param) {
                var myParam = new Object();
                myParam.paramid =  param.get('paramid');
                myParam.type =  param.get('type');
                myParam['dim1-index'] = param.get('dim1-index');
                myParam['dim1-sum-type'] = param.get('dim1-sum-type');
                myParam['dim1-min-value'] =  param.get('dim1-min-value');
                myParam['dim1-max-value'] =  param.get('dim1-max-value');
                myParam['dim1-min-index'] =  param.get('dim1-min-index');
                myParam['dim1-max-index'] =  param.get('dim1-max-index');
                myParam['dim2-index'] = param.get('dim2-index');
                myParam['dim2-sum-type'] = param.get('dim2-sum-type');
                myParam['dim2-min-value'] =  param.get('dim2-min-value');
                myParam['dim2-max-value'] =  param.get('dim2-max-value');
                myParam['dim2-min-index'] =  param.get('dim2-min-index');
                myParam['dim2-max-index'] =  param.get('dim2-max-index');
                myParam.template_args = param.get('template_args');
                if (!param.get('plotonly')) {
                    myValues.list.push(myParam);
                }
                else 
                    alert('Parameter '+ myParam.paramid + ' is PlotOnly');						
            });
        });				
        myValues.timesrc = obj.get('timesrc');
        // if there's at least one timeTable name into 'timeTables' collection
        if (myValues.timesrc == amdaModel.AmdaTimeObject.inputTimeSrc[0]
            && obj.get('timeTables')
            && obj.get('timeTables').length){
            // get complete timeTables collection
            var timeTables =  obj.get('timeTables');	    
            // init an empty array for timeTables
            myValues.timeTables=[];
            // for each interval record
            Ext.Array.each(timeTables, function(item, index, all){
                if (!item.$className) {
                    myValues.timeTables[index] = {timeTableName : item.timeTableName, id : item.id};
                }
                // get Json simplified value 
                else {
                    myValues.timeTables[index] = item.getJsonValues();
                }
            });            
        }
        else {
            myValues.startDate =  Ext.Date.format(obj.get('startDate'), 'Y-m-d\\TH:i:s.u');	
            myValues.stopDate =  Ext.Date.format(obj.get('startDate'), 'Y-m-d\\TH:i:s.u');
            myValues.durationDay = obj.get('durationDay');
            myValues.durationHour = obj.get('durationHour');
            myValues.durationMin = obj.get('durationMin');
            myValues.durationSec = obj.get('durationSec');
            myValues.durationMs = obj.get('durationMs');
        }

        myValues.name = obj.get('name');
        return myValues;
    }
});