-
Notifications
You must be signed in to change notification settings - Fork 87
/
genericaddpluginsettings2.html
177 lines (163 loc) · 5.8 KB
/
genericaddpluginsettings2.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
<div class="genericaddpluginsettings2">
<h3 class="title"></h3>
<form>
<div class="form-group">
<label for="exampleInputEmail1">Plugin</label> <span class="pluginName"></span>
</div>
<div class="form-group">
<label for="exampleInputEmail1">Name</label> <input class="nameInp form-control"/>
</div>
</form>
<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">Add</button>
</div>
</div>
<script>
function GenericAddPluginSettings2(cd, main, usersettings, configuration, descriptor) {
var othis = this;
this.close = function() {
};
this.show = function() {
};
cd.find(".pluginName").html(descriptor.name);
cd.find(".nameInp").val(descriptor.name);
cd.find("h3.title").html(configuration.addTitle);
this.loadPluginObjectDefinition = function() {
Global.bimServerApi.call("PluginInterface", "getPluginObjectDefinition", {oid: descriptor.oid}, function(objectDefinition){
if (objectDefinition != null && objectDefinition.parameters != null) {
objectDefinition.parameters.forEach(function(parameter){
console.log(parameter.defaultValue);
cd.find(".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.val(parameter.defaultValue.value);
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.val(parameter.defaultValue.value);
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\"/>");
input.val(parameter.defaultValue.value);
td.append(input);
} else if (primitiveDefinition.type == "BYTE_ARRAY") {
input = $("<input class=\"form-control\" identifier=\"" + parameter.identifier + "\" dtype=\"" + primitiveDefinition.type + "\" type=\"file\"/>");
input.val(parameter.defaultValue.value);
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\"/>");
if (parameter.defaultValue.value) {
input.attr("checked", "checked");
}
td.append(input);
}
}
cd.find(".settingsTable tbody").append(tr);
});
}
});
};
othis.loadPluginObjectDefinition();
this.saveSettings = function(callback) {
var settings = {
__type: "SObjectType",
parameters: []
};
cd.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.pluginSettingsId, settings: settings}, function(data){
if (callback != null) {
callback();
}
});
};
this.savePlugin = function(){
var conf = {
__type: configuration.type,
name: cd.find(".nameInp").val(),
enabled: true,
description: descriptor.description,
pluginDescriptorId: descriptor.oid
};
Global.bimServerApi.call("PluginInterface", configuration.addNewCall, configuration.createUpdateObject(conf), function(oid){
othis.pluginSettingsId = oid;
othis.saveSettings(function(){
configuration.showListFunction();
});
});
};
this.save = function(event) {
event.preventDefault();
othis.savePlugin();
};
cd.find(".saveButton").click(othis.save);
}
</script>