source: EcnlProtoTool/trunk/webapp/webmrbc/EObjectModalView.cs@ 425

Last change on this file since 425 was 425, checked in by coas-nagasima, 4 years ago

Visual Studio 2019 と Bridge.NET でビルドできるよう更新。

  • Property svn:eol-style set to native
  • Property svn:mime-type set to text/x-csharp;charset=UTF-8
File size: 10.8 KB
Line 
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$
36 */
37using System;
38using Bridge;
39using Bridge.Bootstrap3;
40using Bridge.Html5;
41using Bridge.jQuery2;
42
43namespace 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 [Convention(Notation.CamelCase)]
301 public void OnChangeIdentifier(Element ele)
302 {
303 var identifier = jQuery.Select("#eobject_identifier").Val();
304 model.identifier = identifier;
305 }
306
307 [Convention(Notation.CamelCase)]
308 public void OnSelectAttribute(Element sender, string attribute)
309 {
310 var text = sender.TextContent;
311 SetAttribute(attribute, text);
312 }
313
314 [Convention(Notation.CamelCase)]
315 public void OnSelectClassGroupCode(jQueryMouseEvent e)
316 {
317 var cg = (JsonClassGroupInfo)e.Data;
318 SetClassGroup(cg, () => {
319 SetClass(cg.classes[0], UpdateProperties);
320 });
321 }
322
323 [Convention(Notation.CamelCase)]
324 public void OnSelectClassCode(jQueryMouseEvent e)
325 {
326 SetClass((JsonClassInfo)e.Data, UpdateProperties);
327 }
328
329 [Convention(Notation.CamelCase)]
330 public void OnChangeInstanceCode(Element sender)
331 {
332 model.instanceCode = (byte)Script.ParseInt((new jQuery(sender)).Val());
333 }
334
335 [Convention(Notation.CamelCase)]
336 public void OnOk(Element ele)
337 {
338 if ((model.attribute == "device") && (model.type == App.NodeProfileClass)) {
339 return;
340 }
341
342 el.Modal(ModalOperation.Hide);
343
344 target.type = model.type;
345 target.identifier = model.identifier;
346 target.parent = model.parent;
347 target.instanceCode = model.instanceCode;
348 target.attribute = model.attribute;
349 target.properties = new JsonPropertyInfo[0];
350
351 var labels = jQuery.Select("#eobject_properties > .btn.btn-default");
352
353 foreach (Element l in labels.Get()) {
354 var label = new jQuery(l);
355 if (!label.Is(".active"))
356 continue;
357
358 var sepc = label.Attr("data-ecnl-epc");
359 if (sepc == null)
360 continue;
361
362 var epc = Script.ParseInt(sepc);
363 JsonPropertyInfo prop = null;
364 if (model.type.classGroup.classGroupCode != 0x0E || model.type.classCode != 0xF0) {
365 foreach (var p in App.BaseObjectPropertyList) {
366 if (p.propertyCode != epc)
367 continue;
368 prop = p;
369 break;
370 }
371 }
372 if (prop != null) {
373 target.properties.Push(prop);
374 }
375 else {
376 foreach (var p in model.type.properties) {
377 if (p.propertyCode != epc)
378 continue;
379 prop = p;
380 break;
381 }
382 if (prop != null) {
383 target.properties.Push(prop);
384 }
385 }
386 }
387
388 if (Closed != null)
389 Closed(this, true);
390 }
391
392 [Convention(Notation.CamelCase)]
393 public void OnCancel(Element ele)
394 {
395 el.Modal(ModalOperation.Hide);
396
397 if (Closed != null)
398 Closed(this, false);
399 }
400 }
401}
Note: See TracBrowser for help on using the repository browser.