-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathAltStateListbox.js
125 lines (125 loc) · 3.14 KB
/
AltStateListbox.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
define( ["jquery", "text!./style.css", "qlik"], function ( $, cssContent, qlik ) {
'use strict';
$( "<style>" ).html( cssContent ).appendTo( "head" );
return {
initialProperties: {
qListObjectDef: {
qShowAlternatives: true,
qFrequencyMode: "V",
qInitialDataFetch: [{
qWidth: 2,
qHeight: 50
}]
}
},
definition: {
type: "items",
component: "accordion",
items: {
dimension: {
type: "items",
label: "Dimensions",
ref: "qListObjectDef",
min: 1,
max: 1,
items: {
label: {
type: "string",
ref: "qListObjectDef.qDef.qFieldLabels.0",
label: "Label",
show: true
},
libraryId: {
type: "string",
component: "library-item",
libraryItemType: "dimension",
ref: "qListObjectDef.qLibraryId",
label: "Dimension",
show: function ( data ) {
return data.qListObjectDef && data.qListObjectDef.qLibraryId;
}
},
field: {
type: "string",
expression: "always",
expressionType: "dimension",
ref: "qListObjectDef.qDef.qFieldDefs.0",
label: "Field",
show: function ( data ) {
return data.qListObjectDef && !data.qListObjectDef.qLibraryId;
}
},
frequency: {
type: "string",
component: "dropdown",
label: "Frequency mode",
ref: "qListObjectDef.qFrequencyMode",
options: [{
value: "N",
label: "No frequency"
}, {
value: "V",
label: "Absolute value"
}, {
value: "P",
label: "Percent"
}, {
value: "R",
label: "Relative"
}],
defaultValue: "V"
}
}
},
settings: {
uses: "settings"
},
customProperties : {
component: "expandable-items",
label: "Custom Properties",
type : "items",
items : {
state : {
ref : "qListObjectDef.qStateName",
label : "State",
type : "string",
component : "dropdown",
defaultValue : "$",
options: function() {
return qlik.currApp(this).getAppLayout().then(function (layout){
return [{value : "$", label : "Default"}].concat(layout.qStateNames.map(function (state){
return {value : state, label : state}
}));
});
}
}
}
}
}
},
snapshot: {
canTakeSnapshot: true
},
paint: function ( $element ) {
var self = this, html = "<ul>";
this.backendApi.eachDataRow( function ( rownum, row ) {
html += '<li class="data state' + row[0].qState + '" data-value="' + row[0].qElemNumber + '">' + row[0].qText;
if ( row[0].qFrequency ) {
html += '<span>' + row[0].qFrequency + '</span>';
}
html += '</li>';
} );
html += "</ul>";
$element.html( html );
if ( this.selectionsEnabled ) {
$element.find( 'li' ).on( 'qv-activate', function () {
if ( this.hasAttribute( "data-value" ) ) {
var value = parseInt( this.getAttribute( "data-value" ), 10 ), dim = 0;
self.selectValues( dim, [value], true );
$( this ).toggleClass( "selected" );
}
} );
}
}
};
} );