-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapp.js
More file actions
490 lines (462 loc) · 16.9 KB
/
Copy pathapp.js
File metadata and controls
490 lines (462 loc) · 16.9 KB
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
136
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
/**
* Copyright (C) 2013 by Bundesamt fuer Strahlenschutz
* Software engineering by Intevation GmbH
*
* This file is Free Software under the GNU GPL (v>=3)
* and comes with ABSOLUTELY NO WARRANTY! Check out
* the documentation coming with IMIS-Labordaten-Application for details.
*/
Ext.application({
// Name of the application. Do not change as this name is used in
// references!
name: 'Lada',
requires: [
'Lada.view.Viewport',
'Lada.override.DisplayField',
'Lada.override.Table',
'Lada.override.RestProxy',
'Lada.override.Toolbar',
'Lada.override.Window',
'Lada.override.RowEditor',
'Lada.override.i18n.DE',
'Lada.override.RowExpander',
'Lada.override.FilteredComboBox',
'Lada.override.Date',
'Lada.override.DatePicker',
'Lada.override.UnderlayPool',
'Lada.view.plugin.GridRowExpander',
'Ext.i18n.Bundle',
'Ext.layout.container.Column',
'Lada.query.QueryProxy',
'Lada.store.LocalPagingStore',
'Lada.store.KtaGruppe',
'Lada.store.Datenbasis',
'Lada.store.Messeinheiten',
'Lada.store.Messgroessen',
'Lada.store.Messstellen',
'Lada.store.Leitstelle',
'Lada.store.Probenarten',
'Lada.store.Probenzusaetze',
'Lada.store.Staaten',
'Lada.store.Verwaltungseinheiten',
'Lada.store.VerwaltungseinheitenUnfiltered',
'Lada.store.Bundesland',
'Lada.store.Landkreis',
'Lada.store.Regierungsbezirk',
'Lada.store.StatusWerte',
'Lada.store.StatusStufe',
'Lada.store.StatusKombi',
'Lada.store.DatensatzErzeuger',
'Lada.store.DownloadQueue',
'Lada.store.UploadQueue',
'Lada.store.MessprogrammKategorie',
'Lada.store.GridColumn',
'Lada.store.Query',
'Lada.model.MeasFacil',
'Lada.model.GenericResults',
'Lada.model.GridColMp',
'Lada.model.QueryUser',
'Lada.model.DownloadQueue',
'Lada.model.UploadQueue',
'Lada.view.widget.TimeZoneButton',
'Lada.view.window.ElanScenarioWindow',
'Lada.view.window.TrackedWindow',
'Lada.util.Date',
'Lada.util.I18n',
'Lada.util.WindowTracker',
'Lada.util.LocalStorage',
'Lada.util.WindowTracker',
'Koala.util.DokpoolRequest'
],
statics: {
applicationUpdateTitle: 'Anwendungsupdate',
applicationUpdateText: 'Für diese Anwendung steht ein Update zur Verfügung. Jetzt neu laden?',
dblClickTimeout: 500
},
// Setting up translations. This is done using a ext-plugin which can be
// found on https://github.com/elmasse/Ext.i18n.Bundle
bundle: {
bundle: 'Lada',
language: (function() {
//Set Language according to build profile
switch (Ext.manifest.profile) {
case 'lada-en':
return 'en-US';
case 'lada-de':
return 'de-DE';
default: return 'de-DE';
}
}()),
path: 'resources/i18n',
noCache: true
},
beforeCloseHandler: function(evt) {
var i18n = Lada.getApplication().bundle;
// match different handling from different browsers
var confirmMessage = i18n.getMsg('window.confirmclose');
evt.returnValue = confirmMessage;
return confirmMessage;
},
// Setting this variable to true triggers loading the Viewport.js
// file which sets ob the viewport.
//autoCreateViewport: true,
// Start the application.
launch: function() {
var loadmask = Ext.get('loadmask');
if (loadmask) {
loadmask.destroy();
}
Ext.JSON.encodeDate = function(o) {
return '"' + Ext.Date.format(o, 'c') + '"';
};
// Default headers for all requests
Ext.Ajax.setDefaultHeaders({
Accept: 'application/json'
});
Lada.username = '';
Lada.userroles = '';
Lada.logintime = '';
Lada.mst = [];
Lada.netzbetreiber = [];
Lada.clientVersion = '4.8.0-SNAPSHOT';
Lada.serverVersion = '';
// paging sizes available for the client
Lada.availablePagingSizes = [
{value: 50, label: '50'},
{value: 100, label: '100'},
{value: 500, label: '500'},
{value: 2000, label: '2000'},
{value: 5000, label: '5000 (lange Ladezeit!)'}
];
//initial default paging size, may be changed by user
Lada.pagingSize = 50;
Ext.Ajax.request({
url: 'lada-server/rest/user',
method: 'GET',
scope: this,
success: this.onLoginSuccess,
failure: this.onLoginFailure
});
Ext.Ajax.request({
url: 'resources/appContext.json',
method: 'GET',
scope: this,
success: function(response) {
var json = Ext.decode(response.responseText);
if (json.data) {
Lada.appContext = json.data;
}
}
});
Ext.tip.QuickTipManager.init();
// ask before closing/refreshing the window.
// Not all browsers will respect this, depending on settings
window.addEventListener('beforeunload', this.beforeCloseHandler);
},
/*
* Gets called if the appCache signals an app update. It shows a confirm
* dialog which reloads the page on confirmation. xxx
*/
onAppUpdate: function() {
//FIXME i18n does not work on Firefox on early load of appUpdate uses statics
Ext.Msg.confirm(Lada.$application.applicationUpdateTitle,
Lada.$application.applicationUpdateText,
function(choice) {
if (choice === 'yes') {
window.location.reload();
}
}
);
},
onLoginFailure: function(response) {
var i18n = Lada.getApplication().bundle;
if (response.status === 401) {
Ext.MessageBox.alert(i18n.getMsg('err.init.noname'),
response.responseText);
} else {
Ext.MessageBox.alert(i18n.getMsg('err.init.generic.title'),
i18n.getMsg('err.init.generic.msg'));
}
},
onLoginSuccess: function(response) {
/* Parse Username and Timestamp */
var json = Ext.decode(response.responseText);
Lada.username = json.username;
Lada.userId = json.userId;
Lada.userroles = json.roles;
Lada.logintime = json.servertime;
Lada.mst = []; // Messstellen this user may select
Lada.funktionen = json.funktionen;
Lada.netzbetreiber = json.netzbetreiber;
Lada.netzbetreiberFunktionen = json.netzbetreiberFunktionen;
//Lada.serverVersion
this.getServerVersion();
var mstLabor = json.messstelleLabor;
for (var i = 0; i < mstLabor.length; i++) {
Lada.mst.push(mstLabor[i].messstelle);
Lada.mst.push(mstLabor[i].labor);
}
Ext.create('Lada.store.Datenbasis', {
storeId: 'datenbasis'
});
Ext.create('Lada.store.OprMode', {
storeId: 'oprModeStore'
});
Ext.create('Lada.store.Messeinheiten', {
storeId: 'messeinheiten'
});
Ext.create('Lada.store.Messgroessen', {
storeId: 'messgroessen'
});
Ext.create('Lada.store.GridColumn', {
storeId: 'columnstore'
});
// Used in: widget.Leitstelle (used in query panel)
// Extends store.Messstellen and uses proxy.type: 'memory'.
// Data added in load-callback on store 'messstellen' (an instance
// of store.Messstellen) created further down.
Ext.create('Lada.store.Leitstelle', {
storeId: 'leitstellenwidget'
});
// Used in: widget.Messstelle, form.Messprogramm, form.Datensatzerzeuger,
// form.Probe, window.Messprogramm, window.Messung,
// window.Ortszuordnung, window.GenProbenFromMessprogramm,
// window.Probe, panel.Map, panel.QueryPanel,
// grid.PKommentar, ...
// Load-callback here fills data into store 'leitstellenwidget'.
// Server service: MessstelleService via model.Messstelle
Ext.create('Lada.store.Messstellen', {
storeId: 'messstellen',
listeners: {
load: {
fn: function() {
var lst = Ext.data.StoreManager.get(
'leitstellenwidget');
lst.removeAll(true);
var reclst = [];
var rec = [];
this.each(function(rr) {
rec.push(rr.copy());
if (rr.get('id').match(/200.0/)) {
reclst.push(rr.copy());
}
});
lst.add(reclst);
}
}
}
});
Ext.create('Lada.store.Probenarten', {
storeId: 'probenarten'
});
Ext.create('Lada.store.Probenzusaetze', {
storeId: 'probenzusaetze'
});
Ext.create('Lada.store.Staaten', {
storeId: 'staaten'
});
Ext.create('Lada.store.VerwaltungseinheitenUnfiltered', {
storeId: 'verwaltungseinheitenwidget'
});
Ext.create('Lada.store.Bundesland', {
storeId: 'bundeslandwidget'
});
Ext.create('Lada.store.Landkreis', {
storeId: 'landkreiswidget'
});
Ext.create('Lada.store.Regierungsbezirk', {
storeId: 'regierungsbezirkwidget'
});
Ext.create('Lada.store.Verwaltungseinheiten', {
storeId: 'verwaltungseinheiten',
listeners: {
load: function() {
var w = Ext.data.StoreManager.get(
'verwaltungseinheitenwidget');
var b = Ext.data.StoreManager.get(
'bundeslandwidget');
var l = Ext.data.StoreManager.get(
'landkreiswidget');
var r = Ext.data.StoreManager.get(
'regierungsbezirkwidget');
w.removeAll(true);
b.removeAll(true);
l.removeAll(true);
r.removeAll(true);
var rec = [];
var recb = [];
var recl = [];
var recr = [];
this.each(function(rr) {
rec.push(rr.copy());
if (rr.get('isState')) {
recb.push(rr.copy());
}
if (rr.get('isRuralDist')) {
recl.push(rr.copy());
}
if (rr.get('isGovDist')) {
recr.push(rr.copy());
}
});
w.add(rec);
l.add(recl);
b.add(recb);
r.add(recr);
}
}
});
// TODO: usage of this store unclear: reloaded in Datensatzerzeuger
// controller, but never used. Details here should go into model or
// store definition
Ext.create('Lada.store.DatensatzErzeuger', {
storeId: 'datensatzerzeuger',
proxy: {
type: 'rest',
url: 'lada-server/rest/datasetcreator',
reader: {
type: 'json',
totalProperty: 'totalCount',
rootProperty: 'data'
},
limitParam: undefined,
startParam: undefined,
pageParam: undefined
},
autoLoad: true
});
// TODO: Similar to Datensatzerzeuger
Ext.create('Lada.store.MessprogrammKategorie', {
storeId: 'messprogrammkategorie',
proxy: {
type: 'rest',
url: 'lada-server/rest/mpgcateg',
reader: {
type: 'json',
totalProperty: 'totalCount',
rootProperty: 'data'
},
limitParam: undefined,
startParam: undefined,
pageParam: undefined
},
autoLoad: true
});
Ext.create('Lada.store.StatusWerte', {
storeId: 'statuswerte',
autoLoad: true
});
Ext.create('Lada.store.StatusStufe', {
storeId: 'statusstufe',
autoLoad: true
});
Ext.create('Lada.store.StatusKombi', {
storeId: 'statuskombi',
autoLoad: true
});
Ext.create('Lada.store.KtaGruppe', {
storeId: 'ktaGruppe',
autoLoad: true
});
// Store containing all MST a User is allowed to set.
// Used in: Ext.form.field.ComboBox instances in window.SetStatus,
// panel.FileUpload, grid.PKommentar, grid.MKommentar.
// widget.Messstelle (a widget.base.ComboBox) uses store 'messstellen'
// and filters locally in exactly the same way.
// Server service: MessstelleService via model.Messstelle
Ext.create('Lada.store.Messstellen', {
storeId: 'messstellenFiltered',
filters: function(item) {
if (Ext.Array.contains(Lada.mst, item.get('id'))) {
return true;
}
return false;
}
});
Ext.create('Ext.data.Store', {
storeId: 'pagingSizes',
model: Ext.create('Ext.data.Model', {
fields: [
{name: 'label', type: 'string'},
{name: 'value', type: 'int'}
]
}),
data: Lada.availablePagingSizes
});
Ext.create('Lada.store.DownloadQueue', {
storeId: 'downloadqueue-print'
});
Ext.create('Lada.store.DownloadQueue', {
storeId: 'downloadqueue-export'
});
Ext.create('Lada.store.UploadQueue', {
storeId: 'uploadqueue'
});
Ext.create('Lada.view.Viewport');
this.initElanScenarios();
},
initElanScenarios: function() {
Lada.util.LocalStorage.setCurrentUser(Lada.username);
var dokpool = Koala.util.DokpoolRequest;
//Configure dokpool utility
dokpool.elanScenarioUrl = '../dokpool/bund/contentconfig/scen/';
dokpool.storageModule = Lada.util.LocalStorage;
dokpool.updateActiveElanScenarios();
//Create the display window
Ext.create('Lada.view.window.ElanScenarioWindow');
window.setInterval(function() {
dokpool.updateActiveElanScenarios();
}, 60000);
},
getServerVersion: function() {
var i18n = Lada.getApplication().bundle;
Ext.Ajax.request({
url: 'lada-server/rest/version',
method: 'GET',
headers: {},
success: function(response) {
Lada.serverVersion = response.responseText;
},
failure: function() {
console.log('Error in retrieving the server version.'
+ ' It might be lower than 2.0-beta2'
+ ' Or something is broken...');
Lada.serverVersion = i18n.getMsg('err.msg.generic.title');
}
});
},
// Sets the paging size and fires 'pagingSizeChangedEvent' if
// new value differs from old
setPagingSize: function(newVal) {
if (newVal !== Lada.pagingSize) {
Lada.pagingSize = newVal;
Lada.getApplication().fireEvent('pagingSizeChanged');
}
},
/**
* Fix for odd behavior of some browsers in the toExponential(digits)
* function (MS Edge falsely rounds down some least significant digits).
* @param {Number} value the numerical value to parse
* @param {Number} digits the amount of digits as in toExponential()
* @returns {String}
*/
toExponentialString: function(value, digits) {
var rawExp = value.toExponential();
if (digits === undefined) {
return rawExp;
}
var fixedExp = value.toExponential(digits);
if (fixedExp.length === rawExp.length && fixedExp !== rawExp) {
return rawExp;
} else {
return fixedExp;
}
},
// Define the controllers of the application. They will be initialized
// first before the application "launch" function is called.
controllers: [
'Lada.controller.grid.Messung',
'Lada.controller.grid.Ortszuordnung',
'Lada.controller.ElanScenario'
]
});