Blame view

js/app/models/PlotObjects/PlotRequestObject.js 12.7 KB
437c4dbc   Benjamin Renard   First implementat...
1
2
3
4
5
6
7
/**
 * Project      : AMDA-NG
 * Name         : PlotRequestObject.js
 * @class   amdaPlotObj.PlotRequestObject
 * @extends amdaModel.AmdaTimeObject
 * @brief   Plot Request Business Object Definition 
 * @author  Benjamin Renard
940afd8d   Benjamin Renard   Introduce multipl...
8
 * @version $Id: PlotTabObject.js benjamin $
437c4dbc   Benjamin Renard   First implementat...
9
10
11
 ******************************************************************************
 *    FT Id     :   Date   : Name - Description
 ******************************************************************************
940afd8d   Benjamin Renard   Introduce multipl...
12
13
 *	:           :22/07/2015: BRE  - file creation
 *	             20/03/2020: BRE  - full rework
437c4dbc   Benjamin Renard   First implementat...
14
15
16
17
18
19
20
 */
 
 		
Ext.define('amdaPlotObj.PlotRequestObject', {
	extend: 'amdaModel.AmdaTimeObject',
	idProperty: 'id',
	
437c4dbc   Benjamin Renard   First implementat...
21
22
	requires: [
	           'amdaPlotObj.PlotObjectConfig',
940afd8d   Benjamin Renard   Introduce multipl...
23
24
25
26
	           'amdaPlotObj.PlotPanelObject',
	           'amdaPlotObj.PlotLayoutVerticalObject',
	           'amdaPlotObj.PlotLayoutAutoObject',
	           'amdaPlotObj.PlotLayoutManualObject'
437c4dbc   Benjamin Renard   First implementat...
27
28
29
	],
	
	fields : [
d29f5012   Benjamin Renard   Fix doPlot
30
31
              {name: 'tab-index', type: 'int', defaultValue: 0, persist: false},
              {name: 'tab-title', type: 'string', defaultValue: '', persist: false},
4efeb459   Benjamin Renard   First version for...
32
              {name: 'multi-selected', type: 'boolean', defaultValue: false, persist: false},
940afd8d   Benjamin Renard   Introduce multipl...
33

437c4dbc   Benjamin Renard   First implementat...
34
35
36
              {name: 'file-format', type: 'string'},
              {name: 'file-output', type: 'string'},
              {name: 'file-prefix', type: 'string'},
29a2024c   Erdogan Furkan   10852
37
              {name: 'description', type: 'string'},
dbb7bcbe   Benjamin Renard   Add curves defint...
38
              {name: 'one-file-per-interval', type: 'boolean'},
940afd8d   Benjamin Renard   Introduce multipl...
39
40

	      {name: 'tree-full-view', type: 'boolean'},
940afd8d   Benjamin Renard   Introduce multipl...
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
	      {name: 'page-node-state', type: 'int', defaultValue: 2}, //0 : collapsed, 1 : expanded, 2 : not set 
	      {name: 'panels-node-state', type: 'int', defaultValue: 2},  //0 : collapsed, 1 : expanded, 2 : not set

	      {name: 'page-title-text', type: 'string'},
              {name: 'page-title-color', type: 'string'},
              {name: 'page-title-position', type: 'string'},
              {name: 'page-title-alignment', type: 'string'},
              {name: 'page-title-font-activated', type: 'boolean'},
              {name: 'page-title-font-name', type: 'string'},
              {name: 'page-title-font-size', type: 'int'},
              {name: 'page-title-font-bold', type: 'boolean'},
              {name: 'page-title-font-italic', type: 'boolean'},
              {name: 'page-margins-activated', type: 'boolean'},
              {name: 'page-margin-x', type: 'float'},
              {name: 'page-margin-y', type: 'float'},
              {name: 'page-mode', type: 'string'},
              {name: 'page-orientation', type: 'string'},
              {name: 'page-dimension', type: 'string'},
              {name: 'page-superpose-mode', type: 'boolean'},
              {name: 'page-font-activated', type: 'boolean'},
              {name: 'page-font-name', type: 'string'},
              {name: 'page-font-size', type: 'int'},
              {name: 'page-font-bold', type: 'boolean'},
              {name: 'page-font-italic', type: 'boolean'},
              {name: 'page-layout-type', type: 'string'},
              {name: 'page-layout-object', type: 'auto', defaultValue: null},
              {name: 'last-panel-id', type: 'int', defaultValue: 0}
437c4dbc   Benjamin Renard   First implementat...
68
69
    ],
    
940afd8d   Benjamin Renard   Introduce multipl...
70
71
72
73
74
75
76
    associations : [
              {
            	  type : 'hasMany', 
            	  model : 'amdaPlotObj.PlotPanelObject',
            	  name  : 'panels'
              }
    ],
18d4a11e   Benjamin Renard   Save and load plo...
77
78
    
    constructor: function(){
940afd8d   Benjamin Renard   Introduce multipl...
79
80
81
        var me = this;
        me.callParent(arguments);
        if ((arguments.length > 0) && arguments[0])
18d4a11e   Benjamin Renard   Save and load plo...
82
        {
940afd8d   Benjamin Renard   Introduce multipl...
83
84
85
86
        	if (arguments[0].panels)
        		me.loadPanels(arguments[0].panels);
        	if (arguments[0]['page-layout-object'])
        		me.loadLayoutObject(arguments[0]['page-layout-object']);
18d4a11e   Benjamin Renard   Save and load plo...
87
88
89
90
91
        }
        else
        {
        	//new object, set default fields values
        	me.setDefaultValues();
18d4a11e   Benjamin Renard   Save and load plo...
92
        }
940afd8d   Benjamin Renard   Introduce multipl...
93
        this.dirty = false;
18d4a11e   Benjamin Renard   Save and load plo...
94
95
    },
    
940afd8d   Benjamin Renard   Introduce multipl...
96
    loadPanels: function(panels)
18d4a11e   Benjamin Renard   Save and load plo...
97
    {
940afd8d   Benjamin Renard   Introduce multipl...
98
99
       this.panels().loadData(panels);
       this.updatePanelIndex();
437c4dbc   Benjamin Renard   First implementat...
100
101
    },
    
940afd8d   Benjamin Renard   Introduce multipl...
102
    loadLayoutObject: function(layout)
437c4dbc   Benjamin Renard   First implementat...
103
    {
940afd8d   Benjamin Renard   Introduce multipl...
104
105
106
    	this.set('page-layout-object', this.createLayoutByType(this.get('page-layout-type'), layout));
    	if (this.get('page-layout-object') != null)
    		this.get('page-layout-object').dirty = false;
437c4dbc   Benjamin Renard   First implementat...
107
108
    },
    
940afd8d   Benjamin Renard   Introduce multipl...
109
110
111
112
    createNewPanel: function() {
    	this.set('last-panel-id', this.get('last-panel-id') + 1);
    	var recs = this.panels().add({id : this.get('last-panel-id')});
    	recs[0].setDefaultValues();
a971060f   Benjamin Renard   Fix some bugs
113
    	this.dirty = true;
940afd8d   Benjamin Renard   Introduce multipl...
114
115
    	this.updatePanelIndex();
		return recs[0];
abe09878   Benjamin Renard   Add panels and ax...
116
117
    },
    
940afd8d   Benjamin Renard   Introduce multipl...
118
119
120
121
    removePanelById: function(panelId) {
    	//Retrieve panel record
    	var panelRecord = this.panels().getById(panelId);
    	if (panelRecord == null)
dbb7bcbe   Benjamin Renard   Add curves defint...
122
    		return false;
940afd8d   Benjamin Renard   Introduce multipl...
123
    	this.panels().remove(panelRecord);
a971060f   Benjamin Renard   Fix some bugs
124
    	this.dirty = true;
940afd8d   Benjamin Renard   Introduce multipl...
125
    	this.updatePanelIndex();
dbb7bcbe   Benjamin Renard   Add curves defint...
126
    	return true;
abe09878   Benjamin Renard   Add panels and ax...
127
128
    },
    
940afd8d   Benjamin Renard   Introduce multipl...
129
130
131
132
133
134
135
    updatePanelIndex: function() {
    	this.panels().each(function(panel, index) {
    		panel.set('panel-index', index);
    	});
    },
    
    createLayoutByType : function(layoutType, data)
a971060f   Benjamin Renard   Fix some bugs
136
    {
940afd8d   Benjamin Renard   Introduce multipl...
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
    	//Create layout object in relation with the type
    	switch (layoutType)
    	{
    	case 'vertical' :
    		return new amdaPlotObj.PlotLayoutVerticalObject(data);
    	case 'auto' :
    		return new amdaPlotObj.PlotLayoutAutoObject(data);
    	case 'manual' :
    		return new amdaPlotObj.PlotLayoutManualObject(data);
     	default :
     		return null;
    	}
    },
    
    setLayout: function(layoutType)
    {
    	if (layoutType == this.get('page-layout-type'))
    		return;
    	
    	this.set('page-layout-type', layoutType);
    	this.set('page-layout-object', this.createLayoutByType(layoutType));
    },
    
    setDefaultValues: function()
    {
b1dc2eb3   Erdogan Furkan   More modifications
162
163
        this.set('file-format', amdaDefaultValues.plot.file.format);
        this.set('file-output', amdaDefaultValues.plot.file.output);
940afd8d   Benjamin Renard   Introduce multipl...
164
        this.set('file-prefix', '');
17ac91c7   Benjamin Renard   Merge branch 'amd...
165
	this.set('description','');
b1dc2eb3   Erdogan Furkan   More modifications
166
        this.set('one-file-per-interval', amdaDefaultValues.plot.file.oneFilePerInterval);
940afd8d   Benjamin Renard   Introduce multipl...
167
168
        this.set('name', '');

b1dc2eb3   Erdogan Furkan   More modifications
169
    	this.set('tree-full-view', amdaDefaultValues.plot.tree.fullView);
a971060f   Benjamin Renard   Fix some bugs
170
    	
940afd8d   Benjamin Renard   Introduce multipl...
171
    	this.set('page-title-text', '');
b1dc2eb3   Erdogan Furkan   More modifications
172
173
174
    	this.set('page-title-color', amdaDefaultValues.plot.page.title.color);
    	this.set('page-title-position', amdaDefaultValues.plot.page.title.position);
    	this.set('page-title-alignment', amdaDefaultValues.plot.page.title.alignment);
940afd8d   Benjamin Renard   Introduce multipl...
175
176
    	
    	this.set('page-title-font-activated', false);
b1dc2eb3   Erdogan Furkan   More modifications
177
178
    	this.set('page-title-font-name', amdaDefaultValues.plot.page.font.name);
    	this.set('page-title-font-size', amdaDefaultValues.plot.page.font.size);
940afd8d   Benjamin Renard   Introduce multipl...
179
180
181
182
    	this.set('page-title-font-bold', false);
    	this.set('page-title-font-italic', false);
    	
    	this.set('page-margins-activated', false);
b1dc2eb3   Erdogan Furkan   More modifications
183
184
185
186
187
    	this.set('page-margin-x', amdaDefaultValues.plot.page.xMargin);
    	this.set('page-margin-y', amdaDefaultValues.plot.page.yMargin);
    	this.set('page-mode', amdaDefaultValues.plot.page.mode);
    	this.set('page-orientation', amdaDefaultValues.plot.page.orientation);
    	this.set('page-dimension', amdaDefaultValues.plot.page.dimension);
940afd8d   Benjamin Renard   Introduce multipl...
188
189
    	this.set('page-superpose-mode', false);
    	this.set('page-font-activated', false);
b1dc2eb3   Erdogan Furkan   More modifications
190
191
    	this.set('page-font-name', amdaDefaultValues.plot.page.font.name);
    	this.set('page-font-size', amdaDefaultValues.plot.page.font.size);
940afd8d   Benjamin Renard   Introduce multipl...
192
193
194
    	this.set('page-font-bold', false);
    	this.set('page-font-italic', false);
    	
b1dc2eb3   Erdogan Furkan   More modifications
195
    	this.setLayout(amdaDefaultValues.plot.page.layout.type);
940afd8d   Benjamin Renard   Introduce multipl...
196
197
198
199
    },
    
    getPageShortInfo : function()
    {
4f728fd9   Erdogan Furkan   For now 2
200
201
    	var dimension = amdaPlotObj.PlotObjectConfig.getValueByKey(amdaDefaultConfigs.availablePageDimensions, this.get('page-dimension'));
		var orientation = amdaPlotObj.PlotObjectConfig.getValueByKey(amdaDefaultConfigs.availablePageOrientations, this.get('page-orientation'));
940afd8d   Benjamin Renard   Introduce multipl...
202
203
204
205
206
207
208
209
210
		
		var info = dimension+', '+orientation;
		if (this.get('page-superpose-mode'))
			info += ', Epoch superposed mode';
		return info;
    },
    
    getLayoutShortInfo : function()
    {
4f728fd9   Erdogan Furkan   For now 2
211
    	var type = amdaPlotObj.PlotObjectConfig.getValueByKey(amdaDefaultConfigs.availablePageLayouts, this.get('page-layout-type'));
940afd8d   Benjamin Renard   Introduce multipl...
212
213
214
215
216
		return type;
    },
    
    isDirty : function()
    {
a971060f   Benjamin Renard   Fix some bugs
217
218
219
    	if (this.dirty)
    		return true;
    	
940afd8d   Benjamin Renard   Introduce multipl...
220
221
222
223
    	if (this.get('page-layout-object') != null)
    		if (this.get('page-layout-object').dirty)
    			return true;
    	
a971060f   Benjamin Renard   Fix some bugs
224
    	var d = false;
940afd8d   Benjamin Renard   Introduce multipl...
225
226
    	this.panels().each(function (panel, index) {
    		if (panel.isDirty())
a971060f   Benjamin Renard   Fix some bugs
227
228
229
230
231
    			d = true;
    	});
    	return d;
    },
    
940afd8d   Benjamin Renard   Introduce multipl...
232
    getJsonValues : function() 
437c4dbc   Benjamin Renard   First implementat...
233
234
    {
    	var requestValues  = new Object();
57e15214   Benjamin Renard   Fix addParameter ...
235
236

        requestValues['nodeType'] = 'request';
c9db9962   Benjamin Renard   WIP
237
        requestValues['leaf'] = true;
437c4dbc   Benjamin Renard   First implementat...
238
    	
940afd8d   Benjamin Renard   Introduce multipl...
239
    	requestValues['id'] = this.get('id');
d29f5012   Benjamin Renard   Fix doPlot
240
241
        requestValues['tab-index'] = this.get('tab-index');
        requestValues['tab-title'] = this.get('tab-title');
8dddc557   Benjamin Renard   Fix plot reload
242
        requestValues['name'] = this.get('name');
940afd8d   Benjamin Renard   Introduce multipl...
243
244
245
246

        requestValues['file-format'] = this.get('file-format');
        requestValues['file-output'] = this.get('file-output');
        requestValues['file-prefix'] = this.get('file-prefix');
29a2024c   Erdogan Furkan   10852
247
		requestValues['description'] = this.get('description');
940afd8d   Benjamin Renard   Introduce multipl...
248
249
250
        requestValues['one-file-per-interval'] = this.get('one-file-per-interval');

    	requestValues['tree-full-view'] = this.get('tree-full-view');
940afd8d   Benjamin Renard   Introduce multipl...
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
    	requestValues['page-node-state'] = this.get('page-node-state');
    	requestValues['panels-node-state'] = this.get('panels-node-state');

    	requestValues['page-title-text'] = this.get('page-title-text');
    	requestValues['page-title-color'] = this.get('page-title-color');
    	requestValues['page-title-position'] = this.get('page-title-position');
    	requestValues['page-title-alignment'] = this.get('page-title-alignment');
    	requestValues['page-title-font-activated'] = this.get('page-title-font-activated');
    	requestValues['page-title-font-name'] = this.get('page-title-font-name');
    	requestValues['page-title-font-size'] = this.get('page-title-font-size');
    	requestValues['page-title-font-bold'] = this.get('page-title-font-bold');
    	requestValues['page-title-font-italic'] = this.get('page-title-font-italic');
    	requestValues['page-margins-activated'] = this.get('page-margins-activated');
    	requestValues['page-margin-x'] = this.get('page-margin-x');
    	requestValues['page-margin-y'] = this.get('page-margin-y');
    	requestValues['page-mode'] = this.get('page-mode');
    	requestValues['page-orientation'] = this.get('page-orientation');
    	requestValues['page-dimension'] = this.get('page-dimension');
    	requestValues['page-superpose-mode'] = this.get('page-superpose-mode');
    	requestValues['page-font-activated'] = this.get('page-font-activated');
    	requestValues['page-font-name'] = this.get('page-font-name');
    	requestValues['page-font-size'] = this.get('page-font-size');
    	requestValues['page-font-bold'] = this.get('page-font-bold');
    	requestValues['page-font-italic'] = this.get('page-font-italic');
18d4a11e   Benjamin Renard   Save and load plo...
275
    	
940afd8d   Benjamin Renard   Introduce multipl...
276
    	requestValues['timesrc'] =  this.get('timesrc');       
437c4dbc   Benjamin Renard   First implementat...
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
        // 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 {
9193d9a6   Hacene SI HADJ MOHAND   request ok
294
295
            requestValues['startDate'] = Ext.Date.format(this.get('startDate'), 'Y-m-d\\TH:i:s.u');	
            requestValues['stopDate'] = Ext.Date.format(this.get('stopDate'), 'Y-m-d\\TH:i:s.u');	
940afd8d   Benjamin Renard   Introduce multipl...
296
297
298
299
            requestValues['durationDay'] = this.get('durationDay');
            requestValues['durationHour'] = this.get('durationHour');
            requestValues['durationMin'] = this.get('durationMin');
            requestValues['durationSec'] = this.get('durationSec');
b852834a   Hacene SI HADJ MOHAND   progress
300
            requestValues['durationMs'] = this.get('durationMs');
940afd8d   Benjamin Renard   Introduce multipl...
301
        }
437c4dbc   Benjamin Renard   First implementat...
302
    	
940afd8d   Benjamin Renard   Introduce multipl...
303
304
305
306
307
308
309
310
311
312
313
314
315
    	requestValues['page-layout-type'] = this.get('page-layout-type');
    	if (this.get('page-layout-object') != null)
    		requestValues['page-layout-object'] = this.get('page-layout-object').getJsonValues();
    	
    	requestValues['panels'] = [];
    	
    	this.panels().each(function (panel, index) {
    		requestValues['panels'][index] = panel.getJsonValues();
    	});
    	
    	requestValues['last-panel-id'] = this.get('last-panel-id');
    	
    	return requestValues;
437c4dbc   Benjamin Renard   First implementat...
316
    }
ebbb3638   Benjamin Renard   Edit plot tab on ...
317
});