-
Notifications
You must be signed in to change notification settings - Fork 87
/
genericpluginsettings.html
223 lines (210 loc) · 8.79 KB
/
genericpluginsettings.html
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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
<div class="genericpluginsettings">
<h3 class="title"></h3>
<table class="table detailsTable">
<tbody>
</tbody>
</table>
<h3>Settings</h3>
<div class="well well-sm nosettings">
No settings
</div>
<table class="table settingsTable">
<tbody>
</tbody>
</table>
<div class="popupLoader"></div>
<div class="well clearfix">
<button class="btn btn-primary saveButton pull-right">Save</button>
</div>
</div>
<script>
function GenericPluginSettings(main, usersettings, pluginsettingsoid, configuration) {
var othis = this;
this.close = function(){
};
this.show = function(){
};
this.loadGenericPluginSettings = function() {
$(".genericpluginsettings .detailsTable tbody").append("<tr><td>Name</td><td>" + othis.pluginsettings.name + "</td></tr>");
$(".genericpluginsettings .detailsTable tbody").append("<tr><td>Description</td><td>" + othis.pluginsettings.description + "</td></tr>");
$(".genericpluginsettings .detailsTable tbody").append("<tr><td>Status</td><td>" + (othis.pluginsettings.enabled ? "Enabled" : "Disabled") + "</td></tr>");
Global.bimServerApi.call("PluginInterface", "getPluginDescriptor", {oid: othis.pluginsettings.pluginDescriptorId}, function(pluginDescriptor){
$(".genericpluginsettings .detailsTable tbody").append("<tr><td>Class</td><td>" + pluginDescriptor.pluginClassName + "</td></tr>");
$(".genericpluginsettings .detailsTable tbody").append("<tr><td>Plugin State</td><td>" + (pluginDescriptor.enabled ? "Enabled" : "Disabled") + "</td></tr>");
Global.bimServerApi.call("PluginInterface", "getInstalledPluginBundle", {oid: pluginDescriptor.pluginBundleVersionId}, function(pluginBundleVersion){
console.log(pluginBundleVersion);
$(".genericpluginsettings .detailsTable tbody").append("<tr><td>Plugin Bundle</td><td>" + (pluginBundleVersion.groupId + "." + pluginBundleVersion.artifactId + ":" + pluginBundleVersion.version) + "</td></tr>");
});
});
if (configuration.title == "Internal Service") {
$(".genericpluginsettings .detailsTable tbody").append("<tr><td>Remote Accessible</td><td><input class=\"remoteAccessible\" type=\"checkbox\"" + (othis.pluginsettings.remoteAccessible ? " checked=\"checked\"" : "") + "/></td></tr>");
$(".genericpluginsettings .detailsTable tbody").append("<tr><td>Public Profile</td><td><input class=\"publicProfile\" type=\"checkbox\"" + (othis.pluginsettings.publicProfile ? " checked=\"checked\"" : "") + "/></td></tr>");
//$(".genericpluginsettings .detailsTable tbody").append("<tr><td><a class=\"linkStripeButton\">Link Stripe</a></td></tr>");
}
$(".genericpluginsettings h3.title").html(configuration.title);
othis.loadPluginObjectDefinition();
};
this.loadPluginSettings = function() {
Global.bimServerApi.call("PluginInterface", "getPluginSettings", {poid: pluginsettingsoid}, function(objectDefinition){
if (objectDefinition != null) {
if (objectDefinition.parameters != null) {
objectDefinition.parameters.forEach(function(parameter){
var input = $(".genericpluginsettings").find("input[identifier=\"" + parameter.identifier + "\"]");
var value = parameter.value;
if (value != null) {
if (value.__type == "SDoubleType" || value.__type == "SStringType" || value.__type == "SLongType") {
input.val(value.value);
} else if (value.__type == "SBooleanType") {
if (value.value) {
input.attr("checked", "checked");
}
} else if (value.__type == "SObjectType") {
} else if (value.__type == "SArrayType") {
} else if (value.__type == "SByteArrayType") {
if (value.value != null) {
input.data("base64", value.value);
input.parent().append("<span>Current: " + atob(value.value).length + " bytes</span>");
}
}
}
});
}
}
});
};
this.loadPluginObjectDefinition = function() {
Global.bimServerApi.call("PluginInterface", "getPluginObjectDefinition", {oid: othis.pluginsettings.pluginDescriptorId}, function(objectDefinition){
if (objectDefinition != null && objectDefinition.parameters != null) {
objectDefinition.parameters.forEach(function(parameter){
$(".genericpluginsettings .nosettings").hide();
var tr = $("<tr></tr>");
tr.append("<td></td>");
var link = $("<a>" + parameter.name.firstUpper() + "</a>");
link.tooltip({title: parameter.description});
tr.find("td").append(link);
var td = $("<td></td>");
tr.append(td);
if (parameter.type.__type == "SPrimitiveDefinition") {
var primitiveDefinition = parameter.type;
var input = null;
if (primitiveDefinition.type == "LONG") {
input = $("<input class=\"form-control\" identifier=\"" + parameter.identifier + "\" dtype=\"" + primitiveDefinition.type + "\" type=\"text\"/>");
input.numeric({ decimal: false, negative: false });
td.append(input);
} else if (primitiveDefinition.type == "DOUBLE") {
input = $("<input class=\"form-control\" identifier=\"" + parameter.identifier + "\" dtype=\"" + primitiveDefinition.type + "\" type=\"text\"/>");
input.numeric({ decimal: ".", negative: false });
td.append(input);
} else if (primitiveDefinition.type == "STRING") {
input = $("<input class=\"form-control\" identifier=\"" + parameter.identifier + "\" dtype=\"" + primitiveDefinition.type + "\" type=\"text\"/>");
td.append(input);
} else if (primitiveDefinition.type == "BYTE_ARRAY") {
input = $("<input class=\"form-control\" identifier=\"" + parameter.identifier + "\" dtype=\"" + primitiveDefinition.type + "\" type=\"file\"/>");
var reader = new FileReader();
reader.onload = function (event) {
var data = event.target.result;
var encoded = data.substr(data.indexOf(",") + 1);
input.data("base64", encoded);
};
input.change(function(){
var get = input.get(0);
var files = get.files;
if (files != null && files.length == 1) {
var oFile = files[0];
reader.readAsDataURL(oFile);
}
});
td.append(input);
} else if (primitiveDefinition.type == "BOOLEAN") {
input = $("<input class=\"form-control\" identifier=\"" + parameter.identifier + "\" dtype=\"" + primitiveDefinition.type + "\" type=\"checkbox\"/>");
td.append(input);
}
}
$(".genericpluginsettings .settingsTable tbody").append(tr);
});
othis.loadPluginSettings();
}
});
};
this.saveSettings = function(callback) {
var settings = {
__type: "SObjectType",
parameters: []
};
$(".genericpluginsettings").find("input[identifier]").each(function(){
var type = null;
var input = $(this);
if ($(this).attr("dtype") == "DOUBLE") {
type = {
__type: "SDoubleType",
value: parseFloat($(this).val())
};
} else if ($(this).attr("dtype") == "STRING") {
type = {
__type: "SStringType",
value: $(this).val()
};
} else if ($(this).attr("dtype") == "INTEGER") {
type = {
__type: "SStringType",
value: parseInt($(this).val())
};
} else if ($(this).attr("dtype") == "BYTE_ARRAY") {
type = {
__type: "SByteArrayType",
value: $(this).data("base64")
};
} else if ($(this).attr("dtype") == "BOOLEAN") {
type = {
__type: "SBooleanType",
value: $(this).is(":checked")
};
}
var parameter = {
__type: "SParameter",
identifier: $(this).attr("identifier"),
name: $(this).attr("name"),
value: type
};
settings.parameters.push(parameter);
});
Global.bimServerApi.callWithFullIndication("PluginInterface", "setPluginSettings", {poid: othis.pluginsettings.oid, settings: settings}, function(data){
if (callback != null) {
callback();
}
});
};
this.savePlugin = function() {
if (configuration.title == "Internal Service") {
othis.pluginsettings.remoteAccessible = $(".genericpluginsettings .remoteAccessible").is(":checked");
othis.pluginsettings.publicProfile = $(".genericpluginsettings .publicProfile").is(":checked");
Global.bimServerApi.call("PluginInterface", "updateInternalService", {internalService: othis.pluginsettings}, function(data){
othis.saveSettings();
});
} else {
othis.saveSettings();
}
};
this.save = function(event) {
event.preventDefault();
othis.savePlugin();
};
if (typeof pluginsettingsoid == "number") {
Global.bimServerApi.call(configuration.getInterface, configuration.getMethod, {oid: pluginsettingsoid}, function(data){
othis.pluginsettings = data;
othis.loadGenericPluginSettings();
});
} else {
othis.pluginsettings = pluginsettings;
othis.loadGenericPluginSettings();
}
$(".linkStripeButton").click(function(){
$(".popupLoader").load(Global.baseDir + "stripe.html", function(){
new StripeGetToken(function(token){
console.log(token);
});
});
});
$(".genericpluginsettings .saveButton").click(othis.save);
}
</script>