/
env.js
10272 lines (9188 loc) · 383 KB
/
env.js
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
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* Janox JavaScript Environment
* JavaScript 5
*
*
* This file is part of Janox.
*
* Janox is free software; you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 3 of the License, or (at your option)
* any later version.
*
* Janox is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*
* This script contains Janox JavaScript Environment, the Janox WEB client side
* core runtime.
* .: Environment configuration functions
* .: Dynamic HTML
* .: Ajax style functions
* .: POST/GET information management
*
* @name jxjse
* @package jxrnt/htdocs/js/env.js
* @version 2.6
* @copyright Tommaso Vannini (tvannini@janox.it) 2007
* @author Tommaso Vannini (tvannini@janox.it)
*/
String.prototype.trim = function() { return this.replace(/^\s+|\s+$/g, ""); };
String.prototype.ltrim = function() { return this.replace(/^\s+/, ""); };
String.prototype.rtrim = function() { return this.replace(/\s+$/, ""); };
/**
* Implement string split by separator with max chunks limit
*
* @param {String} separator
* @param {Integer} limit
* @return {Array}
*/
String.prototype.explode = function(separator, limit) {
var arr = this.split(separator);
if (limit) {
arr.push(arr.splice(limit - 1).join(separator));
}
return arr;
};
/**
* Decode HTML entities in a text, if any, using an TEXTAREA tag
*
*/
String.prototype.decode = function() {
if (o2jse.decoderObj == null) {
o2jse.decoderObj = document.createElement("textarea");
}
o2jse.decoderObj.innerHTML = this;
var returnText = o2jse.decoderObj.value;
o2jse.decoderObj.innerHTML = "";
return returnText;
};
/**
* Instance of o2jse - Top level ref object for Janox JavaScript environment.
* Definition in o2jse.init().
* Provides desktop functionalities and ref root for all jxjs objects.
*
*/
var o2jse = {
rntAlias : "/janox/", /* Alias of virtual host where is Janox runtime */
appAlias : "/", /* Alias of virtual host where is Janox application */
charSet : "UTF-8", /* Page character set */
sessName : "PHPSESSID", /* PHP session name */
instId : '', /* Application instance ID (used by keep-alive) */
user : "default", /* Currently logged user */
superUser : false, /* If user is logged as "root" (or is DEVELOPER) */
dev : false, /* Developer tools collection or FALSE if no devmode */
decimalsPoint : ',', /* Character to use as decimal point separator */
thousandsPoint : ' ', /* Character to use as thousands point separator */
keepAlive : 0, /* Number of seconds for keep-alive sending (0=OFF) */
keepAliveHdl : null, /* Keep-alive timeout handler */
refreshTime : 0, /* Number of seconds for refresh count-down (0=OFF) */
maxMultiReq : 5, /* Max allowed number of unresponsed requests */
menuStyle : 'T', /* Menu style [T]op or [L]eft */
doc : false, /* If JXDocumentor is anabled for application */
profiling : false, /* If profiling capabilities enabled and mode (M|C|B)*/
cliMode : true, /* If Full-AJAX behavior is enabled */
waitOnCtrl : true, /* If waiting icon has to be displayed on last ctrl */
netErr : false, /* If network errors reporting is enabled */
fastMsgTime : 5, /* Fast messages timeout to fade away */
contMenuApp : false, /* If context menu shows application menu */
contMenuNewSess : false, /* If context menu shows "Open new session" */
contMenuHelp : false, /* If context menu shows Help request */
started : false, /* If o2jse.init() method has already been called */
submitting : false, /* If o2jse is already submitting post data */
submitCtrl : false, /* Object that started submitting (submit-on-change) */
safeChanges : [], /* List of controls changed since last submit-on-chg */
infoForm : null, /* Reference to o2form_info form */
elBody : null, /* HTML BODY element for the document */
glassObj : null, /* Full screen "glass" while objects moving & sizing */
waitObj : null, /* DIV element containing wait-image during request */
clockObj : null, /* DIV shown while waiting */
decoderObj : null, /* TEXTAREA object used to decode HTML entities */
runnerObj : null, /* SCRIPT object used to eval JS code */
reqData : {}, /* List of posted information in previous request */
exeTree : [], /* Executions chain: running programs and actions */
keyList : [], /* List of enabled control keys */
reposWins : [], /* List of windows to be repositioned */
waitingScripts : 0, /* Scripts waiting to be evaluated */
maximizedWin : false, /* Maximized active form name for browser win resize */
winResizing : false, /* Resizing event on browser window */
closeLogout : true, /* Executing logout on browser window close */
closeWait : false /* Waiting for keyboard to close page (see init) */
};
/**
* Client browser configurations and informations
*
*/
o2jse.cli = {
agent : navigator.userAgent, /* Client browser agent signature */
width : 0, /* Browser window width */
height : 0 /* Browser window height */
};
/**
* Sets up environment.
* This function should be placed in the onLoad event of document.body
*
*/
o2jse.init = function() {
// ______________________________________ Get character-set from META Content-Type ___
var metas = document.getElementsByTagName("meta");
for (var i = 0; i < metas.length; i++) {
if (metas[i].httpEquiv == "Content-Type") {
var c = metas[i].content;
o2jse.charSet = c.substring(c.lastIndexOf("=") + 1);
break;
}
}
// ____________________________________________________ Set environment properties ___
o2jse.appAlias = location.protocol + "//" +
location.host +
location.pathname.substr(0, location.pathname.lastIndexOf("/")) +
"/";
o2jse.elBody = (document.body || document.getElementsByTagName("body")[0]);
o2jse.infoForm = document.forms.o2form;
o2jse.cli.width = (window.innerWidth != null ? window.innerWidth :
(document.documentElement && document.documentElement.clientWidth ?
document.documentElement.clientWidth : o2jse.elBody.clientWidth));
o2jse.cli.height = (window.innerHeight != null ? window.innerHeight :
(document.documentElement &&
document.documentElement.clientHeight ?
document.documentElement.clientHeight :
o2jse.elBody.clientHeight));
o2jse.infoForm['o2_action'].value = '';
o2jse.infoForm['o2lastform'].value = '';
o2jse.infoForm['o2lastctrl'].value = '';
o2jse.submitting = false;
o2jse.started = true;
// ________________________________________________________________ Init all stuff ___
if (jxjs.respTimeOut) {
clearTimeout(jxjs.respTimeOut);
jxjs.respTimeOut = null;
}
// ___________________________________________________________ Init AJAX Requester ___
o2jse.requester.init();
// ___________________________________________________________ Development console ___
if (o2jse.devName && !o2jse.lab.contWin) {
o2jse.lab.init();
}
// ============================================= Register partners in context menu ===
o2jse.cMenu.partnersB = [];
o2jse.cMenu.partnersA = [];
// _________________________________________ Register calendar to use context menu ___
o2jse.cMenu.regPartner(o2jse.cale.initContMenu, true);
// _____________________ Register grid columns personalization to use context menu ___
if (o2jse.tab.gridPlus) {
o2jse.cMenu.regPartner(o2jse.tab.initContMenu, true);
}
// _________________________________ Register treeview control to use context menu ___
o2jse.cMenu.regPartner(o2jse.tv.initContMenu, true);
// __________________________________ Register developer tools to use context menu ___
if (o2jse.devName) {
o2jse.cMenu.regPartner(o2jse.dev.addDevMenu);
}
// _____________________________________ Register help request to use context menu ___
if (o2jse.contMenuHelp) {
o2jse.cMenu.regPartner(o2jse.docInitContMenu);
}
// ________________________________ Manage right-click events to open context menu ___
document.oncontextmenu = o2jse.cMenu.setOn;
// ________________________________________________________________ Set keep-alive ___
if (o2jse.keepAlive && !o2jse.keepAliveHdl) {
o2jse.keepAliveExe = function() {
jxjs.beacon('keepalive', { 'instid' : o2jse.instId });
clearTimeout(o2jse.keepAliveHdl);
o2jse.keepAliveHdl = setTimeout(o2jse.keepAliveExe,
o2jse.keepAlive);
};
o2jse.keepAliveExe();
}
// ___________________________________________________ Set refresh (update notify) ___
if (o2jse.notify.timeOut) {
clearTimeout(o2jse.notify.timeOut);
o2jse.notify.timeOut = null;
}
if (o2jse.refreshTime) {
o2jse.notify.timeOut = setTimeout(o2jse.notify.exeReq, o2jse.refreshTime);
}
// _____________________________________________________ Set progress bars refresh ___
if (o2jse.progress.active && !o2jse.progress.timeOut) {
o2jse.progress.timeOut = setTimeout(function() {
delete o2jse.progress.timeOut;
o2jse.requester.exe('progress',
'JXSESSNAME=' +
o2jse.sessName,
o2jse.progress,
o2jse.progress.getCode,
true);
},
3000);
}
// ________________________________________________ Windows positioning and sizing ___
o2jse.reposAllWins();
window.onresize = function() {
clearTimeout(o2jse.winResizing);
o2jse.winResizing = setTimeout(o2jse.resizeBrowserWindow, 500);
};
// _________________________________________________________ OnLoad portable logic ___
o2jse.waitDocReady();
// ______________________________________________ Application logout on page close ___
if (o2jse.closeLogout) {
window.onunload = function() { jxjs.beacon('logout'); };
window.onmouseover = function () { if (!o2jse.closeWait) {
window.onunload = null; } };
window.onmouseout = function () { if (!o2jse.submitting) {
window.onunload = function() {
jxjs.beacon('logout');
}; } };
window.onclick = function () { window.onunload = null;
o2jse.closeWait = false; };
document.onkeydown = function (e) {
if (e.key == 'Control' || e.key == 'Alt') {
if (!o2jse.submitting) {
window.onunload = function() { jxjs.beacon('logout'); };
o2jse.closeWait = true;
}
}
else {
window.onunload = null;
o2jse.closeWait = false;
}
};
}
// _____________________________________________________________ Set focus control ___
if (o2jse.ctrl.focusCtrl) {
o2jse.cmd.focus(o2jse.ctrl.focusCtrl, o2jse.ctrl.focusMode);
}
};
/**
* Waits for all scripts to be ended, then executes the o2jse.docReady if any.
*
*/
o2jse.waitDocReady = function() {
if (o2jse.waitingScripts > 0) {
setTimeout(o2jse.waitDocReady, 10);
}
else {
if (o2jse.docReady) {
o2jse.docReady();
o2jse.docReady = null;
}
}
};
/**
* Manage resize events on browser window.
* Uses timeout to run only once at the end of resizing.
*
*/
o2jse.resizeBrowserWindow = function() {
if (o2jse.started) {
o2jse.cli.width = (window.innerWidth != null ?
window.innerWidth :
(document.documentElement &&
document.documentElement.clientWidth ?
document.documentElement.clientWidth :
o2jse.elBody.clientWidth));
o2jse.cli.height = (window.innerHeight != null ?
window.innerHeight :
(document.documentElement &&
document.documentElement.clientHeight ?
document.documentElement.clientHeight :
o2jse.elBody.clientHeight));
o2jse.reposAllWins();
if (o2jse.maximizedWin) {
maxWin = document.getElementById(o2jse.maximizedWin[0] + '_' +
o2jse.maximizedWin[1]);
o2jse.ctrl.init(maxWin);
formInfo = maxWin.o2;
// ________________________________________________________ Refresh action ___
var refrAct = formInfo.r;
// Set <form>_jxcmd = '3' to remove 'maximized' flag on form (server-side) ___
var cmdField = o2jse.infoForm[o2jse.maximizedWin[0] +
o2jse.maximizedWin[1] + "_jxcmd"];
if (cmdField) {
cmdField.value = '4';
o2jse.infoForm['o2_modfields'].value+= cmdField.name + ";";
// __________________________________________ Refresh action on resize ___
jxjs.refresh(formInfo, refrAct);
}
}
}
};
/**
* Execute a JS code in the global scope.
*
* NOTE: EVAL inside a TRY/CATCH statement, inside a SCRIPT tag.
* This allows variables global scope and catching exceptions (syntax errors too)
* inside EVAL.
*
* @param {String} codeToExe Code to execute
*/
o2jse.exeCode = function(codeToExe) {
o2jse.codeToExe = codeToExe;
o2jse.runnerObj = document.createElement("script");
o2jse.runnerObj.text = "try { eval(o2jse.codeToExe); o2jse.codeToExe = null; } " +
"catch(ex) { jxjs.cError(ex, o2jse.codeToExe); } ";
document.getElementsByTagName("head")[0].appendChild(o2jse.runnerObj);
};
/**
* Decode HTML entities in a text, if any.
*
* @param {String} decodeText Text to decode
*/
o2jse.textDecode = function(decodeText) {
if (o2jse.decoderObj == null) {
o2jse.decoderObj = document.createElement("textarea");
}
o2jse.decoderObj.innerHTML = decodeText;
var returnText = o2jse.decoderObj.value;
o2jse.decoderObj.innerHTML = "";
return returnText;
};
/**
* Sets execution ID for the o2JS environment.
* Execution ID is the higher program ID running (o2_app->progressivo_istanze).
*
* @param {Integer} exeId Execution ID to set for environment
*/
o2jse.setExeId = function(exeId) {
document.forms.o2form['o2_prgexeid'].value = exeId;
};
/**
* Load a requested JavaScript script in the page
*
* @param {String} fileToLoad JavaScript file to be loaded
*/
o2jse.loadScript = function(fileToLoad) {
var hTag = document.getElementsByTagName("head")[0];
var sTags = hTag.getElementsByTagName("script");
var addS = true;
for (i = 0; i < sTags.length; i++) {
if (sTags[i].src == fileToLoad) {
addS = false;
break;
}
}
if (addS) {
o2jse.waitingScripts++;
var se = o2jse.createEl(hTag, "script");
se.onload = function () { o2jse.waitingScripts--; };
se.src = fileToLoad;
}
};
/**
* Load a requested CSS file in the page
*
* @param {String} fileToLoad CSS file to be loaded
* @param {String} media Media type (screen, print, ...)
*/
o2jse.loadCSS = function(fileToLoad, media) {
var hTag = document.getElementsByTagName("head")[0];
var lTags = hTag.getElementsByTagName("link");
var addL = true;
for (i = 0; i < lTags.length; i++) {
if (lTags[i].href == fileToLoad) {
addL = false;
break;
}
}
if (addL) {
var le = o2jse.createEl(hTag, "link");
le.rel = "stylesheet";
le.href = fileToLoad;
if (media) {
le.media = media;
}
}
};
/**
* Stop executions (click on btn, navigator, ...) to preserve waiting requests
* (submit-on-change)
*
* @param {Object} eventObj Event object originating the call, if any
*/
o2jse.stopExe = function(eventObj) {
if (eventObj) {
o2jse.event.std(eventObj).stop();
}
// _____________________________________________ Reset focus to submitting control ___
setTimeout(function() { o2jse.cmd.focus(o2jse.submitCtrl); }, 200);
// __________________________________________________ Close open combo-list if any ___
o2jse.lu.listOff();
o2jse.fastMsg.show("<center>ACTION BLOCKED</center>" +
"Press TAB or ENTER to validate changed data");
return false;
};
/**
* Change the status-bar content
*
* @param {String} txt_code HTML or text content to display
*/
o2jse.statusMsg = function(txt_code) {
document.getElementById("o2statustext").innerHTML = txt_code;
};
/**
* Creates an HTML element and sets environment object binding
*
* @param {Object} inObj Parent object
* @param {String} elType HTML element type
* @param {String} elClass CSS class name
* @param {String} elHtml Tag HTML content
* @return {Object}
*/
o2jse.createEl = function(inObj, elType, elClass, elHtml) {
var lEl = document.createElement(elType);
if (elClass) {
lEl.className = elClass;
}
if (elHtml) {
lEl.innerHTML = elHtml;
}
if (inObj) {
inObj.appendChild(lEl);
}
return lEl;
};
/**
* Creates an HTML INPUT element and sets environment object binding
*
* @param {Object} inObj Parent object
* @param {String} elType INPUT type [TEXT|INPUT|HIDDEN] default HIDDEN
* @param {String} elClass CSS class name
* @param {String} elValue Value of INPUT field
* @param {Sstring} fieldName Name for INPUT field
*/
o2jse.createInput = function(inObj, elType, elClass, elValue, fieldName) {
var lEl = document.createElement("INPUT");
lEl.type = (elType ? elType : "hidden");
if (fieldName) {
lEl.name = fieldName;
}
if (elValue) {
lEl.value = elValue;
}
if (elClass) {
lEl.className = elClass;
}
inObj.appendChild(lEl);
return lEl;
};
/**
* Removes an HTML element from its parent
*
* @param {Object} objToRemove Object to be removed
*/
o2jse.removeEl = function(objToRemove) {
if (objToRemove) {
if (typeof objToRemove == "string") {
if (elementObj = document.getElementById(objToRemove)) {
o2jse.removeEl(elementObj);
}
}
else if (objToRemove.parentNode) {
objToRemove.parentNode.removeChild(objToRemove);
}
}
};
/**
* Finds absolute position of an element, summing all object ancestors positions. Position
* is returned as an object in the form:
*
* {x : x_pos, y : y_pos}
*
* @param {Object} targetObj Object to find out position for
* @returns {Object}
*/
o2jse.getPos = function(targetObj) {
var pos = { x : targetObj.offsetLeft, y : targetObj.offsetTop };
var level = targetObj;
// ________________________________________________________ Sum all parents offset ___
while (level = level.offsetParent) {
pos.x += level.offsetLeft;
pos.y += level.offsetTop;
}
// ___________________________________________________ Subtract all parents scroll ___
level = targetObj;
while (level = level.parentNode) {
if (level.tagName.toLowerCase() == "body") {
break;
}
else {
pos.x -= level.scrollLeft;
pos.y -= level.scrollTop;
}
}
return pos;
};
/**
* Check visibility of targetObj in its parent: if parent object is scrollable and if
* targetObj is not visible then parent is scrolled to make it visible.
*
* @param {Object} targetObj Object to make visible
*/
o2jse.showByScroll = function(targetObj) {
if (targetObj.offsetTop < targetObj.parentNode.scrollTop + 20) {
targetObj.parentNode.scrollTop = targetObj.offsetTop;
}
else if (targetObj.offsetTop >
(targetObj.parentNode.scrollTop + targetObj.parentNode.offsetHeight - 20)) {
targetObj.parentNode.scrollTop = targetObj.offsetTop +
targetObj.parentNode.offsetHeight;
}
};
/**
* Finds tab index value for requested field
*
* @param {Object} targetObj INPUT field to find out tab index
*/
o2jse.getTabIndex = function(targetObj) {
if (targetObj.tabIndex) {
return targetObj.tabIndex;
}
else {
for (var i = (o2jse.infoForm.elements.length - 1); i > -1; i--) {
if (o2jse.infoForm.elements[i] == targetObj) {
return i;
}
}
return -1;
}
};
/**
* Sets tab index value for requested field
*
* @param {Object} targetObj INPUT field to find out tab index
* @param {Integer} newIndex New tab index to set for field
*/
o2jse.setTabIndex = function(targetObj, newIndex) {
if (newIndex < 0) {
newIndex = 0;
}
if (newIndex > (o2jse.infoForm.elements.length - 1)) {
newIndex = (o2jse.infoForm.elements.length - 1);
}
var upIndex = 0;
for (var i = (o2jse.infoForm.elements.length - 2); i > -1; i--) {
upIndex = (i >= newIndex ? 1 : 0);
if (o2jse.infoForm.elements[i] != targetObj) {
o2jse.infoForm.elements[i].tabIndex = i + upIndex;
}
}
targetObj.tabIndex = newIndex;
};
/**
* Looks for first "real" node child, skipping possible #text nodes
*
* @param {Object} parentObj Object to look in for children
*/
o2jse.firstRealChild = function(parentObj) {
var fieldLocal = parentObj.childNodes[0];
while (fieldLocal.nodeType != 1) {
if (!(fieldLocal = fieldLocal.nextSibling)) {
break;
}
}
return fieldLocal;
};
/**
* Get the closest parent with the given tag name.
*/
o2jse.getParentTag = function(obj, tag) {
var obj_parent = obj.parentNode;
if (!obj_parent) {
return false;
}
else if (obj_parent.tagName.toLowerCase() == tag.toLowerCase()) {
return obj_parent;
}
else {
return o2jse.getParentTag(obj_parent, tag);
}
};
/**
* Sets right windows position on resize.
* This method is also used to set right position for first displayed window after login,
* because we don't have real browser dimensions yet.
*
*/
o2jse.reposAllWins = function() {
for (var winIndex in o2jse.reposWins) {
o2jse.win.repos(o2jse.reposWins[winIndex]);
}
};
/**
* Environment configuration utility functions collection.
* Configuration functions are supposed to be called before o2jse.init() method.
*
*/
o2jse.conf = {};
/**
* Sets Janox runtime web path
*
* @param {String} aliasStr Alias to set
*/
o2jse.conf.rntAlias = function(aliasStr) {
o2jse.rntAlias = aliasStr;
};
/**
* Sets current PHP session name
*
* @param {String} phpSessName PHP session name
*/
o2jse.conf.sessName = function(phpSessName) {
o2jse.sessName = phpSessName;
};
/**
* Sets logout execution on close or browsing away from application page
*
* @param {String} phpSessName PHP session name
*/
o2jse.conf.closeLogout = function(closeOnLogout) {
o2jse.closeLogout = (closeOnLogout ? true : false);
};
/**
* Sets keep-alive count-down to force reload
*
* @param {Integer} tSecs Number of seconds of the count-down
*/
o2jse.conf.keepAlive = function(tSecs, instId) {
o2jse.keepAlive = tSecs * 1000;
o2jse.instId = instId;
};
/**
* Sets refresh time to call refresh program (update notify)
*
* @param {Integer} tSecs Number of seconds of the count-down
*/
o2jse.conf.setRefresh = function(tSecs) {
o2jse.refreshTime = tSecs * 1000;
};
/**
* Sets the maximum number of unresponded requests user is allowed to start
*
* @param {Integer} reqs Number of requests
*/
o2jse.conf.setMaxReq = function(reqs) {
o2jse.maxMultiReq = reqs;
};
/**
* Displays a waiting icon on submitting control.
* It's used both in Full-AJAX ON and OFF.
*
* @param {Boolean} wait_on_ctrl If waiting icon has to be displayed
*/
o2jse.conf.setWaiting = function(wait_on_ctrl) {
o2jse.waitOnCtrl = (wait_on_ctrl ? true : false);
};
/**
* Set timeout for fast messages to fade away
* It's used both in Full-AJAX ON and OFF.
*
* @param {Integer} timeOut Time before fading away
*/
o2jse.conf.setFastMsgTime = function(timeOut) {
o2jse.fastMsgTime = timeOut;
};
/**
* Enables JXDocumentor for application
*
*/
o2jse.conf.doc = function() {
o2jse.doc = true;
};
/**
* Set main menu style
*
* @param {String} mStyle [T]op or [L]eft
*/
o2jse.conf.menuStyle = function(mStyle) {
o2jse.menuStyle = mStyle;
};
/**
* Set context menu options visibility
*
* @param {Object} confList List object of configuration parameters
*/
o2jse.conf.contextMenu = function(confList) {
o2jse.contMenuApp = confList.app;
o2jse.contMenuNewSess = confList.newsess;
o2jse.contMenuHelp = confList.help;
};
/**
* Sets currently logged user
*
* @param {String} userId Logged user
*/
o2jse.conf.user = function(userId) {
o2jse.user = userId;
if (userId.toLowerCase() == "root") {
o2jse.superUser = true;
}
};
/**
* Sets the currently logged developer name and starts development mode for application
* test
*
* @param {String} devName Developer name
*/
o2jse.conf.devel = function(devName) {
o2jse.devName = devName;
o2jse.superUser = true;
};
/**
* Sets o2 runtime string to be used as decimals separator
*
* @param string pointStr Separator to be used
*/
o2jse.conf.decimalsPoint = function(pointStr) {
o2jse.decimalsPoint = pointStr;
};
/**
* Sets o2 runtime string to be used as thousands separator
*
* @param string pointStr Separator to be used
*/
o2jse.conf.thousandsPoint = function(pointStr) {
o2jse.thousandsPoint = pointStr;
};
/**
* Enables runtime profiling capabilities for SuperUser
*
* @param string profLevel Profiling level ([M]enu | [C]ontrol | [B]oth)
*/
o2jse.conf.setProfiling = function(profLevel) {
o2jse.profiling = profLevel;
};
/**
* Adds a key to the list of controlled keys and links it to an action
*
* @param integer keyCode ASCII code of key to control
* @param boolean shiftBtn If SHIFT button has to be pressed
* @param boolean ctrlBtn If CTRL button has to be pressed
* @param boolean altBtn If ALT button has to be pressed
*/
o2jse.conf.addKey = function(keyCode, shiftBtn, ctrlBtn, altBtn, actCode) {
o2jse.keyList.push({code : keyCode,
shift : shiftBtn,
ctrl : ctrlBtn,
alt : altBtn,
exe : actCode});
};
/**
* Set db-grid control extra functions
*
* @param {Boolean} autoSave Auto or manual settings saving mode
* @param {Boolean} multiDel Enables multi row deletion from context menu
*/
o2jse.conf.gridPlus = function(autoSave, multiDel) {
o2jse.tab.gridPlus = true;
o2jse.tab.autoSaveSettings = autoSave;
o2jse.tab.gridMultiDel = multiDel;
};
/**
* Set db-grid action on double click
*
* @param {String} act Action to be executed []Nothing, [D]etail, [S]elect, [B]oth
*/
o2jse.conf.gridDblClick = function(act) {
o2jse.tab.dblClickAct = act;
};
/**
* Set db-grid paging by wheel
*
* @param {Boolean} wheel If TRUE enables wheel use in grid
*/
o2jse.conf.gridWheel = function(wheel) {
o2jse.tab.wheelPaging = (wheel ? true : false);
};
/**
* Set lookup control request delay time.
* This is the time after which request will be fired while typing.
* Minimum allowed time is 300 ms.
*
* @param {Boolean} reqTime Timein milliseconds
*/
o2jse.conf.luReqTime = function(reqTime) {
o2jse.lu.reqDelay = (reqTime >= 300 ? reqTime : 300);
};
/**