-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
70 lines (62 loc) · 2.62 KB
/
index.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
(function () {
const configure = () => {
tableau.extensions.ui.displayDialogAsync("./config.html", "");
};
tableau.extensions.initializeAsync({ configure: configure }).then(() => {
tableau.extensions.settings.addEventListener(
tableau.TableauEventType.SettingsChanged,
onSettingsChange
);
initRadioButton();
});
const onSettingsChange = () => {
initRadioButton();
};
const onParameterChange = (parameterChangeEvent) => {
parameterChangeEvent.getParameterAsync().then((parameter) => {
$(`input:radio[value="${parameter.currentValue.formattedValue}"]`).prop(
"checked",
true
);
});
};
const initRadioButton = () => {
const selectedParameterName = tableau.extensions.settings.get(
"selectedParameterNameKey"
);
tableau.extensions.dashboardContent.dashboard
.getParametersAsync()
.then((parameters) => {
const selectedParameter = parameters.find(
(p) => p.name === selectedParameterName
);
selectedParameter.addEventListener(
tableau.TableauEventType.ParameterChanged,
onParameterChange
);
const parameterValuesElement = $('<div id="parameter">');
selectedParameter.allowableValues.allowableValues.forEach(
(dataValue) => {
const eachValueElement = $('<div style="display: inline-block">');
$("<input />", {
type: "radio",
id: dataValue.formattedValue,
name: selectedParameter.name,
value: dataValue.formattedValue,
checked:
dataValue.formattedValue ===
selectedParameter.currentValue.formattedValue,
click: () =>
selectedParameter.changeValueAsync(dataValue.formattedValue),
}).appendTo(eachValueElement);
$("<label>", {
for: dataValue.formattedValue,
text: dataValue.formattedValue,
}).appendTo(eachValueElement);
parameterValuesElement.append(eachValueElement);
}
);
$("#parameter").replaceWith(parameterValuesElement);
});
};
})();