forked from mediassarQlikBranch/SimpleFieldSelect
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSimpleFieldSelect.js
More file actions
1788 lines (1741 loc) · 73 KB
/
SimpleFieldSelect.js
File metadata and controls
1788 lines (1741 loc) · 73 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
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
define( ["qlik", "jquery", "css!./SimpleFieldStyle.css","text!./datepicker.css","./properties.def","text!./select2/select2.css","./jquery-ui.min","./select2/select2.min"],
function ( qlik, $, cssContent, cssDatepick, propertiesdef,select2css) {
'use strict';
/*if (!$("#sfscss").length>0){
$( '<style id="sfscss">' ).html( cssContent ).appendTo( "head" );
}*/
var debug = 0;
var initialParameters = {'qWidth':1, 'qHeight':10000};
//var sfsstatus = {};
var sfsdefaultselstatus = {};
var keepaliverTimer;
//If nothing selected but should be
function checkDefaultValueSelection($element,countselected,layout,self,app,sfssettings){
if(debug) console.log('checkin default selection, selected: '+countselected);
var selectDefaults = layout.props.allwaysOneSelectedDefault != '' || layout.props.selectAlsoThese != '';
if (selectDefaults && layout.props.selectDefaultsOnlyOnce && sfsdefaultselstatus[layout.qInfo.qId] == 1){
if(debug) console.log('Defaults already selected');
return;
}
if (countselected==0 && selectDefaults){
var defaulttoselect = $element.find( '.defaultelement' );
var otherdefaultelememnts = $element.find('.otherdefelem');
//check if element is found
/*if (defaulttoselect.length<1 && otherdefaultelememnts.length<1) {
if(debug) console.log('Default value was not found' +layout.qInfo.qId);
return;
}*/
var otherDefaultElementsSelectionStyle = true; //depends on if the main default value is selected
var valuesToSelect = [];
sfsdefaultselstatus[layout.qInfo.qId] = 1;
if (defaulttoselect.length>0){
if(debug) console.log('selecting default value');
if (layout.props.visualizationType=='dropdown'){
if (layout.props.dimensionIsVariable){
defaulttoselect.addClass('selected');
selectValueInQlik(self, defaulttoselect.html() ,layout,app,true,$element,sfssettings); //select here, no other defaults
} else {
selectValueInQlik(self, parseInt(defaulttoselect.val(),10) ,layout,app,true,$element,sfssettings); //select here, no other defaults
}
return false; //no need to continue
} else {
if (layout.props.dimensionIsVariable){
defaulttoselect.addClass('selected');
valuesToSelect.push( defaulttoselect.html() );
} else {
valuesToSelect.push( parseInt(defaulttoselect.attr( "dval" ),10) );
}
otherDefaultElementsSelectionStyle = false;
}
}
if (!layout.props.selectOnlyOne && otherdefaultelememnts.length>0){
if(debug) console.log('selecting other defaults, method: '+otherDefaultElementsSelectionStyle);
otherdefaultelememnts.each(function(elem){
valuesToSelect.push( parseInt($(this).attr( "dval" ),10) );
});
}
if (valuesToSelect.length>0){
if(debug){ console.log('select many'); console.log(valuesToSelect);}
selectValuesInQlik(self, valuesToSelect ,layout,app,false,$element,sfssettings);
}
}
}
//not in use yet
//var forcedelements = $element.find('.forcedelem');
//if forced, no need to check defaults
/*if (forcedelements.length>0){
checkForcedSelection(layout,self,app,forcedelements);
return false;
}*/
function checkForcedSelection(layout,self,app,forcedelements,sfssettings){
var valuesToSelect = [];
forcedelements.each(function(elem){
valuesToSelect.push( parseInt($(this).attr( "dval" ),10) );
});
if (valuesToSelect.length>0){
selectValuesInQlik(self, valuesToSelect ,layout,app,false,$element,sfssettings);
}
}
function selectValueInQlik(self,value,layout,app,selectvalueMethod,$element,sfssettings){ //selectvalueMethod true or false. This is not used for datepicker
//Variable
if (layout.props.dimensionIsVariable){
if(debug) console.log('set variable value to '+value);
if (! (sfssettings.variableOptionsForValuesArray && sfssettings.variableOptionsForValuesArray.length>0)){
if(debug) console.log('No values in variableOptionsForValuesArray');
return;
}
if(layout.props.variableName=='' || !layout.props.variableName || typeof layout.props.variableName =='object'){
if(debug) console.log('Variable name is empty');
return;
}
var valueTxt = '';
if ( layout.props.varMultiselectAllow){
var varvaluelist = [], varvalueSelectedIndexes = [];
$element.find('.selected').each(function(sel){
var ind = parseInt($(this).attr("dval"));
if (ind>=0){
varvaluelist.push( sfssettings.variableOptionsForValuesArray[ind] );
varvalueSelectedIndexes.push(ind);
}
});
if (varvaluelist){
valueTxt = varvaluelist.join(layout.props.varMultiselectSep);
if(debug) {console.log('multivalues to select to var '); console.log(varvaluelist);}
} else {
valueTxt = '';
}
} else {
valueTxt = sfssettings.variableOptionsForValuesArray[ value ];
//if value is not defined, forexample nothing is selected for variable.
var clearingSelection = 0;
if (typeof valueTxt == 'undefined' ){
valueTxt = '';
clearingSelection = 1;
}
if(layout.props.variableEmptyAlreadySelected && layout.variableValue==valueTxt){
valueTxt = '';
clearingSelection = 1;
}
}
if(debug) console.log(' means '+valueTxt+' to variable ' +layout.props.variableName);
//set variable
app.variable.setStringValue(layout.props.variableName, valueTxt);
//set key value too if defined
if (sfssettings.variableOptionsForKeysArray != [] && layout.props.variableNameForKey && sfssettings.variableOptionsForKeysArray[ value ]){
var keyTxt = '';
if ( layout.props.varMultiselectAllow){
var varkeylist = [];
varvalueSelectedIndexes.forEach(function(ind){
varkeylist.push(sfssettings.variableOptionsForKeysArray[ind]);
});
keyTxt = varkeylist.join(layout.props.varMultiselectSep);
} else {
keyTxt = sfssettings.variableOptionsForKeysArray[ value ];
}
if(debug) console.log(' key value '+keyTxt+' to variable ' +layout.props.variableNameForKey);
if (clearingSelection){ //if main value is being set to empty, set key also.
keyTxt = '';
}
app.variable.setStringValue(layout.props.variableNameForKey, keyTxt);
}
//set field
} else {
if(debug) console.log('set value to index '+value);
self.backendApi.selectValues( 0, [value], selectvalueMethod );
}
}
//select manyvalues at the same time
function selectValuesInQlik(self,values,layout,app,selectvalueMethod,$element,sfssettings){
if(debug) { console.log('set values to indexes '); console.log(values); }
if (layout.props.dimensionIsVariable){
var valueToSet = values[0];
selectValueInQlik(self,valueToSet,layout,app,selectvalueMethod,$element,sfssettings);
} else {
self.backendApi.selectValues( 0, values, selectvalueMethod );
}
}
//leonardo ui class
function createLUIclass(addLUIclasses,inputtype,visInputFieldType){
if(addLUIclasses){
if(inputtype=='dropdown' || inputtype=='select2'){
return ' lui-select';
} else if(inputtype=='checkbox'){
return ' lui-checkbox';
} else if(inputtype=='radio'){
return ' lui-radiobutton';
} else if(inputtype=='btn'){
return ' lui-button';
} else if(inputtype=='input'){
if(visInputFieldType=='range'){
return '';
} else if (visInputFieldType=='color'){
return ' lui-select';
} else {
return ' lui-input';
}
}
}
return '';
}
return {
initialProperties: {
qListObjectDef: {
qShowAlternatives: true,
//qFrequencyMode: "V",
qInitialDataFetch: [{
qWidth: initialParameters['qWidth'],
qHeight: initialParameters['qHeight']
}],
qSortByState: 0,
},
variableValue: {},
maxLimitvariableValue: {},
props: {
dimensionIsVariable: false
}
},
definition: propertiesdef,
support : {
snapshot: false,
export: function( layout ) {
return layout.props.exportenabled;
},
exportData : false
},
resize: function($element,layout){
if (debug) console.log('resize method');
var pr = layout.props;
if (pr.visualizationType=='actions'){
if (debug) console.log('resize paint');
this.paint( $element,layout);
}
//when exiting edit mode.
if(pr.enableGlobals && pr.hideGuiToolbar && $(".qv-mode-edit").length == 0){
$("#qv-toolbar-container").hide();
}
return false;
},
/*mounted: function( $element){
if (debug){ console.log('mounted'); }
globalAllSelectionsCleared = 0; //reset
},*/
controller: ['$scope', '$element', function ($scope, $element) {
if (debug) console.log('controller init');
var scpr = $scope.layout.props;
//globalAllSelectionsCleared = 0; //reset
if (scpr.enableGlobals && scpr.clearAllSelOnFirstLoad){
if (debug) console.log('clear all');
var app = qlik.currApp();
app.clearAll();
} else if (scpr.clearFieldSelOnFirstLoad){
if(debug) console.log('clear selections');
$scope.backendApi.selectValues( 0, [], false );
//var app = qlik.currApp(); //alternative
//app.field($scope.layout.qListObject.qDimensionInfo.qFallbackTitle).clear();
}
if (scpr.enableGlobals && scpr.clearAllSelOnLeave){
$scope.$on('$destroy', function (ev) {
if (debug) console.log('clear all');
var app = qlik.currApp();
app.clearAll();
});
} else if (scpr.clearFieldSelOnLeave){
$scope.$on('$destroy', function (ev) {
if (debug) console.log('clear selections');
$scope.backendApi.selectValues( 0, [], false );
});
}
$scope.$on('$destroy', function (ev) {
var contextmenuID = 'sfsrmenu'+$scope.layout.qInfo.qId;
$("."+contextmenuID).remove(); //removes if exists
});
}],
paint: function ( $element,layout ) {
if (debug){ console.log('start painting '+layout.qInfo.qId); console.log($element);}
var self = this, html = "";
var app = qlik.currApp();
var pr = layout.props;
var visType = pr.visualizationType;
var sfssettings = {};
//exit if needed, no dimension, not txtonly, variable empty
if (pr.dimensionIsVariable){
if((!pr.variableName || pr.variableName=='')){
$element.html('<h3>Set / check variable name !</h3>');
return qlik.Promise.resolve();
}
} else if ((pr.rightclikcmenu_getselectionurl || pr.rightclikcmenu_getselurltoclipboard) && pr.rightclikcmenu_getselectionurlAsButton){
pr.rightclikcmenu_getselectionurlAsButtonTxt = pr.rightclikcmenu_getselectionurlAsButtonTxt ? pr.rightclikcmenu_getselectionurlAsButtonTxt : 'Get current selections as an URL';
$element.html('<button type="button" class="sfs_getselectionurl lui-button">'+pr.rightclikcmenu_getselectionurlAsButtonTxt+'</button>');
$(".sfs_getselectionurl").click(function(){
getSelectedUrl('dialog');
});
return qlik.Promise.resolve();
//actions
} else if (pr.visualizationType=='actions') {
} else {
if (layout.qListObject.qDataPages.length==0 && visType !='txtonly' ) {
$element.html('<h3>Select one dimension or variable first!</h3> Or use textarea only - visualization option<br /> Datepicker can only control a variable. To use datepicker, select a varibale and enable "Variable is a date selector"-option.');
return qlik.Promise.resolve();
}
}
//if dimension is there, data exists
var matrixdata = [];
if (layout.qListObject.qDataPages[0] && layout.qListObject.qDataPages[0].qMatrix.length > 0){
var rowcount = layout.qListObject.qDataPages[0].qMatrix.length;
var allrowscount = self.backendApi.getRowCount();
if(allrowscount > rowcount){ //if more rows need to be fetched
var lastrow = 0;
this.backendApi.eachDataRow( function ( rownum, row ) {
lastrow = rownum;
});
if (debug) console.log('fetching more rows ' + lastrow);
if(allrowscount > lastrow +1){
var requestPage = [{
qTop: lastrow + 1, qLeft: 0,
qWidth: initialParameters['qWidth'],
qHeight: Math.min( initialParameters['qHeight'], allrowscount - lastrow )
}];
this.backendApi.getData( requestPage ).then( function ( dataPages ) {
self.paint( $element,layout );
} );
$element.html('wait for data');
return qlik.Promise.resolve();
} else {
//finally read all
this.backendApi.eachDataRow( function ( rownum, row ) {
matrixdata[rownum] = row;
});
}
} else {
//use matrix data if paging is nor needed.
matrixdata = layout.qListObject.qDataPages[0].qMatrix;
}
}
if (debug) console.log(layout);
var objectCSSid = 'sf'+layout.qInfo.qId;
var extraStyle = ''; //object spesific
//change header size
var headerelement = $element.parent().parent().prev();
if (pr && pr.showHeader){
headerelement.show();
if (pr.headerSize && pr.headerSize != '-'){
headerelement.css('height',pr.headerSize+'px');
}
if (pr.headerBpadding && pr.headerBpadding != '-'){
headerelement.css('padding-bottom',pr.headerBpadding+'px');
}
if (pr.headerTpadding && pr.headerTpadding != '-'){
headerelement.find('h1').css('padding-top',pr.headerTpadding+'px');
}
} else {
headerelement.hide();
}
//borders and bg
var articleInnerElement = headerelement.parent();
var articleElement = articleInnerElement.parent();
if (pr.transparentBackground){
articleElement.css('background-color','transparent');
articleInnerElement.css('background-color','transparent');
} else if (pr.specialBackgroundColor){
articleElement.css('background-color',pr.specialBackgroundColor);
articleInnerElement.css('background-color',pr.specialBackgroundColor);
} else {
articleElement.css('background-color','');
articleInnerElement.css('background-color','');
}
if (pr.noBorders){
articleElement.css('border-width','0');
articleElement.parent().parent().css('border-width','0');
} else {
if (pr.ownBordercolor2 != ''){
articleElement.css('border-color',pr.ownBordercolor2);
}
if (pr.ownBordercolor != ''){
articleElement.parent().parent().css('border-color',pr.ownBordercolor);
}
}
if (pr.removeYscroll){
articleInnerElement.find('.qv-object-content-container').css('overflow-y','hidden');
}
if (pr.showXscroll){
articleInnerElement.find('.qv-object-content-container').css('overflow-x','auto');
}
if (pr.whitespacenowrap){
extraStyle += ' .'+objectCSSid + ', .'+objectCSSid + ' .sfe {white-space:nowrap; display:inline-block;}';
if (visType=='luiradio'){
extraStyle += ' .'+objectCSSid + ' .lui-radiobutton {padding-right:5px;}'
}
}
/*if (layout.props.specialFontcolor){
articleElement.css('color',layout.props.specialFontcolor);
} else {
articleElement.css('color','');
}*/
//left padding in one qlik theme
if(pr.leftpadding && pr.leftpadding != '-'){
articleInnerElement.css('padding-left',pr.leftpadding+'px');
}
if(pr.rightpadding && pr.rightpadding != '-'){
articleInnerElement.css('padding-right',pr.rightpadding+'px');
}
if(pr.bottompadding && pr.bottompadding != '-'){
articleInnerElement.css('padding-bottom',pr.bottompadding+'px');
}
if (extraStyle){
html += '<style>'+extraStyle+'</style>';
}
//padding
var paddingDivAdded = 1;
var containerDivHeight_reduce = 0;
if (pr.helptext){
containerDivHeight_reduce += 19; //approximantion px amount of help text size
}
//extra label
if(pr.inlinelabeltext){
html += '<label class=inlinelabel><div class="inlinelabeldiv';
if (pr.inlinelabelSetinline){
html += ' inlinelabeldivInline';
containerDivHeight_reduce += 2;
} else {
containerDivHeight_reduce += 22;
}
html += '"';
if (pr.inlinelabelcss){
html = ' style="'+checkUserCSSstyle2(pr.inlinelabelcss,1)+'"'
}
html += '>'+pr.inlinelabeltext+'</div> ';
html += '</label>';
}
if(pr.enablesearch){
if((visType=='hlist' || visType=='vlist' || visType=='checkbox' ||visType=='radio' || visType=='luiswitch' || visType=='luicheckbox' || visType=='luiradio')){
var searchId = 'se'+layout.qInfo.qId;
html += '<div class="sfssearchdiv">';
html += '<div class="lui-search">';
html += '<span class="lui-icon lui-search__search-icon"></span>';
html += '<input class="lui-search__input sfssearchinput" id="'+searchId+'" maxlength="255" spellcheck="false" type="text" placeholder="Search"/>';
html += '<span id="cl'+searchId+'" class="lui-icon lui-search__clear-icon sfssearchinput_clear" title="clear search"></span>';
html += '</div></div>';
html += '<div class="sfssearchIcon"><span class="lui-icon lui-icon--search"></span></div>';
}
}
//content heigth
if(pr.contentpadding && pr.contentpadding != '-'){
containerDivHeight_reduce += (parseInt(pr.contentpadding)*2); //add padding to height reduce x 2
html += '<div style="padding:'+pr.contentpadding +'px; height:calc(100% - '+containerDivHeight_reduce+'px); min-height:50%;">';
} else {
html += '<div style="height:calc(100% - '+containerDivHeight_reduce+'px); min-height:50%;">';
}
//change for mobile
if ($('.smallDevice').length >0){ //$(window).width()<600
var parent = $element.closest('.qv-gridcell');
//console.log(parent.html());
if(pr.mobileRemoveZoom){
parent.find('.transparent-overlay').remove(); //remove mobile zoom haveto
}
//set height, default is too high
if(pr.mobileCustomHeightCSS && pr.mobileCustomHeightCSS != ''){
parent.css('height',pr.mobileCustomHeightCSS);
} else {
parent.css('height','65px');
}
}
//hiding, global or local..
if (pr.hideFieldsFromSelectionBar || pr.hideFromSelectionsBar){
//add hide area if needed
if ($(".hideselstyles").length>0){
} else {
$('.qv-selections-pager').append('<div style="display:none;" class=hideselstyles></div>');
}
//hide global
if (pr.hideFieldsFromSelectionBar && pr.hideFieldsFromSelectionBar != ''){
var splittedfields = pr.hideFieldsFromSelectionBar.split(";");
if (debug){ console.log('hiding fields:'); console.log(splittedfields); }
splittedfields.forEach(function(fieldToHide,i){
var fieldToHideSelector = fieldToHide.replace(/ /g,'_').replace(/=/g,'');
if (fieldToHideSelector){
if ($('#hid'+fieldToHideSelector).length>0){
//already hidden
} else {
$('.hideselstyles').append('<style id="hid'+fieldToHideSelector+'">.qv-selections-pager li[data-csid="'+ fieldToHide +'"] {display:none;}</style>');
}
}
});
}
//hide current
if (pr.hideFromSelectionsBar){
var fieldToHide = pr.hideFromSelectionRealField;
if (fieldToHide == '' || !fieldToHide){
fieldToHide = layout.qListObject.qDimensionInfo.qGroupFieldDefs[0]; //try this one if not defined.
if (fieldToHide.slice(0,1)==='='){ //if first letter =
fieldToHide = fieldToHide.slice(1);
}
fieldToHide = fieldToHide.replace(/[\[\]']+/g,''); //reomve []
}
var fieldToHideSelector = fieldToHide.replace(/ /g,'_').replace(/=/g,'');
if (fieldToHideSelector){
if ($('#hid'+fieldToHideSelector).length>0){
//already hidden
} else {
$('.hideselstyles').append('<style id="hid'+fieldToHideSelector+'">.qv-selections-pager li[data-csid="'+ fieldToHide +'"] {display:none;}</style>');
}
}
}
}
//Globals CSS mod
if (pr.enableGlobals){
if(debug) console.log('enabled globals ' + layout.qInfo.qId);
var sfsglobalCSSid = "SFSglobalCSS"+layout.qInfo.qId
if ($("#"+sfsglobalCSSid).length>0){
} else {
articleElement.append($( '<div id="'+sfsglobalCSSid+'" style="display:none;" class="sfsglobalcss"></div>' ));
}
if( $(".sfsglobalcss").length>1 ){
console.log('SimpleFieldSelect: This sheet has two or more global modifications enabled. Remove another one.');
}
var csstxt = '';
if (pr.global_bgcolor){
csstxt += ' .qv-client #qv-stage-container .qvt-sheet, .qv-client.qv-card #qv-stage-container .qvt-sheet, .qv-client.qv-card #qv-stage-container .qvt-sheet:not(.qv-custom-size), .sheet-list #grid, .qvt-sheet.qv-custom-size #grid { background-color:'+pr.global_bgcolor+';}';
}
/*if (pr.global_bgcolor2){
csstxt += ' .qvt-sheet.qv-custom-size #grid { background-color:'+pr.global_bgcolor2+';}';
}*/
if (pr.global_bgcss){
csstxt += ' .qv-client #qv-stage-container .qvt-sheet, .qv-client.qv-card #qv-stage-container .qvt-sheet {'+pr.global_bgcss+'}';
}
if (pr.global_borderwidth && pr.global_borderwidth != '-'){
csstxt += ' .sheet-grid .qv-gridcell:not(.qv-gridcell-empty),.qv-mode-edit .qv-gridcell:not(.qv-gridcell-empty), .sheet-grid :not(.library-dragging)#grid .qv-gridcell.active { border-width:'+pr.global_borderwidth+'px;}';
}
if (pr.global_bordercolor){ //tbfixed, border on more than one level
csstxt += ' .sheet-grid .qv-gridcell:not(.qv-gridcell-empty) { border-color:'+pr.global_bordercolor+';}';
}
if (typeof pr.global_bordercolor2 === 'undefined'){ //use nro 1
csstxt += ' .sheet-grid .qv-gridcell:not(.qv-gridcell-empty) { border-color:'+pr.global_bordercolor+';}';
} else if (pr.global_bordercolor2){ //tbfixed, border on more than one level
csstxt += ' .sheet-grid .qv-gridcell:not(.qv-gridcell-empty) .qv-object { border-color:'+pr.global_bordercolor2+'!important;}';
}
if(pr.removeHeaderFromTextImageObjects){
csstxt += " .qv-object-text-image header {display:none!important;}";
}
if(pr.removeHeaderFromAllObjects){
csstxt += " .qv-object header {display:none!important;}";
}
if(pr.headerTpadding_global && pr.headerTpadding_global != '-'){
csstxt += " .qv-object header h1 {padding-top:"+pr.headerTpadding_global+"px!important;}";
}
if(pr.headerBpadding_global && pr.headerBpadding_global != '-'){
csstxt += " .qv-object header {padding-bottom:"+pr.headerBpadding_global+"px!important;}";
}
if(pr.headerfontcolor_global && pr.headerfontcolor_global != ''){
csstxt += " .qv-object header h1 {color:"+pr.headerfontcolor_global+"!important;}";
}
if(pr.headerbgcolor_global && pr.headerbgcolor_global != ''){
csstxt += " .qv-object header {background-color:"+pr.headerbgcolor_global+"!important;}";
}
if(pr.leftpadding_global && pr.leftpadding_global != '-'){
csstxt += ' .qv-object .qv-inner-object {padding-left:'+pr.leftpadding_global+'px!important;}';
}
if(pr.rightpadding_global && pr.rightpadding_global != '-'){
csstxt += ' .qv-object .qv-inner-object {padding-right:'+pr.rightpadding_global+'px!important;}';
}
if(pr.removeHeaderIfNoText){
csstxt += ' .qv-object header.thin {display:none!important;}';
}
if(pr.fontfamily_global && pr.fontfamily_global != ''){
csstxt += ' .qv-object * {font-family:"'+pr.fontfamily_global+'";}';
}
if(pr.global_elementbgcolor && pr.global_elementbgcolor != ''){
csstxt += ' .qv-client #qv-stage-container #grid .qv-object-wrapper .qv-inner-object, .qv-client.qv-card #qv-stage-container #grid .qv-object-wrapper .qv-inner-object {background-color:'+pr.global_elementbgcolor+'!important;}'; //ow element style
}
if(pr.global_fontcolor && pr.global_fontcolor != ''){
csstxt += ' .qv-client #qv-stage-container .qvt-sheet {color:'+pr.global_fontcolor+';}';
csstxt += ' .qvt-visualization-title, .qv-object-SimpleFieldSelect .inlinelabeldiv, .qv-object .qv-media-tool-html {color:'+pr.global_fontcolor+';}';
}
if(pr.hidepivotTableSelectors){
csstxt += " .qv-object .left-meta-headers,.qv-object .top-meta {display:none!important;}";
}
if(pr.hideInsightsButton){
csstxt += " .qv-insight-toggle-button {display:none!important;}";
}
if(pr.hideSelectionsTool){
csstxt += ' .qv-subtoolbar-button[tid="currentSelections.toggleGlobalSelections"] {display:none!important;}';
}
if(pr.hideSmartSearchButton){
csstxt += ' .qv-subtoolbar-button[tid="toggleGlobalSearchButton"] {display:none!important;}';
}
if(pr.hideGuiToolbar && $(".qv-mode-edit").length == 0){
if($("#qv-toolbar-container").length>0) {
csstxt += ' #qv-toolbar-container {display:none!important;}';//pre 2019 feb
} else {
csstxt += ' .qs-toolbar-container {display:none!important;}';
}
csstxt += '.qv-panel {height:100%;}';
}
if (pr.toolbarTxt && !pr.hideGuiToolbar){
if ($("#sfstoolbartxt").length==0){
if ($(".qui-buttonset-left").length>0){ //pre 2019 feb
$(".qui-buttonset-left").append('<div id="sfstoolbartxt"></div>');
} else {
$(".qs-toolbar__left").append('<div id="sfstoolbartxt"></div>');
}
}
$("#sfstoolbartxt").html(pr.toolbarTxt); //'+pr.toolbarTxt+'
}
if(pr.hideToolbarCenter && !pr.hideGuiToolbar){
csstxt += ' .qs-toolbar__center {display:none!important;}';
}
$("#"+sfsglobalCSSid).html('<style>' + csstxt + '</style>');
if (pr.hideSheetTitle){
$(".sheet-title-container").hide();
} else {
if(pr.removeSheetTitlePadding){
$(".sheet-title-container").css('padding','0');
}
if(pr.sheetTitleheight && pr.sheetTitleheight != -1){
$(".sheet-title-container").css('height',pr.sheetTitleheight +'px');
$("#sheet-title").css('height',pr.sheetTitleheight +'px');
}
if(pr.sheetTitleFontSize && pr.sheetTitleFontSize != -1){
$("#sheet-title").css('font-size',pr.sheetTitleFontSize +'px');
}
if(pr.sheetTitleExtraText && pr.sheetTitleExtraText != ''){
if ($("#sfsSheetTitleTxt").length==0){
$("#sheet-title").append('<div id="sfsSheetTitleTxt" style="margin-left:20px;"></div>');
}
$("#sfsSheetTitleTxt").html(pr.sheetTitleExtraText);
}
}
if (pr.hideSelectionBar){
$(".qvt-selections").hide();
} else {
if(pr.selBarExtraText && pr.selBarExtraText != ''){
if ($("#sfsSelBartxt").length==0){
$(".qv-selections-pager .buttons-end").append('<div id="sfsSelBartxt" class="item qv-object-SimpleFieldSelect qv-subtoolbar-button borderbox bright"></div>');
}
$("#sfsSelBartxt").html(pr.selBarExtraText).prop('title',pr.selBarExtraText).prop('style',pr.selBarExtraTextcss);
if (pr.selBarExtraTextQlikStyle){
$("#sfsSelBartxt").addClass('selbarqlikstyle');
} else {
$("#sfsSelBartxt").removeClass('selbarqlikstyle');
}
}
}
if(pr.toolbarheight && !pr.hideGuiToolbar && pr.toolbarheight != -1){
if($(".qui-toolbar").length>0){
$(".qui-toolbar").css('height',pr.toolbarheight +'px'); //pre 2019 feb
} else {
$(".qs-toolbar").css('height',pr.toolbarheight +'px');
}
}
if(pr.keepaliver && pr.keepaliver>0){
setKeepaliver(self,pr.keepaliver);
}
}
//get variable value(s)
var varvalue = '', varvalues = {};
if (pr.dimensionIsVariable){
varvalue = layout.variableValue;
if (debug){ console.log('varvalue from '+pr.variableName+' is '); console.log(varvalue); }
if (pr.varMultiselectAllow){// && typeof varvalue !=='undefined' && !pr.variableIsDate && !visType=='input' && typeof pr.varMultiselectSep !== 'undefined'){
var splittedvar = varvalue.split(pr.varMultiselectSep);
splittedvar.forEach(function(val){
varvalues[val] = 1; //collect selected
});
}
}
var fontStyleTxt = '';
if (pr.customFontCSS && pr.customFontCSS != ''){
fontStyleTxt += ' font:'+checkUserCSSstyle2(pr.customFontCSS, 1);
}
if (pr.customFontFamilyCSS && pr.customFontFamilyCSS != ''){
fontStyleTxt += ' font-family:'+checkUserCSSstyle2(pr.customFontFamilyCSS);
}
var elementStyleCSS = '';
if (pr.customStyleCSS && pr.customStyleCSS != ''){
elementStyleCSS = ' '+checkUserCSSstyle2(pr.customStyleCSS);
}
var containerStyles = '';
if (pr.useMaxHeight){
if (visType=='input'){
containerStyles += ' height:calc(100% - 10px);';
} else {
containerStyles += ' height:100%;';
}
//headerelement.parent().css('padding-bottom','0px');
}
if (pr.textHAlign && pr.textHAlign != '-'){
containerStyles += ' text-align:'+pr.textHAlign+';';
}
if (pr.textVAlign && pr.textVAlign != '-'){
elementStyleCSS += ' vertical-align:'+pr.textVAlign+';';
}
var elementExtraAttribute = '';
if (pr.customElementAttribute && pr.customElementAttribute != ''){
elementExtraAttribute = ' '+pr.customElementAttribute+' ';
}
var elementExtraClass = '';
if (pr.customElementClass && pr.customElementClass != ''){
elementExtraClass = ' '+pr.customElementClass+' ';
}
var fontsizechanges = '';
if (pr.responsivefontsize){
fontsizechanges = ' font-size:'+pr.responsivefontvalue + pr.responsivefonttype+';';
} else
if (pr.fontsizeChange && pr.fontsizeChange != '' && pr.fontsizeChange != '100'){
fontsizechanges = ' font-size:'+pr.fontsizeChange+'%;';
}
//border color style
var bordercolorstyle = '';
if (pr.color_border && pr.color_border != ''){
bordercolorstyle = ' border-color:'+pr.color_border+';';
}
var elementpadding = '';
if (pr.elementpadding && pr.elementpadding != '' && pr.elementpadding != '-'){
elementpadding = ' padding:'+pr.elementpadding+'px;';
}
var elementmargin = '';
if (pr.elementmargin && pr.elementmargin != '' && pr.elementmargin != '-'){
elementmargin = ' margin:'+pr.elementmargin+'px;';
}
var titletext = '';
if (pr.hovertitletext && pr.hovertitletext != ''){
titletext += pr.hovertitletext.replace(/\"/g,'"');
}
//if date select to variable
if (pr.variableIsDate && pr.dimensionIsVariable){
if ($("#sfsdatepicker").length>0){
//ok
} else {
$( "<style id=sfsdatepicker>" ).html( cssDatepick ).appendTo( "head" ); //add css.
}
if (pr.variableName){
if (debug){ console.log('varvalue ' + pr.variableName); console.log(app.variable.getContent(pr.variableName)); }
var inattributes = 'type=text';
if(pr.visInputNumberMin != ''){
inattributes += ' min="'+pr.visInputNumberMin+'"';
}
if(pr.visInputNumberMax != ''){
inattributes += ' max="'+pr.visInputNumberMax+'"';
}
if (pr.preElemHtml){
html += pr.preElemHtml;
}
html += '<div class="checkboxgroup '+objectCSSid+'">';
html += '<input '+inattributes+' title="';
if (titletext != ''){
html += titletext; //escape quotas!!
} else {
html += 'Click to select date';
}
html += '" class="sfe pickdate'+elementExtraClass+createLUIclass(pr.addLUIclasses,'input','text')+'" ';
if (pr.visInputPlaceholdertxt && pr.visInputPlaceholdertxt != ''){
html += ' placeholder="'+pr.visInputPlaceholdertxt.replace(/\"/g,'"')+'"'; //escape quotas!!
}
if (pr.color_stateO_bg && pr.color_stateO_bg != ''){
elementStyleCSS += 'background-color:'+pr.color_stateO_bg+';';
}
if (pr.color_stateO_fo && pr.color_stateO_fo != ''){
elementStyleCSS += ' color:'+pr.color_stateO_fo+';';
}
//no multivar support here
html += 'value="'+varvalue+'" style="width:6em; max-width:80%;'+fontsizechanges+fontStyleTxt+elementStyleCSS+bordercolorstyle+elementpadding+elementmargin+'"' +elementExtraAttribute+ '/>';
if (pr.postElemHtml){
html += pr.postElemHtml;
}
if (pr.helptext){
html += createhelptextdiv(pr);
}
html += '</div>';
if(paddingDivAdded) html += '</div>';
$element.html( html );
//set javascript
var datepickElement = $element.find( '.pickdate' );
datepickElement.datepicker({
dateFormat: pr.dateformat,
changeMonth: true,
changeYear: true,
showOn: "both",
maxDate: pr.visInputNumberMax,
minDate: pr.visInputNumberMin,
firstDay:1,
constrainInput: true
});
//dates limited? will be depricated
if (pr.maxLimitvariable && pr.maxLimitvariable && pr.maxLimitvariable != '-'){
if (debug){ console.log('Limiting days to '); console.log(pr.maxLimitvariable); }
var parsedDate = $.datepicker.parseDate(pr.dateformat, pr.maxLimitvariable);
datepickElement.datepicker( "option", "maxDate", parsedDate );
}
$element.find( '.pickdate' ).on( 'change', function () {
var newval = $(this).val();
if(debug) console.log('NEW '+newval + ' to '+pr.variableName);
app.variable.setStringValue(pr.variableName, newval);
});
}
//html input for variable
} else if (visType=='input' && !pr.variableIsDate) {
var datalist = '', datalistID='';
if (pr.color_stateO_bg && pr.color_stateO_bg != ''){
elementStyleCSS += 'background-color:'+pr.color_stateO_bg+';';
}
if (pr.color_stateO_fo && pr.color_stateO_fo != ''){
elementStyleCSS += ' color:'+pr.color_stateO_fo+';';
}
if (!pr.dimensionIsVariable){
html += 'HTML input option is available only for variables';
} else {
//if stepped, datalist values
var splitted = pr.variableOptionsForValues.split(";");
var splittedkeys = pr.variableOptionsForKeys.split(";");
if(splitted && pr.variableOptionsForValues != ''){
datalistID = 'dl'+layout.qInfo.qId;
datalist = ' <datalist id="'+datalistID+'">';
splitted.forEach(function(opt,i){
var label = opt;
if(typeof splittedkeys[i] !== 'undefined'){
label = splittedkeys[i];
}
datalist += '<option label="'+label+'">'+opt+'</option>';
});
datalist += '</datalist> ';
}
var inattributes = 'type='+pr.visInputFieldType;
if(pr.visInputFieldType!='text' && pr.visInputFieldType!='password'){
if(pr.visInputNumberMin != ''){
inattributes += ' min="'+pr.visInputNumberMin+'"';
}
if(pr.visInputNumberMax != ''){
inattributes += ' max="'+pr.visInputNumberMax+'"';
}
if(pr.visInputNumberStep != ''){
inattributes += ' step="'+pr.visInputNumberStep+'"';
}
}
//build html
html += '<div class="checkboxgroup '+objectCSSid+'">';
if (pr.preElemHtml){
html += pr.preElemHtml;
}
html += '<input '+inattributes+' title="';
//no multivar support here
if(pr.visInputFieldType=='range') html += varvalue+' ';
if (titletext != ''){
html += titletext; //escape quotas!!
}
html += '"';
if (datalist) html += ' list="'+datalistID+'"';
if (pr.visInputPlaceholdertxt && pr.visInputPlaceholdertxt != ''){
html += ' placeholder="'+pr.visInputPlaceholdertxt.replace(/\"/g,'"')+'"'; //escape quotas!!
}
html += ' class="sfe htmlin '+createLUIclass(pr.addLUIclasses,visType,pr.visInputFieldType)+elementExtraClass+'" value="'+varvalue+'" style="'+fontsizechanges+fontStyleTxt+elementStyleCSS+bordercolorstyle+elementpadding+elementmargin+containerStyles+'"' +elementExtraAttribute+ '/>';
if (pr.postElemHtml){
html += pr.postElemHtml;
}
if (datalist) html += datalist;
if(pr.visInputFieldType=='range'){
if(pr.visInputRangeSliderValuefield){
html += '<output class="rangval" id="rv_'+layout.qInfo.qId+'">'+varvalue+'</output>';
}
//tooltip
html += '<div class="rangvaltooltip" style="display:none;" id="tip_'+layout.qInfo.qId+'">'+varvalue+'</div>';
}
if (pr.helptext){
html += createhelptextdiv(pr);
}
html += '</div>';
if(paddingDivAdded) html += '</div>';
}
$element.html( html );
$element.find( '.htmlin' ).on( 'change select', function () { //select for datalist
var newval = $(this).val();
if (newval != layout.variableValue){
if(debug) console.log('NEW '+newval + ' to '+pr.variableName);
app.variable.setStringValue(pr.variableName, newval);
}
});
//range actions
if(pr.visInputFieldType=='range'){
var targetelement = $element.find( '.htmlin' );
var tooltip = $("#tip_"+layout.qInfo.qId);
targetelement[0].oninput = function(e){ //jquery doesn't support oninput
$("#rv_"+layout.qInfo.qId).html(this.value);
tooltip.html(this.value);
};
targetelement.mousedown(function(e){
tooltip.css({'position':'fixed','top':(e.pageY-35),'left':(e.pageX+5)}).show();
targetelement.on('mousemove',function(e){
tooltip.css({'top':(e.pageY-30),'left':(e.pageX+5)})
});
});
targetelement.mouseup(function(){
targetelement.off('mousemove');
tooltip.fadeOut('slow');
});
/* for jquery slider....
var handle = $( "#custom-handle" );
$element.find('#slider').slider({
slide: function( event, ui ) {
alert( ui.value );
handle.text( ui.value );
}
});*/
}
//only txt
} else if(visType=='txtonly'){
if (pr.preElemHtml){
html += pr.preElemHtml;
}
html += '<div class="'+objectCSSid+' sfe txtonly '+elementExtraClass+'"';
if (titletext){
html += ' title="'+titletext+'"'; //escape quotas!!
}
html += ' style="'+fontsizechanges+fontStyleTxt+elementStyleCSS+bordercolorstyle+elementpadding+elementmargin+containerStyles+'"' +elementExtraAttribute+'>';
if (pr.textareaonlytext) html += pr.textareaonlytext;
if (pr.textareaonlytext2) html += pr.textareaonlytext2;
if (pr.helptext){
html += createhelptextdiv(pr);
}
html += '</div>';
if (pr.postElemHtml){
html += pr.postElemHtml;
}
$element.html( html );
//not date or html input:
} else {
var stylechanges = ' style="'+fontsizechanges+fontStyleTxt+containerStyles+'"';
if(visType=='luiswitch' || visType=='luicheckbox' || visType=='luiradio'){
html += '<div class="sfs_lui '+objectCSSid+'"'+stylechanges;
} else {
html += '<div class="checkboxgroup '+objectCSSid+'"';
}
if (titletext){
html += ' title="'+titletext+'"'; //escape quotas!!
}
html += '>';
var countselected = 0;
var multiselect = ''; //dropdown multi
if (pr.selectmultiselect && !(pr.dimensionIsVariable && !pr.varMultiselectAllow)) {
multiselect = ' multiple="multiple"';
elementExtraClass = ' ddmulti '+elementExtraClass;
}
var mainobjectstyle = '';
if (pr.mainobjectwidth){
mainobjectstyle += ' width:'+pr.mainobjectwidth;
}
if (visType=='vlist'){
html += '<ul'+stylechanges+'>';
}else if (visType=='hlist'){
var roundcornerClass=' rcorners';
if (pr.hlistRoundedcorners===false){
roundcornerClass='';
}
var rmarginclass = ' rmargin1';
if (pr.hlistMarginBetween >= 0){ //its defined
rmarginclass = ' rmargin'+pr.hlistMarginBetween;
}
var displayastableClass = '';
if (pr.hlistShowAsTable){
displayastableClass = ' ulastable'
}
html += '<ul class="horizontal'+roundcornerClass+rmarginclass+displayastableClass+'" '+stylechanges+'>';
} else if (visType=='checkbox' || visType=='radio'){
html += '<div '+stylechanges+'>';
} else if (visType=='dropdown'){
if (pr.preElemHtml){
html += pr.preElemHtml;
}
html += '<select class="dropdownsel'+elementExtraClass+createLUIclass(pr.addLUIclasses,visType,'')+'" style="'+fontsizechanges+fontStyleTxt+elementStyleCSS+bordercolorstyle+elementpadding+elementmargin+containerStyles+mainobjectstyle+'"' +elementExtraAttribute+multiselect+ '>';
} else if (visType=='select2'){
if (pr.preElemHtml){
html += pr.preElemHtml;
}
html += '<select class="dropdownsel'+elementExtraClass+createLUIclass(pr.addLUIclasses,visType,'')+'" style="'+fontsizechanges+fontStyleTxt+elementStyleCSS+bordercolorstyle+containerStyles+mainobjectstyle+'"' +elementExtraAttribute+multiselect+ '>'; //no elementpadding/margin
} else if (visType=='btn'){
html += '<div '+stylechanges+'>';
} else if (visType=='luiswitch' || visType=='luicheckbox' || visType=='luiradio'){
} else {
html += 'Select visualization type';
}
//print elements
var optionsforselect = [];
if (pr.dimensionIsVariable){
//generate variable options from field
if (debug) console.log('variable value '+varvalue);
if (debug && pr.varMultiselectAllow) {console.log('paint multivalues'); console.log(varvalues); }
if (!pr.variableOptionsForValues){
html += 'Set variable options or enable date selector or switch to HTML standard input visualization';
}
if (pr.variableName =='' || !pr.variableName){
html += ' <br /> Invalid variable name.';
}
//create lists for variable values
var splitted = pr.variableOptionsForValues.split(";");
var varindex = 0; //index is used to access variable
sfssettings.variableOptionsForValuesArray = [];
sfssettings.variableOptionsForKeysArray = [];
splitted.forEach(function(opt){
var qState = 'O';
//if values match with current, mark selected
if (pr.varMultiselectAllow){