forked from simeonsv/sense-alternate-states
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAlternateStates.js
65 lines (57 loc) · 1.83 KB
/
AlternateStates.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
/*global define */
define(["jquery", "qlik"], function($, qlik) {
function createBtn(cmd, text) {
return '<button class="qirby-button" style="font-size:13px;" data-cmd="' + cmd + '">' + text + '</button>';
}
return {
initialProperties : {
version : 1.0
},
definition : {
type : "items",
component : "accordion",
items : {
}
},
paint : function($element, layout) {
$element.css('overflow', 'auto');
var self = this;
var html = '';
var app = qlik.currApp(this);
html += '<div class="qirby-buttongroup">';
html += '<input class="qirby-input" type="text" id="altStateName" value="" name"altStateName"/>';
html += createBtn("addAltState", "Add");
html += '</div>';
html += '<div class="qirby-buttongroup">';
html += '<select class="qirby-select" id="altStates">';
var getLayoutPromise = app.getAppLayout();
getLayoutPromise.then(function(layout){
$.each(layout.qStateNames, function(key, value) {
html += '<option value="' + value.replace(/\"/g, '"') + '">' + value + '</option>';
});
});
getLayoutPromise.finally(function(){
html += '</select>';
html += createBtn("removeAltState", "Remove");
$element.html(html);
$element.find('button').on('qv-activate', function() {
switch($(this).data('cmd')) {
case 'addAltState':
app.addAlternateState($element.find("#altStateName").val());
app.doSave().then(function(){
self.paint($element, layout);
});
break;
case 'removeAltState':
console.log($element.find("#altStates").val());
app.removeAlternateState($element.find("#altStates").val());
app.doSave().then(function(){
self.paint($element, layout);
});
break;
}
});
});
}
};
});