Blame view

js/app/models/PlotObjects/PlotRequestObject.js 5.67 KB
437c4dbc   Benjamin Renard   First implementat...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
/**
 * Project      : AMDA-NG
 * Name         : PlotRequestObject.js
 * @class   amdaPlotObj.PlotRequestObject
 * @extends amdaModel.AmdaTimeObject
 * @brief   Plot Request Business Object Definition 
 * @author  Benjamin Renard
 * @version $Id: PlotRequestObject.js benjamin $
 ******************************************************************************
 *    FT Id     :   Date   : Name - Description
 ******************************************************************************
 *	:           :21/07/2015: BRE  - file creation
 */
 
 		
Ext.define('amdaPlotObj.PlotRequestObject', {
	extend: 'amdaModel.AmdaTimeObject',
	idProperty: 'id',
	
437c4dbc   Benjamin Renard   First implementat...
20
21
22
23
24
25
26
27
28
29
	requires: [
	           'amdaPlotObj.PlotObjectConfig',
	           'amdaPlotObj.PlotTabObject'
	],
	
	fields : [
	          {name: 'id', type:'string'},
              {name: 'file-format', type: 'string'},
              {name: 'file-output', type: 'string'},
              {name: 'file-prefix', type: 'string'},
dbb7bcbe   Benjamin Renard   Add curves defint...
30
              {name: 'one-file-per-interval', type: 'boolean'},
87658ba0   Benjamin Renard   TT Navigation in ...
31
              {name: 'last-plotted-tab', type: 'int', defaultValue: 0},
e9e906ad   Elena.Budnik   update mulritab p...
32
              {name: 'last-tab-id', type: 'int', defaultValue: 0},
13ad8aca   Elena.Budnik   2 options : all i...
33
				  {name: 'active-tab-id', type: 'int', defaultValue: 1},
fd6c7cd1   Elena.Budnik   delete not needed...
34
				  {name: 'all-in-one', type: 'boolean', defaultValue: false}
437c4dbc   Benjamin Renard   First implementat...
35
36
37
38
    ],
    
    hasMany: {
    		model : 'amdaPlotObj.PlotTabObject',
18d4a11e   Benjamin Renard   Save and load plo...
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
    		name  : 'tabs',
    		associationKey:'tabs'
    },
    
    constructor: function(){
    	var me = this;
    	me.callParent(arguments);
        if ((arguments.length > 0) && arguments[0] && arguments[0].tabs)
        {
        	if (arguments[0].tabs)
        		me.loadTabs(arguments[0].tabs);
        }
        else
        {
        	//new object, set default fields values
        	me.setDefaultValues();
        	//New object, force the creation of the first tab
        	me.createNewTab();
        }
    },
    
    loadTabs: function(tabs)
    {
       this.tabs().loadData(tabs);
437c4dbc   Benjamin Renard   First implementat...
63
64
65
66
67
68
69
70
    },
    
    setDefaultValues: function()
    {
    	this.set('file-format', amdaPlotObj.PlotObjectConfig.defaultValues.file.format);
    	this.set('file-output', amdaPlotObj.PlotObjectConfig.defaultValues.file.output);
    	this.set('file-prefix', '');
    	this.set('one-file-per-interval', amdaPlotObj.PlotObjectConfig.defaultValues.file.oneFilePerInterval);
87658ba0   Benjamin Renard   TT Navigation in ...
71
    	this.set('last-plotted-tab', 0);
18d4a11e   Benjamin Renard   Save and load plo...
72
    	this.set('name', '');
437c4dbc   Benjamin Renard   First implementat...
73
74
    },
    
abe09878   Benjamin Renard   Add panels and ax...
75
    createNewTab: function() {
dbb7bcbe   Benjamin Renard   Add curves defint...
76
77
    	this.set('last-tab-id', this.get('last-tab-id') + 1);
    	var recs = this.tabs().add({id : this.get('last-tab-id')});
abe09878   Benjamin Renard   Add panels and ax...
78
    	recs[0].setDefaultValues();
a971060f   Benjamin Renard   Fix some bugs
79
    	this.dirty = true;
abe09878   Benjamin Renard   Add panels and ax...
80
81
82
		return recs[0];
    },
    
dbb7bcbe   Benjamin Renard   Add curves defint...
83
84
85
86
87
88
    removeTabById: function(tabId) {
    	//Retrieve tab record
    	var tabRecord = this.tabs().getById(tabId);
    	if (tabRecord == null)
    		return false;
    	this.tabs().remove(tabRecord);
a971060f   Benjamin Renard   Fix some bugs
89
    	this.dirty = true;
dbb7bcbe   Benjamin Renard   Add curves defint...
90
    	return true;
abe09878   Benjamin Renard   Add panels and ax...
91
92
    },
    
a971060f   Benjamin Renard   Fix some bugs
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
    isDirty : function()
    {
    	if (this.get('id') == '')
    		return false;
    	
    	if (this.dirty)
    		return true;
    	
    	var d = false;
    	this.tabs().each(function (tab, index) {
    		if (tab.isDirty())
    			d = true;
    	});
    	return d;
    },
    
437c4dbc   Benjamin Renard   First implementat...
109
110
111
112
113
114
115
116
117
118
    getJsonValues : function(hasId) 
    {
    	var requestValues  = new Object();
    	
    	requestValues['nodeType'] = 'request';
    	
    	if (hasId) {
    		requestValues['id'] = this.get('id');
        }
    	
18d4a11e   Benjamin Renard   Save and load plo...
119
120
    	requestValues['leaf'] = true;
    	
437c4dbc   Benjamin Renard   First implementat...
121
122
123
124
    	requestValues['file-format'] = this.get('file-format');
    	requestValues['file-output'] = this.get('file-output');
    	requestValues['file-prefix'] = this.get('file-prefix');
    	requestValues['one-file-per-interval'] = this.get('one-file-per-interval');
87658ba0   Benjamin Renard   TT Navigation in ...
125
    	requestValues['last-plotted-tab'] = this.get('last-plotted-tab');
e6065c11   Elena.Budnik   overwrite request...
126
127
    	requestValues['name'] = this.get('name');
		requestValues['all-in-one'] =  this.get('all-in-one');
e9e906ad   Elena.Budnik   update mulritab p...
128
		
e6065c11   Elena.Budnik   overwrite request...
129
130
    	requestValues['timesrc'] =  this.get('timesrc'); 
			
437c4dbc   Benjamin Renard   First implementat...
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
        // 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
            requestValues['timeTables'] = [];
            // for each interval record
            Ext.Array.each(timeTables, function(item, index, all){
            	if (!item.$className) {
            		requestValues['timeTables'][index] = {timeTableName : item.timeTableName, id : item.id};
            	}
            	// get Json simplified value 
            	else {
            		requestValues['timeTables'][index] = item.getJsonValues();
            	}
            });            
        } else {
13ad8aca   Elena.Budnik   2 options : all i...
148
149
150
151
152
153
154
				requestValues['startDate'] = this.get('startDate');	
				requestValues['stopDate'] = this.get('stopDate'); 
				requestValues['durationDay'] = this.get('durationDay');
				requestValues['durationHour'] = this.get('durationHour');
				requestValues['durationMin'] = this.get('durationMin');
				requestValues['durationSec'] = this.get('durationSec');
			}
437c4dbc   Benjamin Renard   First implementat...
155
    	
13ad8aca   Elena.Budnik   2 options : all i...
156
		requestValues['tabs'] = [];
a56f041d   Elena.Budnik   bug whne multi pa...
157

fd6c7cd1   Elena.Budnik   delete not needed...
158
		if (this.get('all-in-one')) {
13ad8aca   Elena.Budnik   2 options : all i...
159
160
161
162
163
164
165
166
167
168
169
170
			this.tabs().each(function (tab, index) {
				requestValues['tabs'][index] = tab.getJsonValues();
			});
			
			requestValues['active-tab-id'] = this.get('active-tab-id');
			requestValues['last-tab-id'] = this.get('last-tab-id');
		}
		else {
			var tab = this.tabs().getAt(this.get('active-tab-id')-1);
			requestValues['tabs'][0] = tab.getJsonValues();
			
			requestValues['tabs'][0]['id'] = "1";
a56f041d   Elena.Budnik   bug whne multi pa...
171
			requestValues['active-tab-id'] =  "1";
13ad8aca   Elena.Budnik   2 options : all i...
172
173
174
175
			requestValues['last-tab-id'] = "1";
			requestValues['last-plotted-tab'] = "0";
		}
		
e9e906ad   Elena.Budnik   update mulritab p...
176
      return requestValues;
437c4dbc   Benjamin Renard   First implementat...
177
178
    }
});