RequestParamObject.js 6.09 KB
/**
 * Project      : AMDA-NG
 * Name         : RequestParamObject.js
 * Description  : Request Param Business Object Definition
 * @class amdaModel.RequestParamObject
 * @extends amdaModel.AmdaObject 
 * 
 * @author benjamin
 * @version $Id:  $
 ******************************************************************************
 *    FT Id     :   Date   : Name - Description
 ******************************************************************************
 *	:           :13/06/2016: benjamin – creation 
 */
 
 		
Ext.define('amdaModel.RequestParamObject', {
	extend: 'amdaModel.AmdaObject',

        statics: {
          getEmptyObj: function() {
            return {
            	'paramid': '',
		'is-init': false,
            	'type': 0,
            	'dim1-index': '*',
            	'dim1-sum-type': 0,
            	'dim1-min-value': 0.,
            	'dim1-max-value': 0.,
            	'dim1-min-index': 0,
            	'dim1-max-index': 0,
            	'dim2-index': '*',
            	'dim2-sum-type': 0,
            	'dim2-min-value': 0.,
            	'dim2-max-value': 0.,
            	'dim2-min-index': 0,
            	'dim2-max-index': 0,
            	'template_args': {}
            };
          },
        },
	
	idProperty: 'id',
    
        fields : [
          {name: 'type', type: 'int'}, /* Parameter type. 0: Scalar, 1: Tab1D, 2: Tab2D */
          {name: 'is-init', type: 'bool', default:false},
          {name: 'paramid', type: 'string'},
          /* Fields for dim1 */
          {name: 'dim1-index', type: 'string', defaultValue: '*'},
          {name: 'dim1-sum-type', type: 'int', defaultValue: 0}, /* Sum type. 0: None, 1: sum into values range, 2: sum between indexes */
          {name: 'dim1-min-value', type: 'float', defaultValue: 0.},
          {name: 'dim1-max-value', type: 'float', defaultValue: 0.},
          {name: 'dim1-min-index', type: 'int', defaultValue: 0},
          {name: 'dim1-max-index', type: 'int', defaultValue: 0},
          /* Fields for dim2 */
          {name: 'dim2-index', type: 'string', defaultValue: '*'},
          {name: 'dim2-sum-type', type: 'int', defaultValue: 0}, /* Sum type. 0: None, 1: sum into values range, 2: sum between indexes */
          {name: 'dim1-min-value', type: 'float', defaultValue: 0.},
          {name: 'dim1-max-value', type: 'float', defaultValue: 0.},
          {name: 'dim1-min-index', type: 'int', defaultValue: 0},
          {name: 'dim1-max-index', type: 'int', defaultValue: 0},
          /* Field for arguments of a templated parameter */
          {name: 'template_args', type: 'auto', defaultValue: null},
          /* ?? */
          {name: 'plotonly', type: 'bool', defaultValue: false}
	],

	getDimSum : function(dim) {
		switch (this.get(dim+'-sum-type')) {
			case 1:
				return 'range[' + this.get(dim+'-min-value') + ',' + this.get(dim+'-max-value') + ']';
			case 2:
				return 'indexes[' + this.get(dim+'-min-index') + ',' + this.get(dim+'-max-index') + ']';
		}
		return false;
	},
	
	getParamFullName : function() {
		var paramIndexes = '';
		var sum_dim1 = this.getDimSum('dim1');
		var sum_dim2 = this.getDimSum('dim2');
		switch (this.get('type')) {
			case 0:
	  			//scalar - nothing to do
	  			break;
	  		case 1:
	  			//Tab1D
	  			if (sum_dim1 !== false) {
	  				paramIndexes = '(' + sum_dim1 + ')';
	  			}
	  			else if (sum_dim2 !== false) {
	  				paramIndexes = '(' + sum_dim2 + ')';
	  			}
	  			else {
	  				if ((this.get('dim1-index') != '') && (this.get('dim1-index') != '*'))
	  					paramIndexes = '('+this.get('dim1-index')+')';
	  				else if ((this.get('dim2-index') != '') && (this.get('dim2-index') != '*'))
	  					paramIndexes = '('+this.get('dim2-index')+')';
	  			}
	  			break;
	  		case 2:
	  			//Tab2D
	  			var dim1 = '';
	  			if (sum_dim1 !== false)
	  				dim1 = sum_dim1;
	  			else
		  			dim1 = this.get('dim1-index') != '' ? this.get('dim1-index') : "*";
	  			var dim2 = '';
	  			if (sum_dim2 !== false)
	  				dim2 = sum_dim2;
	  			else
	  				dim2 = this.get('dim2-index') != '' ? this.get('dim2-index') : "*";
	  			if ((dim1 != '*') || (dim2 != '*'))
	  				paramIndexes = '('+dim1+','+dim2+')';
		}
	
		var template_args = "";
		if (this.get('template_args')) {
			Ext.Object.each(this.get('template_args'), function (argKey, argValue) {
				template_args += "_";
				if (typeof(argValue) === "boolean") {
					template_args += (argValue ? 1 : 0);
				}
				else {
					template_args += argValue;
				}
			});
		}
		
		return this.get('paramid')+template_args+paramIndexes;
	},
	
	getJsonValues : function() 
    {
    	var paramValues  = new Object();
    	
    	paramValues['id'] = this.get('id');
    	paramValues['paramid'] = this.get('paramid');
    	paramValues['name'] = this.get('name');
    	
	paramValues['dim1-index'] = this.get('dim1-index');
    	paramValues['dim1-sum-type'] = this.get('dim1-sum-type');
	switch (this.get('dim1-sum-type')) {
		case 1:
			// Between values
			paramValues['dim1-sum-min'] = this.get('dim1-min-value');
			paramValues['dim1-sum-max'] = this.get('dim1-max-value');
			break;
		case 2:
			// Between components indexes
			paramValues['dim1-sum-min'] = this.get('dim1-min-index');
			paramValues['dim1-sum-max'] = this.get('dim1-max-index');
			break;
	}

	paramValues['dim2-index'] = this.get('dim2-index');
	paramValues['dim2-sum-type'] = this.get('dim2-sum-type');
	switch (this.get('dim2-sum-type')) {
		case 1:
			// Between values
			paramValues['dim2-sum-min'] = this.get('dim2-min-value');
			paramValues['dim2-sum-max'] = this.get('dim2-max-value');
			break;
		case 2:
			// Between components indexes
			paramValues['dim2-sum-min'] = this.get('dim2-min-index');
			paramValues['dim2-sum-max'] = this.get('dim2-max-index');
			break;
	}
   	
    	paramValues['type'] = this.get('type');
    	
    	if (this.get('template_args') != null) {
    		paramValues['template_args'] = new Object();
    		Ext.Object.each(this.get('template_args'), function (argKey, argValue) {
			if (typeof(argValue) === "boolean") {
				paramValues['template_args'][argKey] = (argValue ? 1 : 0);
			}
			else {
    				paramValues['template_args'][argKey] = argValue;
			}
    		});
    	}
    	
    	return paramValues;
    }
      
});