-
Notifications
You must be signed in to change notification settings - Fork 0
/
dashboard.js
99 lines (84 loc) · 2.68 KB
/
dashboard.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
(function() {
if (!window.AcmeCorporation) window.AcmeCorporation = {};
if (!AcmeCorporation.Apps) AcmeCorporation.Apps = {};
if (!AcmeCorporation.Apps.FacebookLike) AcmeCorporation.Apps.FacebookLike = {};
AcmeCorporation.Apps.FacebookLike.Dashboard = function(config) {
var target = config.target;
var instance = config.data.instance;
var appId = this.createInput({
"target": target,
"caption": "App ID",
"value": instance.config.appId
});
var URL = this.createInput({
"target": target,
"caption": "URL",
"value": instance.config.href
});
var scheme = this.createSelect({
"target": target,
"caption": "Color scheme",
"options": ["light", "dark"],
"value": instance.config.scheme
});
target.appendChild(document.createElement("br"));
this.createButton({
"target": target,
"caption": "Save",
"onclick": function() {
config.request({
"endpoint": "instance/{data:instance.id}/update",
"data": {
"config": {
"appId": appId.value,
"href": URL.value,
"scheme": scheme.value
}
}
});
},
"style": "margin-left: 170px;"
});
// apply 'ready' callback when dashboard rendering is complete
config.events.ready.apply(this);
};
AcmeCorporation.Apps.FacebookLike.Dashboard.prototype.createInput = function(config) {
var label = document.createElement("label");
label.innerHTML = config.caption || "";
config.target.appendChild(label);
var input = document.createElement("input");
input.type = "text";
input.value = config.value || "";
config.style && input.setAttribute("style", config.style);
config.target.appendChild(input);
return input;
};
AcmeCorporation.Apps.FacebookLike.Dashboard.prototype.createSelect = function(config) {
var addOption = function(select, value, selectedValue) {
var option = document.createElement("option");
option.text = option.value = value;
if (selectedValue === value) {
option.setAttribute("selected", selectedValue);
}
select.appendChild(option);
}
var label = document.createElement("label");
label.innerHTML = config.caption || "";
config.target.appendChild(label);
var select = document.createElement("select");
config.style && select.setAttribute("style", config.style);
for (var i = 0; i < config.options.length; i++) {
addOption(select, config.options[i], config.value);
}
config.target.appendChild(select);
return select;
};
AcmeCorporation.Apps.FacebookLike.Dashboard.prototype.createButton = function(config) {
var button = document.createElement("button");
button.innerHTML = config.caption || "";
config.style && button.setAttribute("style", config.style);
button.onclick = config.onclick || function() {};
config.target.appendChild(button);
return button;
};
})();