-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathogerlib-extjs.js
More file actions
563 lines (443 loc) · 15.2 KB
/
ogerlib-extjs.js
File metadata and controls
563 lines (443 loc) · 15.2 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
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
/*
#LICENSE BEGIN
**********************************************************************
* OgerArch - Archaeological Database is released under the GNU General Public License (GPL) <http://www.gnu.org/licenses>
* Copyright (C) Gerhard Öttl <gerhard.oettl@ogersoft.at>
**********************************************************************
#LICENSE END
*/
/*
* Define Oger.extjs namespace.
*/
Oger.extjs = {};
/*
* Check if a response is present at all and has the 'success' property.
* In extjs 3.3.1 if an response is empty (0 bytes) this is not handled as failure
* but the success handler is called. See ux directory.
*/
Oger.extjs.actionSuccess = function(action, showSuccessMsg) {
if (action != undefined && action.result != undefined &&
action.result.success != undefined && action.result.success == true) {
if (showSuccessMsg) {
Oger.extjs.submitMsg();
}
return true;
}
// SOME MESSAGES ONLY FOR COLLECTING FOR BUGREPORT (begin) -------------------------
if (action == undefined) {
Ext.Msg.alert(Oger._('Fehler (Server+)'), Oger._('Antwort des Servers fehlerhaft oder leer. (action == undefinded)'));
return false;
}
if (action.result == undefined) {
Ext.Msg.alert(Oger._('Fehler (Server+)'), Oger._('Antwort des Servers fehlerhaft oder leer. (action.result == undefinded)'));
return false;
}
if (action.result.success == undefined) {
Ext.Msg.alert(Oger._('Fehler (Server+)'), Oger._('Antwort des Servers fehlerhaft oder leer. (action.result.success == undefinded)'));
return false;
}
if (action.result.success == false) {
Ext.Msg.alert(Oger._('Fehler (Server+)'), Oger._('Antwort des Servers fehlerhaft oder leer. (action.result.success == false)'));
return false;
}
// SOME MESSAGES ONLY FOR COLLECTING FOR BUGREPORT (end) -------------------------
// otherwise notify an error
Ext.Msg.alert(Oger._('Fehler (Server+)'), Oger._('Antwort des Servers fehlerhaft oder leer.'));
return false;
} // eo check for successful response
/*
* Force that the upper left corner of an Extjs object to be displayed inside the
* boundery of another Extjs object. The moved object is not resized.
* If you also want the object also to be resized to fit into the outer objet,
* than use Oger.extjs.adjustToFit().
* Obj and viewPort must be visible to work.
* @obj: Any visible Extjs object that is resized and positioned if not fit.
* @viewpoint: Any visible Extjs object that defines the boundery.
* If not provided the browser windows is taken.
*/
Oger.extjs.moveToFit = function(obj, viewPort) {
// see comment block in Oger.extjs.adjustToFit
// for more posibilities to detect browser size
var viewPortX;
var viewPortY;
var viewPortWidth;
var viewPortHeight;
// get position and size of viewport
if (viewPort == undefined) {
viewPortX = 0;
viewPortY = 0;
viewPortWidth = window.innerWidth;
viewPortHeight = window.innerHeight;
}
else {
viewPortX = viewPort.getPosition()[0];
viewPortY = viewPort.getPosition()[1];
viewPortWidth = viewPort.getWidth();
viewPortHeight = viewPort.getHeight();
} // eo viewport position and size
var objXOri = obj.getPosition()[0];
var objYOri = obj.getPosition()[1];
var objWidthOri = obj.getWidth();
var objHeightOri = obj.getHeight();
var objX = objXOri;
var objY = objYOri;
var objWidth = objWidthOri;
var objHeight = objHeightOri;
// now size of window fits, but may be is not shown inside viewport
// test right
objX = Math.min(objX, viewPortX + viewPortWidth- objWidth);
// test bottom
objY = Math.min(objY, viewPortY + viewPortHeight- objHeight);
// test left
objX = Math.max(objX, viewPortX);
// test top
objY = Math.max(objY, viewPortY);
if (objX != objXOri || objY != objYOri) {
obj.setPosition(objX, objY);
}
} // eo move
/*
* Force an Extjs object to be displayed inside the boundery of another Extjs object.
* Obj and viewPort must be visible to work.
* @obj: Any visible Extjs object that is resized and positioned if not fit.
* @viewpoint: Any visible Extjs object that defines the boundery.
* If not provided the browser windows is taken.
* @autoScroll: Defines if autoScroll should be set, if the window size is altered (shrinked).
*/
Oger.extjs.adjustToFit = function(obj, viewPort, autoScroll) {
/*
// ONLY FOR DOCUMENTATION
var viewportwidth;
var viewportheight;
// the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
if (window.innerWidth != undefined) {
viewPortwidth = window.innerWidth,
viewPortheight = window.innerHeight
}
// IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
else if (document.documentElement != undefined &&
document.documentElement.clientWidth != undefined &&
document.documentElement.clientWidth != 0) {
viewPortwidth = document.documentElement.clientWidth,
viewPortheight = document.documentElement.clientHeight
}
// older versions of IE
else {
viewPortwidth = document.getElementsByTagName('body')[0].clientWidth,
viewPortheight = document.getElementsByTagName('body')[0].clientHeight
}
// maybe try: document.body.clientHeight
*/
var viewPortX;
var viewPortY;
var viewPortWidth;
var viewPortHeight;
// get position and size of viewport
if (viewPort == undefined) {
viewPortX = 0;
viewPortY = 0;
viewPortWidth = window.innerWidth;
viewPortHeight = window.innerHeight;
}
else {
viewPortX = viewPort.getPosition()[0];
viewPortY = viewPort.getPosition()[1];
viewPortWidth = viewPort.getWidth();
viewPortHeight = viewPort.getHeight();
} // eo viewport position and size
var objXOri = obj.getPosition()[0];
var objYOri = obj.getPosition()[1];
var objWidthOri = obj.getWidth();
var objHeightOri = obj.getHeight();
var objX = objXOri;
var objY = objYOri;
var objWidth = objWidthOri;
var objHeight = objHeightOri;
// if size does not fit at all, than resize first.
// to minimize resize events apply at once
if (objWidth > viewPortWidth) {
objWidth = viewPortWidth;
}
if (objHeight > viewPortHeight) {
objHeight = viewPortHeight;
}
if (objWidth != objWidthOri || objHeight != objHeightOri) {
obj.setSize(objWidth, objHeight);
if (autoScroll) {
obj.setAutoScroll(true);
}
}
// now size of window fits, but may be is not shown inside viewport
// Oger.extjs.moveToFit() could be used, but all values are already present,
// so do it here.
// test right
objX = Math.min(objX, viewPortX + viewPortWidth- objWidth);
// test bottom
objY = Math.min(objY, viewPortY + viewPortHeight- objHeight);
// test left
objX = Math.max(objX, viewPortX);
// test top
objY = Math.max(objY, viewPortY);
if (objX != objXOri || objY != objYOri) {
obj.setPosition(objX, objY);
}
} // eo adjust
/*
* General handler for form submission errors.
* On not "sufficient" handled failures do not return true to notify
* that subsequent handling is expected.
*/
Oger.extjs.handleFormSubmitFailure = function(form, action) {
switch (action.failureType) {
case Ext.form.Action.CLIENT_INVALID:
Ext.Msg.alert(Oger._('Fehler'), Oger._('Fehler im Formular. Bitte korrekt ausfüllen.'));
return true;
case Ext.form.Action.CONNECT_FAILURE:
Ext.Msg.alert(Oger._('Fehler'), Oger._('Fehler bei der Datenübertragung. Eventuell nochmal versuchen.'));
return true;
case Ext.form.Action.SERVER_INVALID:
//Ext.Msg.alert(Oger._('Fehler'), Oger._('Serverapplikation meldet successfull=false.'));
// handle only some situations
var isHandled = false;
if (action.result.msg != undefined) {
Ext.Msg.alert(Oger._('Fehler (App)'), action.result.msg,
// Messagebox.alert does not stop code, so handle code also here
function(btn, text, opt) {
if (action.result.code != undefined) {
action.result.code();
};
}
);
isHandled = true;
}
if (!isHandled && action.result.code != undefined) {
action.result.code();
isHandled = true;
}
// last resor for server failure
if (!isHandled) {
Ext.Msg.alert(Oger._('Fehler (Server)'), Oger._('Antwort des Servers fehlerhaft.'));
}
break;
case Ext.form.Action.LOAD_FAILURE:
Ext.Msg.alert(Oger._('Fehler'), Oger._('Fehler beim Laden von Daten oder keine Daten bereitgestellt.'));
// this can not be (or should not be) handled generaly, so do not return with true
break;
default:
Ext.Msg.alert(Oger._('Fehler'), Oger._('Unbekannter Submit/Action-Fehlertyp:' + action.failureType + '.'));
// this can not be (or should not be) handled generaly, so do not return with true
} // eo switch
}; // eo form submission error handler
/*
* General handler for ajax failures
*/
Oger.extjs.handleAjaxFailure = function(response, opts) {
Ext.Msg.alert(Oger._('Fehler'), Oger._('Request: ') + opts.url + '.<br>' +
Oger._('Response: ') + response.status + ' ' + response.statusText + '.');
}; // eo ajax error handler
/*
* Check if form is dirty (used in 'beforeclose' event)
* @panel: Panel (or window) that should be closed
*/
Oger.extjs.confirmDirtyClose = function(panel) {
Ext.Msg.confirm(Oger._('Bestätigung erforderlich'), Oger._('Ungespeicherte Änderungen vorhanden. Trotzdem schliessen?'), function(answerId) {
if(answerId == 'yes') {
// this should work, but I have not tested
//this.hide(null); // window.hide(null) to "unset" animation target - default to null
//this.destroy();
Oger.extjs.forceClose(panel);
//panel.hide(null); // window.hide(null) to "unset" animation target - default to null
//panel.destroy();
}
});
} // eo confirm dirty close
/*
* Force close (bypass the beforclose event)
* @panel: Panel (or window) that should be closed
*/
Oger.extjs.forceClose = function(panel) {
panel.hide(null); // window.hide(null) to "unset" animation target - default to null
panel.destroy();
}; // eo force close
/**
* check if form is dirty and ask for reset
*/
Oger.extjs.formIsUnDirty = function(form, showMsg) {
// if no form given it cannot be dirty?
if (!form) {
return true;
}
// if a form panel is given than get the underlaying basic form
if (typeof form.getForm == 'function') {
form = form.getForm();
}
// check form
if (form.isDirty()) {
var dirtyMsg = '';
if (showMsg) {
dirtyMsg = ' Dirty is: ';
form.items.each(
function(field) {
if (field.isFormField) {
if (typeof field.getXType == 'function' && field.getXType() == 'radiogroup') {
field.eachItem(function(c) {
if (String(c.originalValue) != String(c.getValue())) {
dirtyMsg += ' ' + c.name + ': orig=' + c.originalValue + ', cur=' + c.getValue() + ' (inp=' + c.inputValue + ')';
};
});
}
else {
if (String(field.originalValue) != String(field.getValue())) {
dirtyMsg += ' ' + field.name + ': orig=' + field.originalValue + ', cur=' + field.getValue();
};
};
};
}
);
};
Ext.Msg.confirm(Oger._('Bestätigung erforderlich'), Oger._('Ungespeicherte Änderungen vorhanden. Änderungen rückgängig machen?' + dirtyMsg), function(answerId) {
if(answerId == 'yes') {
form.reset();
}
});
// report as dirty, because eventual reset is a callback function and called later
// a second try is necessary to close without being questened!
return false;
} // eo is dirty
// not dirty
return true;
}; // eo dirty check
/*
* Unset the dirty state of a form
* @form: Form which dirty state should be removed
*/
Oger.extjs.resetDirty = function(form) {
// if a form panel is given than get the underlaying basic form
if (typeof form.getForm == 'function') {
form = form.getForm();
}
var processField = function(field) {
if (field.isFormField) {
if (typeof field.getXType == 'function' &&
(field.getXType() == 'radiogroup' || field.getXType() == 'checkboxgroup')) {
field.eachItem(function(c) {
c.originalValue = c.getValue();
});
}
else if (typeof field.getXType == 'function' && field.getXType() == 'checkboxgroup') {
field.items.each(processField);
}
else if (typeof field.getXType == 'function' && field.getXType() == 'compositefield') {
field.items.each(processField);
}
else {
field.originalValue = field.getValue();
}
}
};
form.items.each(processField);
}; // eo reset dirty
/*
* Empty all fields of a form
* @form: Form for which the fields should be set to empty
*/
Oger.extjs.emptyForm = function(form, resetDirty) {
// if a form panel is given than get the underlaying basic form
if (typeof form.getForm == 'function') {
form = form.getForm();
}
var processField = function(field) {
if (typeof field.getXType == 'function' &&
(field.getXType() == 'radiogroup' || field.getXType() == 'checkboxgroup')) {
field.eachItem(function(c) {
c.originalValue = c.setValue('');
});
}
else if (typeof field.getXType == 'function' && field.getXType() == 'checkboxgroup') {
field.items.each(processField);
}
else if (typeof field.getXType == 'function' && field.getXType() == 'compositefield') {
field.items.each(processField);
}
else if (field.isFormField && typeof field.setValue == 'function') {
field.setValue('');
}
};
form.items.each(processField);
if (resetDirty) {
Oger.extjs.resetDirty(form);
}
}; // eo empty form
/*
* Get invalid fields
* @form: Form to test the fields
*/
Oger.extjs.getInvalidFieldNames = function(form) {
// if a form panel is given than get the underlaying basic form
if (typeof form.getForm == 'function') {
form = form.getForm();
}
var invalidFields = '';
var processField = function(field) {
if (field.isFormField) {
if (typeof field.getXType == 'function' &&
(field.getXType() == 'radiogroup' || field.getXType() == 'checkboxgroup')) {
field.eachItem(function(c) {
if (!c.isValid()) {
invalidFields += c.getName() + '<BR>';
}
});
}
else if (typeof field.getXType == 'function' && field.getXType() == 'checkboxgroup') {
field.items.each(processField);
}
else if (typeof field.getXType == 'function' && field.getXType() == 'compositefield') {
field.items.each(processField);
}
else {
if (!field.isValid()) {
invalidFields += field.getName() + '<BR>';
}
}
}
};
form.items.each(processField);
}; // eo reset dirty
/*
* Workaround for bug in firefox.
* Messageboxes (confirm, alert, ...) are shown behind other windows
* in paticular behind tabpanels.
* Default zseed for window managers is 9000.
* Copied from: http://nicolaematei.wordpress.com/2008/07/02/ext-js-firefox3-z-index-bug/
* DOES NOT WORK AS EXPECTED (02/2011)
*/
this.fireFoxTempZSeed = 9000;
Oger.extjs.fireFoxHighZSeed = function(setHigh){
if(Ext.isGecko3){ // TODO Temp Fix: FF3
if(setHigh){
this.fireFoxTempZSeed = Ext.WindowMgr.zseed;
alert(Ext.WindowMgr.zseed);
Ext.WindowMgr.zseed = 10000;
}
else { // reset to old seed
Ext.WindowMgr.zseed = this.fireFoxTempZSeed;
}
}
}; // eo firefox work around
/*
* Form saved message
*/
Oger.extjs.submitMsg = function(success, addMsg) {
if (typeof success == 'undefined' || success === null) {
success = true;
}
if (typeof addMsg == 'undefined' || addMsg === null) {
addMsg = '';
}
if (success) {
Ext.Msg.alert(Oger._('Ergebnis'), Oger._('Datensatz wurde erfolgreich gespeichert.' + addMsg));
}
else {
Ext.Msg.alert(Oger._('Fehler'), Oger._('Datensatz konnte nicht gespeichert werden.'));
}
}; // eo saved ok message