-
Notifications
You must be signed in to change notification settings - Fork 3
/
cswAltStateActions.js
162 lines (145 loc) · 6.98 KB
/
cswAltStateActions.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
define(["jquery", "qlik"], function ($, qlik) {
'use strict';
//$("<style>").html(cssContent).appendTo("head");
function copyStates(app, fromState, toState) {
app.clearAll(false, toState); // clear selections in target State
app.getObject(null, 'CurrentSelections').then(function (ret) {
// get all selections
var allSel = ret.layout.selectionsInStates;
var fromStateSel;
// find the selections that belong to the toState
allSel.forEach(function (sel) {
if (sel.stateName == fromState) fromStateSel = sel.qSelectionObject.qSelections;
});
//console.log(fromStateSel);
fromStateSel.forEach(function (fieldDesc, i) {
console.log('Selection found in field ', fieldDesc);
var fieldName = fieldDesc.qField || fieldDesc.name;
var fieldObj = app.field(fieldName, toState);
fieldObj.clear();
var secretSauce = "[" + fieldName + "]=Aggr(Only({<[" + fieldName + "]=P([" + fromState + "]::[" + fieldName + "])>} [" + fieldName + "]), [" + fieldName + "])";
fieldObj.selectMatch("=" + secretSauce, true, true);
fieldObj.selectPossible();
});
});
return true;
}
return {
initialProperties: {},
definition: {
type: "items",
component: "accordion",
items: {
settings: {
uses: "settings"
},
customProperties: {
component: "expandable-items",
label: "Custom Properties",
type: "items",
items: {
Layout: {
type: "items",
label: "Extension Settings",
items: [
/*{
ref: "mystate",
label: "Alternate State",
type: "string",
component: "dropdown",
//defaultValue : "$",
options: function () {
var retArr = [];
return qlik.currApp().getAppLayout().then(function (a) {
return a.layout.qStateNames.map(function (state) {
return { value: state, label: state }
})
});
}
},*/
{
type: "string",
ref: "enterStyle",
label: "Enter button style (CSS)",
defaultValue: "margin:2px;display:block;width:200px;"
}, {
type: "string",
ref: "labelCopyButton1",
label: "Button Label: Copy Into Alt. State",
defaultValue: "Copy Main \u25B6 Alt. State",
expression: "optional"
}, {
type: "string",
ref: "labelCopyButton2",
label: "Button Label: Copy From Alt. State",
defaultValue: "Copy Main \u25C0 Alt. State",
expression: "optional"
}, {
type: "string",
ref: "labelClearButton1",
label: "Button Label: Clear Main State",
defaultValue: "Clear Main State",
expression: "optional"
}, {
type: "string",
ref: "labelClearButton2",
label: "Button Label: Clear Alt State",
defaultValue: "Clear Alt. State",
expression: "optional"
}
]
}
}
}
}
},
support: {
snapshot: false,
export: false,
exportData: false
},
paint: function ($element, layout) {
$element.css('overflow', 'auto');
//console.dir(layout);
var self = this;
var ownId = this.options.id;
var app = qlik.currApp(this);
console.log('layout', layout);
var html = '';
if (layout.qStateName == '' || layout.qStateName == '$') {
html += '<p style="color:red;">Please select an alternate state in the settings.</p>';
$element.html(html);
} else {
if (layout.labelCopyButton1.length > 0) {
html += '<button class="lui-button" style="' + layout.enterStyle + '" id="' + ownId + 'Copy1">';
html += layout.labelCopyButton1 + '</button>';
}
if (layout.labelCopyButton2.length > 0) {
html += '<button class="lui-button" style="' + layout.enterStyle + '" id="' + ownId + 'Copy2">';
html += layout.labelCopyButton2 + '</button>';
}
if (layout.labelClearButton1.length > 0) {
html += '<button class="lui-button" style="' + layout.enterStyle + '" id="' + ownId + 'Clear1">';
html += layout.labelClearButton1 + '</button>';
}
if (layout.labelClearButton2.length > 0) {
html += '<button class="lui-button" style="' + layout.enterStyle + '" id="' + ownId + 'Clear2">';
html += layout.labelClearButton2 + '</button>';
}
$element.html(html);
$element.find("#" + ownId + 'Copy1').on("click", function () {
copyStates(app, "$", layout.qStateName);
});
$element.find("#" + ownId + 'Copy2').on("click", function () {
copyStates(app, layout.qStateName, "$");
});
$element.find("#" + ownId + 'Clear1').on("click", function () {
app.clearAll(false, "$");
});
$element.find("#" + ownId + 'Clear2').on("click", function () {
app.clearAll(false, layout.qStateName);
});
}
}
};
});