-
Notifications
You must be signed in to change notification settings - Fork 0
/
Controls.js
2504 lines (2077 loc) · 102 KB
/
Controls.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
// This file is part of DQX - (C) Copyright 2014, Paul Vauterin, Ben Jeffery, Alistair Miles <[email protected]>
// This program is free software licensed under the GNU Affero General Public License.
// You can find a copy of this license in LICENSE in the top directory of the source code or at <http://opensource.org/licenses/AGPL-3.0>
/************************************************************************************************************************************
*************************************************************************************************************************************
Controls are a set of UI widgets (edit boxes, checkboxes, ...) that can be
* put on a Framework.Form FramePanel
* put on a Wizard page
* used as a branch in a Tree (see TreeCtrl.Control)
* used independently
Each control implements at least the following member functions:
- getID : returns the identifier of the control
- modifyEnabled(bool) : modifies the enabled/disabled state of the control
- renderHtml : returns the html string that defines the control
- postCreateHtml : executes necessary code after the control's html was inserted into the DOM (e.g. register event handlers)
NOTE: The 'real' UI widgets are derived from the base class Controls.Control
NOTE: when controls are part of a Form or a Wizard, most actions such as renderHtml and postCreateHtml are called automatically
When used independently, you can call renderHtml explicitely to obtain the markup for the control
In this case, Controls.ExecPostCreateHtml must be called explicitely after the html was added to the DOM
*************************************************************************************************************************************
*************************************************************************************************************************************/
define(["DQX/Utils", "DQX/Msg", "DQX/DocEl", "DQX/Scroller", "DQX/Documentation", "DQX/Externals/spectrum"],
function (DQX, Msg, DocEl, Scroller, Documentation) {
var Controls = {};
Controls.autoCreateListeners = false;//set to true create event listeners for each control
Controls._currentControlNr = 0;
Controls._getNextControlID = function () {
Controls._currentControlNr++;
return "AutoControlID_" + Controls._currentControlNr;
}
Controls._postCreateWaitList = {}
Controls._addToControlPostCreateWaitList = function (ctrl) {
Controls._postCreateWaitList[ctrl.getID()] = ctrl;
}
Controls._removeFromControlPostCreateWaitList = function (ctrl) {
delete Controls._postCreateWaitList[ctrl.getID()];
}
//Call this function to automatically execute any necessary code for controls after the rendering of the control html to the DOM (e.g. registering event handlers).
//In most cases, this function is called automatically by the framework
Controls.ExecPostCreateHtml = function () {
$.each(Controls._postCreateWaitList, function (key, ctrl) {
if (ctrl.isRendered()) {
ctrl.postCreateHtml();
delete Controls._postCreateWaitList[key];
}
});
DQX._registerStaticLinkHandlers();
DQX._registerActionLinkHandlers();
}
DQX.ExecPostCreateHtml = function () { Controls.ExecPostCreateHtml(); }
//Initiate some surveillance code that performs some sanity checks
Controls._surveillance = function () {
$.each(Controls._postCreateWaitList, function (key, ctrl) {
DQX.reportError('Post Html creation not executed for control ' + key);
});
setTimeout(Controls._surveillance, 6000);
}
if (_debug_) Controls._surveillance();
//Stores the status of a control (and subcontrols) to a single object
//NOTE: only controls with specified classID's will be serialised!
Controls.storeSettings = function(ictrl) {
var obj={};
ictrl.applyOnControls(function(actrl) {
if (actrl.getValue) {
var ctrlid = actrl.classID;
if (ctrlid) {
obj[ctrlid]=actrl.getValue();
}
}
});
return obj;
}
//Recalls the status of a control (and subcontrols) from a single object
Controls.recallSettings = function(ictrl, settObj, preventNotify) {
ictrl.applyOnControls(function(actrl) {
if (actrl.modifyValue) {
var ctrlid = actrl.classID;
if ( (ctrlid) && (settObj[ctrlid]!=null) )
actrl.modifyValue(settObj[ctrlid],preventNotify);
}
});
}
////////////////////////////////////////////////////////////////////////////////////////////
// This control can be used to wrap another control control in a styled div
////////////////////////////////////////////////////////////////////////////////////////////
Controls.Wrapper = function (icontrol, wrapperStyle) {
var that = {};
that._control = icontrol;
that.myID = Controls._getNextControlID();
that._wrapperStyle = wrapperStyle;
that.getID = function () {
return that.myID;
}
that.renderHtml = function () {
var el = DocEl.Div({ id: this.myID });
el.setCssClass(that._wrapperStyle)
el.addElem(this._control.renderHtml());
return el.toString();
}
that.postCreateHtml = function () {
this._control.postCreateHtml();
}
that.applyOnControls = function(fnc) {
if ('applyOnControls' in that._control)
that._control.applyOnControls(fnc);
};
that.tearDown = function() {
if ('tearDown' in that._control)
that._control.tearDown();
};
that.setContextID = function (id) {
if ('setContextID' in that._control)
that._control.setContextID(id);
}
return that;
}
////////////////////////////////////////////////////////////////////////////////////////////
// This control can be used to show or hide another control
////////////////////////////////////////////////////////////////////////////////////////////
Controls.ShowHide = function (icontrol) {
var that = {};
that._control = icontrol;
that.myID = Controls._getNextControlID();
that._visible = true;
that.getID = function () {
return that.myID;
}
that.setVisible = function (newStatus) {
if (newStatus != that._visible) {
that._visible = newStatus;
if (newStatus)
$('#' + that.myID).show();
else
$('#' + that.myID).hide();
}
return this;
}
that.renderHtml = function () {
var el = DocEl.Div({ id: this.myID });
el.addStyle('display', 'inline-block');
el.addElem(this._control.renderHtml());
return el.toString();
}
that.postCreateHtml = function () {
if (!that._visible)
$('#' + that.myID).hide();
this._control.postCreateHtml();
}
that.applyOnControls = function(fnc) {
if ('applyOnControls' in that._control)
that._control.applyOnControls(fnc);
};
that.tearDown = function() {
if ('tearDown' in that._control)
that._control.tearDown();
}
return that;
}
////////////////////////////////////////////////////////////////////////////////////////////
// This control can be used to center another control
////////////////////////////////////////////////////////////////////////////////////////////
Controls.AlignCenter = function (icontrol) {
var that = {};
that._control = icontrol;
that.getID = function () {
return that._control.getID();
}
that.renderHtml = function () {
var el1 = DocEl.Div({});
el1.addStyle('text-align', 'center');
var el2 = DocEl.Div({ parent: el1 });
el2.addStyle('display', 'inline-block');
el2.addStyle('text-align', 'left');
// el2.addStyle('background-color', 'rgb(255,192,192)');
el2.addElem(this._control.renderHtml());
return el1.toString();
}
that.postCreateHtml = function () {
this._control.postCreateHtml();
}
that.applyOnControls = function(fnc) {
if ('applyOnControls' in that._control)
that._control.applyOnControls(fnc);
};
that.tearDown = function() {
if ('tearDown' in that._control)
that._control.tearDown();
}
that.setContextID = function (id) {
if ('setContextID' in that._control)
that._control.setContextID(id);
}
return that;
}
////////////////////////////////////////////////////////////////////////////////////////////
// This control can be used to right align another control
////////////////////////////////////////////////////////////////////////////////////////////
Controls.AlignRight = function (icontrol) {
var that = {};
that._control = icontrol;
that.getID = function () {
return that._control.getID();
}
that.renderHtml = function () {
var el = DocEl.Div({ id: this.myID });
el.addStyle('display', 'inline-block');
el.addStyle('float', 'right');
el.addElem(this._control.renderHtml());
return el.toString();
}
that.postCreateHtml = function () {
this._control.postCreateHtml();
}
that.applyOnControls = function(fnc) {
if ('applyOnControls' in that._control)
that._control.applyOnControls(fnc);
};
that.tearDown = function() {
if ('tearDown' in that._control)
that._control.tearDown();
}
that.setContextID = function (id) {
if ('setContextID' in that._control)
that._control.setContextID(id);
}
return that;
}
////////////////////////////////////////////////////////////////////////////////////////////
//Base class for a compound control grouping a list of controls
// A compound control is not a control by itself in a strict sense,
// but acts as a container to layout a set of controls
////////////////////////////////////////////////////////////////////////////////////////////
Controls.CompoundGenericList = function (icontrols) {
var that = {};
that._legend = '';
that._controls = [];
that.myID = Controls._getNextControlID();
that._visible = true;
that._autoFillX = true;
that._legendClass = "DQXFormFieldSet";
//Clears the list of member controls
that.clear = function () {
that.tearDown();
that._controls = [];
}
//Determines whether or not the control fills the full horizontal space
that.setAutoFillX = function(status) { this._autoFillX = status; return this; }
that.setID = function(iid) {
that.myCustomID = iid;
return that;
}
//add a new control to the list (append at the end)
that.addControl = function (item) {
DQX.requireMemberFunction(item, 'getID');
that._controls.push(item);
return item;
}
//add a new control to the list (insert at top)
that.addControlTop = function (item) {
DQX.requireMemberFunction(item, 'getID');
that._controls.unshift(item);
return item;
}
that.tearDown = function() {
$.each(that._controls, function(idx, ctrl) {
if ('tearDown' in ctrl)
ctrl.tearDown();
});
}
if (icontrols)
$.each(icontrols, function (idx, ctrl) { that.addControl(ctrl); });
//Sets a header legend for the group
that.setLegend = function (txt) {
this._legend = txt; return this;
}
that.setLegendSimple = function () {
that._legendClass = "DQXFormFieldSetSimple";
return this;
}
that.setLegendClass = function (clss) {
that._legendClass = clss;
return this;
}
that.getID = function () {
if (that.myCustomID)
return that.myCustomID;
if (this._controls.length == 0) DQX.reportError('Compound control has no components');
return this._controls[0].getID(id);
}
that.setContextID = function (id) {
for (var i = 0; i < this._controls.length; i++)
this._controls[i].setContextID(id);
}
//Modify the enabled status of all member controls
that.modifyEnabled = function (newstate) {
for (var i = 0; i < this._controls.length; i++)
this._controls[i].modifyEnabled(id);
return that;
}
that.postCreateHtml = function () {
for (var i = 0; i < this._controls.length; i++)
this._controls[i].postCreateHtml(id);
setTimeout(function () {
for (var i = 0; i < that._controls.length; i++)
if (that._controls[i]._hasDefaultFocus)
that._controls[i].setFocus();
}, 200);
}
//Finds & returns a member control by id
that.findControl = function (id) {
for (var i = 0; i < this._controls.length; i++) {
var rs = this._controls[i].findControl(id);
if (rs != null) return rs;
}
return null;
}
that.applyOnControls = function(fnc) {
$.each(that._controls, function(idx,ctrl) {
if ('applyOnControls' in ctrl)
ctrl.applyOnControls(fnc);
});
};
return that;
}
////////////////////////////////////////////////////////////////////////////////////////////
//A compound control grouping a list of controls in a horizontal way
////////////////////////////////////////////////////////////////////////////////////////////
Controls.CompoundHor = function (icontrols) {
var that = Controls.CompoundGenericList(icontrols);
that.renderHtml = function () {
var st = '';
if (!that._autoFillX)
st += '<div style="display:inline-block">';
if (this._legend.length > 0) {
st += '<fieldset class="{cls}">'.DQXformat({cls:that._legendClass});
st += '<legend>' + this._legend + '</legend>';
}
for (var i = 0; i < this._controls.length; i++)
st += this._controls[i].renderHtml();
if (this._legend.length > 0) {
st += '</fieldset>';
}
if (!that._autoFillX)
st += '</div>';
return st;
}
return that;
}
Controls.CompoundFloat = function (icontrols) {
var that = Controls.CompoundGenericList(icontrols);
that.renderHtml = function () {
var st = '';
st += '<div style="display:inline-block">';
for (var i = 0; i < this._controls.length; i++) {
if (i === 0)
st += '<div style="float:left">';
else
st += '<div>';
st += this._controls[i].renderHtml();
if (i === 0)
st += '</div>';
}
st += '</div>';
return st;
}
return that;
}
////////////////////////////////////////////////////////////////////////////////////////////
//A compound control grouping a list of controls in a horizontal way
////////////////////////////////////////////////////////////////////////////////////////////
Controls.CompoundVert = function (icontrols) {
var that = Controls.CompoundGenericList(icontrols);
that.treatAsBlock = false;
that._margin = 3;
that._leftIndent = 0;
that.setMargin = function(margin) {
that._margin = margin;
return that;
}
that.setLeftIndent = function(vl) {
that._leftIndent = vl;
if (!that.treatAsBlock)
DQX.reportError('Invalid combination of settings');
return that;
}
that.setTreatAsBlock = function() {
that.treatAsBlock = true;
return that;
}
that.renderHtml = function () {
var st = '';
if (that.treatAsBlock || (!that._autoFillX) )
st += '<div style="display:inline-block;vertical-align:top;margin-left:{marginleft}px">'.DQXformat({
marginleft: that._leftIndent
});
if (this._legend.length > 0) {
st += '<fieldset class="{cls}">'.DQXformat({cls:that._legendClass});
st += '<legend>' + this._legend + '</legend>';
}
for (var i = 0; i < this._controls.length; i++) {
var el = DocEl.Div({});
if (that._margin>0) {
if (i>0)
el.addStyle('margin-top', ((i>0)?(this._margin):(this._margin/2)) + 'px');
if (i<this._controls.length-1)
el.addStyle('margin-bottom', ((i<this._controls.length-1)?(this._margin):(this._margin/2)) + 'px');
}
el.addElem(this._controls[i].renderHtml());
st += el.toString();
}
if (this._legend.length > 0) {
st += '</fieldset>';
}
if (that.treatAsBlock || (!that._autoFillX) )
st += '</div>';
return st;
}
return that;
}
Controls.BaseCustom = function (stackVertical) {
if (!stackVertical)
var that = Controls.CompoundHor([]);
else
var that = Controls.CompoundVert([]);
return that;
}
//////////////////////////////////////////////////////////////////////////
Controls.Section = function (icontrol, settings) {
var that = {};
that._control = icontrol;
that.myID = Controls._getNextControlID();
that._visible = true;
that._headerStyleClass = 'DQXControlSectionHeader';
that._bodyStyleClass = 'DQXControlSectionBody';
that._title = settings.title;
//that._visible = true;
that._canCollapse = true;
that._defaultCollapsed = false;
if (settings.headerStyleClass)
that._headerStyleClass = settings.headerStyleClass;
if (settings.bodyStyleClass)
that._bodyStyleClass = settings.bodyStyleClass;
if (settings.canCollapse === false)
that._canCollapse = false;
if (settings.defaultCollapsed)
that._visible = false;
that.getID = function () {
return that.myID;
}
that._createButtonHtml = function (_collapsed) {
return '<span class="fa {ic}" style="font-size: 12px"></span>'.DQXformat({ic:_collapsed?'fa-plus-circle':'fa-minus-circle'});
//return '<IMG SRC="' + DQX.BMP(_collapsed ? 'morelines.png' : 'lesslines.png') + '" border=0 ALT="" TITLE="" class="DQXTreeButtonImage" style="float:left;padding-right:6px">';
}
that.renderHtml = function () {
that.myIDHeader = that.myID+'header';
that.myIDButton = that.myID+'collapserbutton';
that.myIDBody = that.myID+'body';
var el = DocEl.Div({ id: this.myID });
var header = DocEl.Div({ parent: el , id:that.myIDHeader});
header.setCssClass(that._headerStyleClass);
if (that._canCollapse) {
header.addStyle('cursor', 'pointer');
var buttondv = DocEl.Div({ parent: header, id:that.myIDButton });
buttondv.addStyle('width','20px');
buttondv.addStyle('height','15px');
buttondv.setCssClass("DQXTreeButton");
buttondv.addElem(that._createButtonHtml(!that._visible));
}
header.addElem(that._title);
var body = DocEl.Div({ parent: el, id:that.myIDBody });
body.setCssClass(that._bodyStyleClass);
if (!that._visible)
body.addStyle('display','none');
body.addElem(this._control.renderHtml());
return el.toString();
}
that.postCreateHtml = function () {
if (that._canCollapse) {
var clickElem = $('#' + that.myIDHeader);
clickElem.click(function() {
that._visible = !that._visible;
var subdiv = $('#' + that.myIDBody);
if (!that._visible) {
subdiv.slideUp(250);
if (that.onCollapsing)
that.onCollapsing();
}
else {
subdiv.slideDown(250);
if (that.onExpanding)
that.onExpanding();
}
setTimeout(function() {
$('#' + that.myIDButton).html(that._createButtonHtml(!that._visible));
}, 300)
});
}
this._control.postCreateHtml();
}
that.applyOnControls = function(fnc) {
if ('applyOnControls' in that._control)
that._control.applyOnControls(fnc);
};
that.tearDown = function() {
if ('tearDown' in that._control)
that._control.tearDown();
}
return that;
}
////////////////////////////////////////////////////////////////////////////////////////////
//A compound control grouping a list of controls on a grid
////////////////////////////////////////////////////////////////////////////////////////////
Controls.CompoundGrid = function () {
var that = {};
that._controlRows = [];
that.sepH = 12;
that.sepV = 5;
that._legend = null;
that._autoFillX = true;
//Clears the member controls
that.clear = function () {
that._controlRows = [];
}
that.setSeparation = function(seph, sepv) {
that.sepH = seph;
that.sepV = sepv;
return that;
}
//Sets a header legend for the group
that.setLegend = function (txt) { this._legend = txt; return this; }
that.setID = function(iid) {
that.myCustomID = iid;
return that;
}
//Determines whether or not the control fills the full horizontal space
that.setAutoFillX = function(status) { this._autoFillX = status; return this; }
//Adds a member control
that.setItem = function (rowNr, colNr, item) {
DQX.requireMemberFunction(item, 'getID');
while (this._controlRows.length <= rowNr)
this._controlRows.push([]);
while (this._controlRows[rowNr].length <= colNr)
this._controlRows[rowNr].push(null);
this._controlRows[rowNr][colNr] = item;
return item;
}
//Gets a member control by position in the grid
that.getItem = function (rowNr, colNr) {
if ((rowNr < 0) || (rowNr >= this._controlRows.length))
return null;
if ((colNr < 0) || (colNr >= this._controlRows[rowNr].length))
return null;
return this._controlRows[rowNr][colNr];
}
//Internal helper function that applies an action on all member items
that._loopItems = function (fnc) {
for (var rowNr = 0; rowNr < this._controlRows.length; rowNr++)
for (var colNr = 0; colNr < this._controlRows[rowNr].length; colNr++)
if (this._controlRows[rowNr][colNr] != null)
fnc(this._controlRows[rowNr][colNr]);
}
that.applyOnControls = function(fnc) {
for (var rowNr = 0; rowNr < this._controlRows.length; rowNr++)
for (var colNr = 0; colNr < this._controlRows[rowNr].length; colNr++)
if (this._controlRows[rowNr][colNr] != null)
if ('applyOnControls' in this._controlRows[rowNr][colNr])
this._controlRows[rowNr][colNr].applyOnControls(fnc);
};
that.getID = function () {
if (that.myCustomID)
return that.myCustomID;
if (!this.getItem(0, 0)) DQX.reportError('Compound control has no components');
return this.getItem(0, 0).getID(id);
}
that.setContextID = function (id) {
this._loopItems(function (it) { it.setContextID(id); });
}
that.modifyEnabled = function (newstate) {
this._loopItems(function (it) { it.modifyEnabled(id); });
return that;
}
that.renderHtml = function () {
var st = '';
if (!this._autoFillX)
st += '<div style="display:inline-block">';
if (this._legend) {
st += '<fieldset class="{cls}">'.DQXformat({cls:that._legendClass});
st += '<legend>' + this._legend + '</legend>';
}
st += '<table style="padding-top:{pt}px;">'.DQXformat({ pt: this.sepV });
for (var rowNr = 0; rowNr < this._controlRows.length; rowNr++) {
st += '<tr>';
for (var colNr = 0; colNr < this._controlRows[rowNr].length; colNr++) {
st += '<td style="padding-right:{sepH}px;padding-bottom:{sepV}px;">'.DQXformat({ sepH: this.sepH, sepV: this.sepV });
var item = this.getItem(rowNr, colNr);
if (item != null)
st += item.renderHtml();
st += '</td>';
}
st += '</tr>';
}
st += '</table>';
if (this._legend) {
st += '</fieldset>';
}
if (!this._autoFillX)
st += '</div>';
return st;
}
that.postCreateHtml = function () {
this._loopItems(function (it) { it.postCreateHtml(); });
}
//Finds & returns a member control by id
that.findControl = function (id) {
this._loopItems(function (it) {
var rs = it.findControl(id);
if (rs != null) return rs;
});
return null;
}
return that;
}
//////////////////////////////////////////////////////////////////////////////////////////////
//A static label control
////////////////////////////////////////////////////////////////////////////////////////////
Controls.Label = function (icontent) {
var that = {};
that._content = DQX.interpolate(icontent);
that.getID = function () { return ''; }
that.setContextID = function (id) { }
that.modifyEnabled = function (newstate) { }
that.renderHtml = function () { return this._content; }
that.postCreateHtml = function () { }
that.applyOnControls = function(fnc) {
};
that.findControl = function (id) { return null; }
return that;
}
//////////////////////////////////////////////////////////////////////////////////////////////
//A
////////////////////////////////////////////////////////////////////////////////////////////
Controls.HorizontalSeparator = function (isize) {
var that = {};
that._size = isize;
that.getID = function () { return ''; }
that.setContextID = function (id) { }
that.modifyEnabled = function (newstate) { }
that.renderHtml = function () {
return '<div style="width:{sz}px;display:inline-block"></div>'.DQXformat({ sz: this._size });
}
that.postCreateHtml = function () { }
that.findControl = function (id) { return null; }
that.applyOnControls = function(fnc) {
};
return that;
}
//////////////////////////////////////////////////////////////////////////////////////////////
//A
////////////////////////////////////////////////////////////////////////////////////////////
Controls.VerticalSeparator = function (isize) {
var that = {};
that._size = isize;
that.getID = function () { return ''; }
that.setContextID = function (id) { }
that.modifyEnabled = function (newstate) { }
that.renderHtml = function () {
return '<div style="height:{sz}px;width:100%;clear:both"></div>'.DQXformat({ sz: this._size });
}
that.postCreateHtml = function () { }
that.findControl = function (id) { return null; }
that.applyOnControls = function(fnc) {
};
return that;
}
////////////////////////////////////////////////////////////////////////////////////////////
// Base class for all controls that implement an UI element (which are the 'real' widgets)
// Each leaf class derived from this should implement at least:
// _execRenderHtml : returns the html markup string
// _execPostCreateHtml : executes actions after the html was added to the DOM (e.g. add event handlers)
// getValue : returns the current value of the control
// modifyValue : changes the current value of the control
// The following messages are sent:
// CtrlValueChanged : when the content of the control was changed
// The control listens to the following messages:
// ModifyValue : to modify the value of the control
// ModifyEnabled : to change the enabled/disabled status of the control
////////////////////////////////////////////////////////////////////////////////////////////
Controls.Control = function (iid) {
var that = {};
that.myID = iid;
if (!iid)
that.myID = Controls._getNextControlID();
that.myContextID = '';
that._enabled = true;
that._controlExtensionList = ['']; //A list of all the ID's of member DOM elements of the control, registered as extensions to the base ID of the control
that._hasDefaultFocus = false;
that._eventids = [];
if (_debug_) {
if ($('#' + iid).length > 0)
DQX.reportError('Control creation error: element with ID ' + iid + ' is already present in the DOM tree');
}
//Defines this control to have the focus
that.setHasDefaultFocus = function () {
this._hasDefaultFocus = true;
return this;
}
//Used for store/recall serialisation of the control data
that.setClassID = function(id) {
that.classID = id;
return that;
}
that.getID = function () { return this.myID; }
//Internal
that.getFullID = function (extension) { return this.myContextID + this.myID + extension; }
that._reactModifyValue = function (scope, value) {
if (scope.contextid == this.myContextID) {
this.modifyValue(value);
}
}
if (Controls.autoCreateListeners) {
//We install a listener so that we can send an event to modify the value of the control
var eventid = DQX.getNextUniqueID();that._eventids.push(eventid);
Msg.listen(eventid, { type: 'CtrlModifyValue', id: that.myID }, $.proxy(that._reactModifyValue, that));
}
that._reactModifyEnabled = function (scope, value) {
if (scope.contextid == this.myContextID) {
this.modifyEnabled(value);
}
}
if (Controls.autoCreateListeners) {
//We install a listener so that we can send an event to modify the enabled state of the control
var eventid = DQX.getNextUniqueID();that._eventids.push(eventid);
Msg.listen(eventid, { type: 'CtrlModifyEnabled', id: that.myID }, $.proxy(that._reactModifyEnabled, that));
}
that.tearDown = function() {
$.each(that._eventids, function(idx,eventid) {
Msg.delListener(eventid);
});
}
that.setContextID = function (id) {
if ((this.myContextID != '') && (this.myContextID !== id))
DQX.reportError('Control context id is already set');
this.myContextID = id;
}
//Base implementation of renderHtml, calling _execRenderHtml in the leaf classes
that.renderHtml = function () {
Controls._addToControlPostCreateWaitList(this);
this._postCreateHtmlExecuted = false;
return this._execRenderHtml();
}
that.applyOnControls = function(fnc) {
fnc(that);
};
//Internal
that.getJQElement = function (extension) {
return $('#' + this.getFullID(extension));
}
//Modifies the enabled/disabled state of a control
that.modifyEnabled = function (newstate) {
this._enabled = newstate;
for (var i = 0; i < this._controlExtensionList.length; i++) {
if (this._enabled)
this.getJQElement(this._controlExtensionList[i]).removeAttr('disabled');
else
this.getJQElement(this._controlExtensionList[i]).attr("disabled", "disabled");
}
return that;
}
//Use this function to add a callback function that will be called when the value of the control was changed
//note: more than one handler can be added
that.addValueChangedListener = function (handler) {
Msg.listen('', { type: 'CtrlValueChanged', id: this.getID() }, handler);
}
//Use this function to provide a single handler function that will be called when the control changes
//note: only a single handler can be set in this way
that.setOnChanged = function (handler) {
this.onChanged = handler;
return this;
}
//Internal
that._notifyChanged = function () {
if (this.onChanged)
this.onChanged(this.myID, this);
Msg.broadcast({ type: 'CtrlValueChanged', id: this.myID, contextid: this.myContextID }, this);
}
//Trivial implementation of finding a control
that.findControl = function (id) {
if (id == this.myID) return this;
else return null;
}
//Determines if the control is currently rendered in the DOM tree
that.isRendered = function () {
return this.getJQElement('').length > 0;
}
//Sets the focus to this control
that.setFocus = function () {
if (!this.isRendered()) DQX.reportError('Control is not rendered');
document.getElementById(this.getFullID('')).focus();
}
//Internal: called after the html was rendered
that.postCreateHtml = function () {
if (!this._postCreateHtmlExecuted) {
if (_debug_)
if (!this.isRendered())
DQX.reportError('PostCreate called on unrendered control: ' + this.myID);
var ln0 = this.getJQElement().length;