Plot.js 5.11 KB
/**
 * Project      : AMDA-NG
 * Name         : Plot.js
 * @class   amdaModel.Plot
 * @extends amdaModel.PlotNodeObject
 * @brief   Plot Request Business Object Definition 
 * @author  Caroline DARMON
 * @version $Id: Plot.js 2544 2014-10-03 10:21:56Z elena $
 ******************************************************************************
 *    FT Id     :   Date   : Name - Description
 ******************************************************************************
 *	:           :08/09/2011: CDA  - file creation
 */
 
 		
Ext.define('amdaModel.Plot', {
    extend: 'amdaModel.AmdaTimeObject',
    
    fields : [
	  {name: 'children'},
	  {name: 'leaf', type: 'boolean', defaultValue: false},	 		 
          {name: 'outputName', type: 'string'},
	  {name: 'orientation', type: 'string', defaultValue: 'LANDSCAPE'},
          {name: 'format', type: 'string', defaultValue: 'PNG'},
          {name: 'title', type: 'string'},
          {name: 'description', type: 'string'},
          {name: 'charSize', type: 'float', defaultValue: 1.3},
          {name: 'thickness', type: 'int', defaultValue: 1},
	  {name: 'ppp', type: 'int', defaultValue: 3000},
	  {name: 'forcedLayout', type: 'boolean', defaultValue: false}, 
	  {name: 'forcedMulti', type: 'boolean', defaultValue: false},
          {name: 'resultId', type: 'string'},
	  {name: 'resultFolder', type: 'string'},
	  {name: 'tabId', type: 'string', defaultValue: '1'},
	  {name: 'xMin', type: 'string'},  
	  {name: 'xMax', type: 'string'}
	],

	hasMany: {model: 'amdaModel.PlotPanel', name: 'children'},
	 
	propertiesToCopy : 'id,name,outputName,orientation,format,ppp,title,description,charSize,thickness,timesrc,startDate,stopDate,children',
	
	constructor: function(configPanel){
        this.callParent(arguments);
        this.set('leaf',false);
	},
		
	getParentPanel : function(paramObject){
        // for each panel
        for(var i=0;i<this.object.plotPanels().getCount();i++) {
            var panel = this.object.plotPanels().getAt(i);
            // if there's at least one param
            if (panel.plotParams()){
                // for each param
                for(var j=0;j<panel.plotParams().getCount();j++) {
                    if (paramObject == panel.plotParams().getAt(j)){
                        return panel;
                    }
                }
            }
        }
    },
	
	getJsonValues : function(hasId){
	    
	var myValues  = new Object();       
        if (hasId) {
            myValues.id = this.get('id');
        }
        if (this.get('resultId')) {
            myValues.resultId = this.get('resultId');
        }
        myValues.name = this.get('name');
        
     //   myValues.text = this.get('text');
        myValues.tabId = this.get('tabId');
        myValues.outputName = this.get('outputName');
        myValues.orientation = this.get('orientation');
        myValues.format = this.get('format');
        myValues.title = this.get('title');
        myValues.description = this.get('description');
        myValues.charSize = this.get('charSize');
        myValues.thickness = this.get('thickness');
	myValues.ppp = this.get('ppp');
        myValues.forcedLayout = this.get('forcedLayout');
	myValues.forcedMulti = this.get('forcedMulti');
	
        var childrenArray = []; //PlotPanel.JsonValues!!!
        if (this.childNodes && this.childNodes.length > 0){	
            // use internal node attribute of NodeInterface to get children             
            Ext.Array.each(this.childNodes, function(panelItem, panelIndex, allPanelItem) {
                childrenArray.push(panelItem.getJsonValues());		 
           });		   
       } else {	  
            // else if a json config has been past to the Plot constructor
            childrenArray = this.get('children');
        }
        myValues.children = childrenArray;
        myValues.timesrc =  this.get('timesrc');       
        // if there's at least one timeTable name into 'timeTables' collection
        if (this.get('timesrc') == amdaModel.AmdaTimeObject.inputTimeSrc[0] && this.get('timeTables') && this.get('timeTables').length){
            // get complete timeTables collection
            var timeTables = this.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 = this.get('startDate');	
            myValues.stopDate = this.get('stopDate'); 
            myValues.durationDay = this.get('durationDay');
            myValues.durationHour = this.get('durationHour');
            myValues.durationMin = this.get('durationMin');
            myValues.durationSec = this.get('durationSec');
        }
        
        myValues.leaf = true;
        myValues.nodeType = amdaModel.PlotNode.nodeType;
        return myValues;  
	}

});