Blame view

ihm/app/controller/Steps/ExportDefinitionStep.js 4.67 KB
346b85c6   Benjamin Renard   First commit with...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
Ext.define('treps.controller.Steps.ExportDefinitionStep', {
	extend: 'treps.controller.Steps.BaseStep',

	views: [
		'Steps.ExportDefinition.ExportDefinitionPanel'
	],

	init: function() {
		var me = this

	},

	onAfterLoad: function(store, records, successful, eOpts)
	{
		var gridController = treps.app.getController('Data.Grid.ResultDataGrid');

                gridController.setTotalInHeader(store.totalCount);
        },

	doRequest: function(afterrequest) {
		var timeController   = treps.app.getController('Times.ExportTimeSelection');
		var exportController = treps.app.getController('Export.ExportSelection');

		var args = {
			'id'          : treps.model.Session.get('id'),
			'format'      : exportController.getExportFormat(),
			'structure'   : exportController.getExportStructure(),
			'timeformat'  : timeController.getTimeFormat(),
			'timepattern' : timeController.getTimePattern()
		};

		treps.LoadMask.show("Build exported file. please wait ... ");
		TREPSAction.exportOperation(args, function(result, event)
			{
				treps.LoadMask.hide();

				if (!result)
				{
					treps.Messages.showError("Internal error during exportOperation request");
					return;
				}
				else if (!result.success)
				{
					treps.Messages.showError(result.error);
					return;
				}

				treps.model.Session.set('exportFormat',exportController.getExportFormat());

				afterrequest.call();
			}
		);
	},

	doInitStep: function() {
		var me = this;
		var session = treps.model.Session;

		var timeController   = treps.app.getController('Times.ExportTimeSelection');
		var gridController   = treps.app.getController('Data.Grid.ResultDataGrid');
		var plotController   = treps.app.getController('Data.Plot.ResultDataPlot');
		var exportController = treps.app.getController('Export.ExportSelection');

		var dataStoreManager = treps.controller.Data.Store.DataStoreManager;

		//get format and structure file list
		treps.LoadMask.show("Load export structures list. Please wait ...");
		exportController.initStores(function (formatsStore, structuresStore)
			{
				treps.LoadMask.hide();
				//load times list
				treps.LoadMask.show("Load time formats list. Please wait ...");
				timeController.initStore(function (timesStore)
					{
						treps.LoadMask.hide();
						timeController.setTime(session.get('sourceTimeFormat'));

						//get result data info, create result data store, and reconfigure the data grid
						treps.LoadMask.show("Get result data info. Please wait ...");
						TREPSAction.getResultInfo({'id' : session.get('id')}, function(result, event)
							{
								treps.LoadMask.hide();

								if (!result)
								{
									treps.Messages.showError("Internal error during resultInfo request");
									return;
								}
								else if (!result.success)
								{
									treps.Messages.showError(result.error);
									return;
								}


								//create model fields
								var modelFields = dataStoreManager.createModelFields(result.info.fields);

								//create result data model
								dataStoreManager.defineModel(gridController.getDataModelName(),modelFields);

								//reconfigure the result data store
								var store = dataStoreManager.reconfigureStore(
									gridController.getDataStoreId(),
									gridController.getDataModelName(),
									TREPSAction.getResultData,
									me.onAfterLoad);

								if (!store)
								{
									treps.Messages.showError("Error during result data store reconfiguration");
									return;
								}

								//reconfigure grid
								gridController.reconfigureDataGrid(result.info.nbRecords, result.info.fields);

								var resVectors = result.info.vectors;

								//get transformation info
								treps.LoadMask.show("Get transformation info. Please wait ...");
								TREPSAction.getRunInfo({'id' : session.get('id')}, function(result, event)
									{
										treps.LoadMask.hide();
										if (!result)
										{
											treps.Messages.showError("Internal error during runInfo request");
											return;
										}
										else if (!result.success)
										{
											treps.Messages.showError(result.error);
											return;
										}

150096dc   Benjamin Renard   Fix some bugs + i...
136
137
										exportController.setExportStructureEnabled(result.info.srcFrame != result.info.dstFrame);

346b85c6   Benjamin Renard   First commit with...
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
										//reconfigure plot
										plotController.reconfigureDataPlot(result.info.vectors, resVectors, result.info.srcFrame, result.info.dstFrame);
									});
							}
						);
					}
				);
			}
		);
	},

	isValidStep: function() {
		var timeController = treps.app.getController('Times.ExportTimeSelection');

		if (!timeController.isValid())
			return false;

		var exportController = treps.app.getController('Export.ExportSelection');
		
		if (!exportController.isValid())
			return false;

		return true;
	}
});