1 | /*
|
---|
2 | * TOPPERS/ECNL Prototyping tool
|
---|
3 | *
|
---|
4 | * Copyright (C) 2017 Cores Co., Ltd. Japan
|
---|
5 | *
|
---|
6 | * 上記著作権者は,以下の(1)~(4)の条件を満たす場合に限り,本ソフトウェ
|
---|
7 | * ア(本ソフトウェアを改変したものを含む.以下同じ)を使用・複製・改
|
---|
8 | * 変・再配布(以下,利用と呼ぶ)することを無償で許諾する.
|
---|
9 | * (1) 本ソフトウェアをソースコードの形で利用する場合には,上記の著作
|
---|
10 | * 権表示,この利用条件および下記の無保証規定が,そのままの形でソー
|
---|
11 | * スコード中に含まれていること.
|
---|
12 | * (2) 本ソフトウェアを,ライブラリ形式など,他のソフトウェア開発に使
|
---|
13 | * 用できる形で再配布する場合には,再配布に伴うドキュメント(利用
|
---|
14 | * 者マニュアルなど)に,上記の著作権表示,この利用条件および下記
|
---|
15 | * の無保証規定を掲載すること.
|
---|
16 | * (3) 本ソフトウェアを,機器に組み込むなど,他のソフトウェア開発に使
|
---|
17 | * 用できない形で再配布する場合には,次のいずれかの条件を満たすこ
|
---|
18 | * と.
|
---|
19 | * (a) 再配布に伴うドキュメント(利用者マニュアルなど)に,上記の著
|
---|
20 | * 作権表示,この利用条件および下記の無保証規定を掲載すること.
|
---|
21 | * (b) 再配布の形態を,別に定める方法によって,TOPPERSプロジェクトに
|
---|
22 | * 報告すること.
|
---|
23 | * (4) 本ソフトウェアの利用により直接的または間接的に生じるいかなる損
|
---|
24 | * 害からも,上記著作権者およびTOPPERSプロジェクトを免責すること.
|
---|
25 | * また,本ソフトウェアのユーザまたはエンドユーザからのいかなる理
|
---|
26 | * 由に基づく請求からも,上記著作権者およびTOPPERSプロジェクトを
|
---|
27 | * 免責すること.
|
---|
28 | *
|
---|
29 | * 本ソフトウェアは,無保証で提供されているものである.上記著作権者お
|
---|
30 | * よびTOPPERSプロジェクトは,本ソフトウェアに関して,特定の使用目的
|
---|
31 | * に対する適合性も含めて,いかなる保証も行わない.また,本ソフトウェ
|
---|
32 | * アの利用により直接的または間接的に生じたいかなる損害に関しても,そ
|
---|
33 | * の責任を負わない.
|
---|
34 | *
|
---|
35 | * @(#) $Id: EObjectModalView.cs 287 2017-05-05 14:22:23Z coas-nagasima $
|
---|
36 | */
|
---|
37 | using System;
|
---|
38 | using Bridge;
|
---|
39 | using Bridge.Bootstrap3;
|
---|
40 | using Bridge.Html5;
|
---|
41 | using Bridge.jQuery2;
|
---|
42 |
|
---|
43 | namespace WebMrbc
|
---|
44 | {
|
---|
45 | public class EObjectModalView
|
---|
46 | {
|
---|
47 | jQuery el;
|
---|
48 | JsonObjectInfo model;
|
---|
49 | JsonObjectInfo target;
|
---|
50 | JsonClassGroupInfo currentClassGroup;
|
---|
51 |
|
---|
52 | public event Action<EObjectModalView, bool> Closed;
|
---|
53 |
|
---|
54 | public EObjectModalView()
|
---|
55 | {
|
---|
56 | el = jQuery.Select("#eobject-modal");
|
---|
57 | }
|
---|
58 |
|
---|
59 | internal void SetEObject(JsonObjectInfo eobject, string imgUrl)
|
---|
60 | {
|
---|
61 | target = eobject;
|
---|
62 | model = eobject.Clone();
|
---|
63 |
|
---|
64 | var cg = model.type.classGroup;
|
---|
65 | if ((model.attribute == "device") && (model.type == App.NodeProfileClass)) {
|
---|
66 | cg = App.ClassGroups[0];
|
---|
67 | }
|
---|
68 |
|
---|
69 | var img = (new jQuery("<img>"));
|
---|
70 | img.Attr("src", imgUrl);
|
---|
71 | img.Attr("alt", model.identifier);
|
---|
72 | jQuery.Select("#eobject-modal-eobject img").ReplaceWith(img);
|
---|
73 |
|
---|
74 | jQuery.Select("#eobject_identifier").Val(model.identifier);
|
---|
75 | jQuery.Select("#eobject_instanceCode").Val(model.instanceCode.ToString());
|
---|
76 | SetAttribute(model.attribute);
|
---|
77 |
|
---|
78 | SetClassGroup(cg, () => {
|
---|
79 | var c = model.type;
|
---|
80 | if ((model.attribute == "device") && (model.type == App.NodeProfileClass)) {
|
---|
81 | c = App.ClassGroups[0].classes[0];
|
---|
82 | }
|
---|
83 | SetClass(c, UpdateProperties);
|
---|
84 | });
|
---|
85 | }
|
---|
86 |
|
---|
87 | internal void Render()
|
---|
88 | {
|
---|
89 | el.Modal(new ModalOptions() {
|
---|
90 | Backdrop = "static",
|
---|
91 | Show = true
|
---|
92 | });
|
---|
93 | }
|
---|
94 |
|
---|
95 | private void SetAttribute(string attribute)
|
---|
96 | {
|
---|
97 | var dropdown = jQuery.Select("#eobject_attribute").Parent();
|
---|
98 | var button = jQuery.Select("button[type='button']", dropdown);
|
---|
99 | button.Attr("disabled", "disabled");
|
---|
100 |
|
---|
101 | var menuitem = jQuery.Select("a[role='menuitem']", dropdown);
|
---|
102 |
|
---|
103 | string text;
|
---|
104 | switch (attribute) {
|
---|
105 | case "local":
|
---|
106 | text = menuitem.Get(0).TextContent;
|
---|
107 | break;
|
---|
108 | case "sync":
|
---|
109 | text = menuitem.Get(1).TextContent;
|
---|
110 | break;
|
---|
111 | case "async":
|
---|
112 | text = menuitem.Get(2).TextContent;
|
---|
113 | break;
|
---|
114 | case "device":
|
---|
115 | text = menuitem.Get(3).TextContent;
|
---|
116 | break;
|
---|
117 | default:
|
---|
118 | text = attribute;
|
---|
119 | break;
|
---|
120 | }
|
---|
121 |
|
---|
122 | SetAttribute(attribute, text);
|
---|
123 | }
|
---|
124 |
|
---|
125 | private void SetAttribute(string attribute, string text)
|
---|
126 | {
|
---|
127 | model.attribute = attribute;
|
---|
128 |
|
---|
129 | var button = jQuery.Select("#eobject_attribute");
|
---|
130 | button.Text(text);
|
---|
131 |
|
---|
132 | var caret = jQuery.Select("span.caret", button);
|
---|
133 | if (caret.Length == 0) {
|
---|
134 | caret = new jQuery(ElementType.Span);
|
---|
135 | caret.Attr("class", "caret");
|
---|
136 | button.Append(caret);
|
---|
137 | }
|
---|
138 | }
|
---|
139 |
|
---|
140 | private void SetClassGroup(JsonClassGroupInfo cg, Action success = null)
|
---|
141 | {
|
---|
142 | currentClassGroup = cg;
|
---|
143 |
|
---|
144 | var button = jQuery.Select("#eobject_classGroupCode");
|
---|
145 | button.Text(cg.description);
|
---|
146 |
|
---|
147 | if (model.attribute == "device") {
|
---|
148 | button.RemoveAttr("disabled");
|
---|
149 | }
|
---|
150 | else {
|
---|
151 | button.Attr("disabled", "disabled");
|
---|
152 | }
|
---|
153 |
|
---|
154 | var caret = jQuery.Select("span.caret", button);
|
---|
155 | if (caret.Length == 0) {
|
---|
156 | caret = new jQuery(ElementType.Span);
|
---|
157 | caret.Attr("class", "caret");
|
---|
158 | button.Append(caret);
|
---|
159 | }
|
---|
160 |
|
---|
161 | InitClasss(cg);
|
---|
162 | if (success != null) success();
|
---|
163 | }
|
---|
164 |
|
---|
165 | private void SetClass(JsonClassInfo c, Action success = null)
|
---|
166 | {
|
---|
167 | model.type = c;
|
---|
168 |
|
---|
169 | var button = jQuery.Select("#eobject_classCode");
|
---|
170 | button.Text(c.description);
|
---|
171 |
|
---|
172 | if (model.attribute == "device") {
|
---|
173 | button.RemoveAttr("disabled");
|
---|
174 | }
|
---|
175 | else {
|
---|
176 | button.Attr("disabled", "disabled");
|
---|
177 | }
|
---|
178 |
|
---|
179 | var caret = jQuery.Select("span.caret", button);
|
---|
180 | if (caret.Length == 0) {
|
---|
181 | caret = new jQuery(ElementType.Span);
|
---|
182 | caret.Attr("class", "caret");
|
---|
183 | button.Append(caret);
|
---|
184 | }
|
---|
185 |
|
---|
186 | string identifier = jQuery.Select("#eobject_identifier").Val();
|
---|
187 | if (model.identifier == identifier) {
|
---|
188 | model.identifier = CodeGenerator.GetClassIdentifier(c);
|
---|
189 | jQuery.Select("#eobject_identifier").Val(model.identifier);
|
---|
190 | }
|
---|
191 |
|
---|
192 | InitProperties(c);
|
---|
193 | if (success != null) success();
|
---|
194 | }
|
---|
195 |
|
---|
196 | internal void InitClassGroups()
|
---|
197 | {
|
---|
198 | var ul = jQuery.Select("#eobject_classGroups");
|
---|
199 |
|
---|
200 | ul.Html("");
|
---|
201 |
|
---|
202 | foreach (var cg in App.ClassGroups) {
|
---|
203 | var li = new jQuery(ElementType.LI);
|
---|
204 | li.Attr("role", "presentation");
|
---|
205 |
|
---|
206 | var a = new jQuery(ElementType.Anchor);
|
---|
207 | a.Attr("role", "menuitem");
|
---|
208 | a.Append(cg.description);
|
---|
209 | a.Click(cg, new Action<jQueryMouseEvent>(OnSelectClassGroupCode));
|
---|
210 |
|
---|
211 | li.Append(a);
|
---|
212 | ul.Append(li);
|
---|
213 | }
|
---|
214 | }
|
---|
215 |
|
---|
216 | internal void InitClasss(JsonClassGroupInfo cg)
|
---|
217 | {
|
---|
218 | var ul = jQuery.Select("#eobject_classs");
|
---|
219 |
|
---|
220 | ul.Html("");
|
---|
221 |
|
---|
222 | foreach (var c in cg.classes) {
|
---|
223 | var li = new jQuery(ElementType.LI);
|
---|
224 | li.Attr("role", "presentation");
|
---|
225 |
|
---|
226 | var a = new jQuery(ElementType.Anchor);
|
---|
227 | a.Attr("role", "menuitem");
|
---|
228 | a.Append(c.description);
|
---|
229 | a.Click(c, new Action<jQueryMouseEvent>(OnSelectClassCode));
|
---|
230 |
|
---|
231 | li.Append(a);
|
---|
232 | ul.Append(li);
|
---|
233 | }
|
---|
234 | }
|
---|
235 |
|
---|
236 | internal void InitProperties(JsonClassInfo c)
|
---|
237 | {
|
---|
238 | var div = jQuery.Select("#eobject_properties");
|
---|
239 |
|
---|
240 | div.Html("");
|
---|
241 |
|
---|
242 | if (c.classGroup.classGroupCode != 0x0E || c.classCode != 0xF0) {
|
---|
243 | foreach (var p in App.BaseObjectPropertyList) {
|
---|
244 | InitProperty(div, p);
|
---|
245 | }
|
---|
246 | }
|
---|
247 |
|
---|
248 | foreach (var p in c.properties) {
|
---|
249 | InitProperty(div, p);
|
---|
250 | }
|
---|
251 | }
|
---|
252 |
|
---|
253 | private void InitProperty(jQuery div, JsonPropertyInfo p)
|
---|
254 | {
|
---|
255 | var label = new jQuery(ElementType.Label);
|
---|
256 | label.Attr("class", "btn btn-default");
|
---|
257 |
|
---|
258 | var input = new jQuery(ElementType.Input);
|
---|
259 | input.Attr("type", "checkbox");
|
---|
260 | input.Attr("autocomplete", "off");
|
---|
261 |
|
---|
262 | label.Append(input);
|
---|
263 | label.Append(p.description);
|
---|
264 | label.Attr("data-ecnl-epc", p.propertyCode.ToString());
|
---|
265 |
|
---|
266 | div.Append(label);
|
---|
267 |
|
---|
268 | if ((p.required.Length > 0) && (p.required[0] != "NONE")) {
|
---|
269 | label.ButtonToggle();
|
---|
270 | }
|
---|
271 | }
|
---|
272 |
|
---|
273 | private void UpdateProperties()
|
---|
274 | {
|
---|
275 | var labels = jQuery.Select("#eobject_properties > .btn.btn-default");
|
---|
276 |
|
---|
277 | foreach (Element l in labels.Get()) {
|
---|
278 | var label = new jQuery(l);
|
---|
279 | if (label.Is(".active"))
|
---|
280 | label.ButtonToggle();
|
---|
281 |
|
---|
282 | var sepc = label.Attr("data-ecnl-epc");
|
---|
283 | if (sepc == null)
|
---|
284 | continue;
|
---|
285 |
|
---|
286 | var epc = Script.ParseInt(sepc);
|
---|
287 | JsonPropertyInfo prop = null;
|
---|
288 | foreach (var p in model.properties) {
|
---|
289 | if (p.propertyCode != epc)
|
---|
290 | continue;
|
---|
291 | prop = p;
|
---|
292 | break;
|
---|
293 | }
|
---|
294 | if (prop != null) {
|
---|
295 | label.ButtonToggle();
|
---|
296 | }
|
---|
297 | }
|
---|
298 | }
|
---|
299 |
|
---|
300 | public void OnChangeIdentifier(Element ele)
|
---|
301 | {
|
---|
302 | var identifier = jQuery.Select("#eobject_identifier").Val();
|
---|
303 | model.identifier = identifier;
|
---|
304 | }
|
---|
305 |
|
---|
306 | public void OnSelectAttribute(Element sender, string attribute)
|
---|
307 | {
|
---|
308 | var text = sender.TextContent;
|
---|
309 | SetAttribute(attribute, text);
|
---|
310 | }
|
---|
311 |
|
---|
312 | public void OnSelectClassGroupCode(jQueryMouseEvent e)
|
---|
313 | {
|
---|
314 | var cg = (JsonClassGroupInfo)e.Data;
|
---|
315 | SetClassGroup(cg, () => {
|
---|
316 | SetClass(cg.classes[0], UpdateProperties);
|
---|
317 | });
|
---|
318 | }
|
---|
319 |
|
---|
320 | public void OnSelectClassCode(jQueryMouseEvent e)
|
---|
321 | {
|
---|
322 | SetClass((JsonClassInfo)e.Data, UpdateProperties);
|
---|
323 | }
|
---|
324 |
|
---|
325 | public void OnChangeInstanceCode(Element sender)
|
---|
326 | {
|
---|
327 | model.instanceCode = (byte)Script.ParseInt((new jQuery(sender)).Val());
|
---|
328 | }
|
---|
329 |
|
---|
330 | public void OnOk(Element ele)
|
---|
331 | {
|
---|
332 | if ((model.attribute == "device") && (model.type == App.NodeProfileClass)) {
|
---|
333 | return;
|
---|
334 | }
|
---|
335 |
|
---|
336 | el.Modal(ModalOperation.Hide);
|
---|
337 |
|
---|
338 | target.type = model.type;
|
---|
339 | target.identifier = model.identifier;
|
---|
340 | target.parent = model.parent;
|
---|
341 | target.instanceCode = model.instanceCode;
|
---|
342 | target.attribute = model.attribute;
|
---|
343 | target.properties = new JsonPropertyInfo[0];
|
---|
344 |
|
---|
345 | var labels = jQuery.Select("#eobject_properties > .btn.btn-default");
|
---|
346 |
|
---|
347 | foreach (Element l in labels.Get()) {
|
---|
348 | var label = new jQuery(l);
|
---|
349 | if (!label.Is(".active"))
|
---|
350 | continue;
|
---|
351 |
|
---|
352 | var sepc = label.Attr("data-ecnl-epc");
|
---|
353 | if (sepc == null)
|
---|
354 | continue;
|
---|
355 |
|
---|
356 | var epc = Script.ParseInt(sepc);
|
---|
357 | JsonPropertyInfo prop = null;
|
---|
358 | if (model.type.classGroup.classGroupCode != 0x0E || model.type.classCode != 0xF0) {
|
---|
359 | foreach (var p in App.BaseObjectPropertyList) {
|
---|
360 | if (p.propertyCode != epc)
|
---|
361 | continue;
|
---|
362 | prop = p;
|
---|
363 | break;
|
---|
364 | }
|
---|
365 | }
|
---|
366 | if (prop != null) {
|
---|
367 | target.properties.Push(prop);
|
---|
368 | }
|
---|
369 | else {
|
---|
370 | foreach (var p in model.type.properties) {
|
---|
371 | if (p.propertyCode != epc)
|
---|
372 | continue;
|
---|
373 | prop = p;
|
---|
374 | break;
|
---|
375 | }
|
---|
376 | if (prop != null) {
|
---|
377 | target.properties.Push(prop);
|
---|
378 | }
|
---|
379 | }
|
---|
380 | }
|
---|
381 |
|
---|
382 | if (Closed != null)
|
---|
383 | Closed(this, true);
|
---|
384 | }
|
---|
385 |
|
---|
386 | public void OnCancel(Element ele)
|
---|
387 | {
|
---|
388 | el.Modal(ModalOperation.Hide);
|
---|
389 |
|
---|
390 | if (Closed != null)
|
---|
391 | Closed(this, false);
|
---|
392 | }
|
---|
393 | }
|
---|
394 | }
|
---|