Statistics.js 2.21 KB
/**
 * Project      : AMDA-NG
 * Name         : Statistics.js 
 * Description  : Statistics Object Definition
 * @class amdaModel.Statistics
 * @extends amdaModel.TimeTable 
 * @author  elena
 */

Ext.define('amdaModel.Statistics', {
	extend: 'amdaModel.AmdaTimeObject',
    
	fields : [
		{ name: 'parameter' } ,
		{ name: 'description' }
	],
    
	getJsonValues : function (hasId) 
	{
		var values  = new Object();	    
		if (hasId) {
			values.id = this.get('id');
		}

		values.timesrc =  this.get('timesrc');
		values.name = 'test'; //this.get('name');
    
// 		if (this.get('description').match(/[a-z,0-9]/gi) != null) {
// 			values.description = this.get('description');
// 		}
//     	if (this.get('history').match(/[a-z,0-9]/gi) != null) {
//     		values.history = this.get('history');
//     	}
		values.objName = this.get('objName');
		values.objFormat = this.get('objFormat');
        	
//    values.cacheToken = this.get('cacheToken');
      values.parameter = this.get('parameter'); 
		
		// if there's at least one parameter
// 		if (this.get('parameter') && this.get('parameter').length) 
// 		{
// 			var list = this.get('parameter');
// 			values.parameter=[];					
// 			Ext.each(list, function(item, index){   
// 				values.parameter[index] = item.getJsonValues();
// 			});
// 		} 
		
		if (values.timesrc == amdaModel.AmdaTimeObject.inputTimeSrc[0])
		{
			// get complete timeTables collection
			var timeTables = this.get('timeTables');	    
			// init an empty array for timeTables
			values.timeTables=[];
			// for each interval record
			Ext.Array.each(timeTables, function(item, index, all)
			{
				if (!item.$className) {
					values.timeTables[index] = {timeTableName : item.timeTableName, id : item.id};
				}
				// get Json simplified value 
				else {
					values.timeTables[index] = item.getJsonValues();
				}
			});            
		} else 
		{
			values.startDate = this.get('startDate');
			values.stopDate = this.get('stopDate');
			values.durationDay = this.get('durationDay');
			values.durationHour = this.get('durationHour');
			values.durationMin = this.get('durationMin');
			values.durationSec = this.get('durationSec');
		} 
	 
		values.leaf = true;
		values.nodeType = 'statistics';

		return values;
	}
});