Debian Codegraph @

Server/Web/WebClient.cpp

raw symbols ◀ ▶
Source reconstructed at patch state 2 of 3 — not the installed (fully patched) source.
3 Debian patches touch this file
1 /*
2 RailControl - Model Railway Control Software
3
4 Copyright (c) 2017-2025 by Teddy / Dominik Mahrer - www.railcontrol.org
5
6 RailControl is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by the
8 Free Software Foundation; either version 3, or (at your option) any
9 later version.
10
11 RailControl is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14 See the GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with RailControl; see the file LICENCE. If not see
18 <http://www.gnu.org/licenses/>.
19 */
20
21 #include <algorithm>
22 #include <cstring> //memset
23 #include <netinet/in.h>
24 #include <signal.h>
25 #include <sstream>
26 #include <sys/socket.h>
27 #include <sys/stat.h>
28 #include <sys/time.h>
29 #include <unistd.h>
30
31 #include "DataModel/DataModel.h"
32 #include "DataModel/AccessoryConfig.h"
33 #include "DataModel/LocoConfig.h"
34 #include "DataModel/ObjectIdentifier.h"
35 #include "Hardware/HardwareHandler.h"
36 #include "RailControl.h"
37 #include "Utils/Utils.h"
38 #include "Server/Web/HtmlTagAccessory.h"
39 #include "Server/Web/HtmlTagButtonCancel.h"
40 #include "Server/Web/HtmlTagButtonCommand.h"
41 #include "Server/Web/HtmlTagButtonCommandFullScreen.h"
42 #include "Server/Web/HtmlTagButtonCommandPressRelease.h"
43 #include "Server/Web/HtmlTagButtonCommandToggle.h"
44 #include "Server/Web/HtmlTagButtonCommandWide.h"
45 #include "Server/Web/HtmlTagButtonOK.h"
46 #include "Server/Web/HtmlTagButtonPopup.h"
47 #include "Server/Web/HtmlTagButtonPopupWide.h"
48 #include "Server/Web/HtmlTagCounter.h"
49 #include "Server/Web/HtmlTagFeedback.h"
50 #include "Server/Web/HtmlTagInputCheckbox.h"
51 #include "Server/Web/HtmlTagInputCheckboxWithLabel.h"
52 #include "Server/Web/HtmlTagInputHidden.h"
53 #include "Server/Web/HtmlTagInputIntegerWithLabel.h"
54 #include "Server/Web/HtmlTagInputSliderLocoSpeed.h"
55 #include "Server/Web/HtmlTagInputTextWithLabel.h"
56 #include "Server/Web/HtmlTagRoute.h"
57 #include "Server/Web/HtmlTagSelectOrientation.h"
58 #include "Server/Web/HtmlTagSelectWithLabel.h"
59 #include "Server/Web/HtmlTagSignal.h"
60 #include "Server/Web/HtmlTagSwitch.h"
61 #include "Server/Web/HtmlTagText.h"
62 #include "Server/Web/HtmlTagTrack.h"
63 #include "Server/Web/ResponseCsv.h"
64 #include "Server/Web/ResponseHtml.h"
65 #include "Server/Web/ResponseHtmlFull.h"
66 #include "Server/Web/ResponseHtmlNotFound.h"
67 #include "Server/Web/ResponseHtmlNotImplemented.h"
68 #include "Server/Web/WebClient.h"
69 #include "Server/Web/WebClientStatic.h"
70 #include "Server/Web/WebServer.h"
71 #include "Utils/Integer.h"
72
73 using namespace DataModel;
74 using LayoutPosition = DataModel::LayoutItem::LayoutPosition;
75 using LayoutItemSize = DataModel::LayoutItem::LayoutItemSize;
76 using LayoutRotation = DataModel::LayoutItem::LayoutRotation;
77 using Visible = DataModel::LayoutItem::Visible;
78 using std::deque;
79 using std::map;
80 using std::string;
81 using std::thread;
82 using std::to_string;
83 using std::vector;
84
85 namespace Server { namespace Web
86 {
87 WebClient::~WebClient()
88 {
89 run = false;
90 clientThread.join();
91 delete connection;
92 }
93
94 // worker is the thread that handles client requests
95 void WebClient::Worker()
96 {
97 Utils::Utils::SetThreadName("WebClient");
98 logger->Debug(Languages::TextTcpConnectionEstablished, connection->AddressAsString());
99 WorkerImpl();
100 logger->Debug(Languages::TextTcpConnectionClosed, connection->AddressAsString());
101 terminated = true;
102 }
103
104 void WebClient::WorkerImpl()
105 {
106 run = true;
107 bool keepalive = true;
108
109 while (run && keepalive)
110 {
111 const int BufferSize = 8192;
112 char buffer[BufferSize];
113 memset(buffer, 0, BufferSize);
114
115 int pos = 0;
116 string s;
117 while (pos < BufferSize - 1 && s.find("\n\n") == string::npos && run)
118 {
119 int ret = connection->Receive(buffer + pos, BufferSize - 1 - pos, 0);
120 if (ret == -1)
121 {
122 if (errno != ETIMEDOUT)
123 {
124 logger->Debug(Languages::TextErrorReadingData, strerror(errno));
125 return;
126 }
127 if (run == false)
128 {
129 return;
130 }
131 continue;
132 }
133 pos += ret;
134 s = string(buffer);
135 Utils::Utils::ReplaceString(s, string("\r\n"), string("\n"));
136 Utils::Utils::ReplaceString(s, string("\r"), string("\n"));
137 }
138
139 deque<string> lines;
140 Utils::Utils::SplitString(s, string("\n"), lines);
141
142 if (lines.size() <= 1)
143 {
144 return;
145 }
146
147 string method;
148 string uri;
149 string protocol;
150 map<string, string> arguments;
151 map<string, string> headers;
152 InterpretClientRequest(lines, method, uri, protocol, arguments, headers);
153 keepalive = (Utils::Utils::GetStringMapEntry(headers, "Connection", "close").compare("keep-alive") == 0);
154 logger->Info(Languages::TextHttpRequest, method, uri);
155
156 // if method is not implemented
157 if ((method.compare("GET") != 0) && (method.compare("HEAD") != 0))
158 {
159 logger->Info(Languages::TextMethodNotImplemented, id, method);
160 ResponseHtmlNotImplemented response(method);
161 connection->Send(response);
162 return;
163 }
164
165 // handle requests
166 if (uri.compare("/") == 0)
167 {
168 PrintMainHTML();
169 }
170 else if (arguments["cmd"].compare("askshutdown") == 0)
171 {
172 HandleAskShutdown();
173 }
174 else if (arguments["cmd"].compare("shutdown") == 0)
175 {
176 ReplyResponse(ResponseInfo, Languages::TextShutdownRailControl);
177 shutdownRailControlWebserver();
178 }
179 else if (arguments["cmd"].compare("booster") == 0)
180 {
181 bool on = Utils::Utils::GetBoolMapEntry(arguments, "on");
182 if (on)
183 {
184 ReplyHtmlWithHeaderAndParagraph(Languages::TextTurningBoosterOn);
185 manager.Booster(ControlTypeWebServer, BoosterStateGo);
186 }
187 else
188 {
189 ReplyHtmlWithHeaderAndParagraph(Languages::TextTurningBoosterOff);
190 manager.Booster(ControlTypeWebServer, BoosterStateStop);
191 }
192 }
193 else if (arguments["cmd"].compare("layeredit") == 0)
194 {
195 HandleLayerEdit(arguments);
196 }
197 else if (arguments["cmd"].compare("layersave") == 0)
198 {
199 HandleLayerSave(arguments);
200 }
201 else if (arguments["cmd"].compare("layerlist") == 0)
202 {
203 HandleLayerList();
204 }
205 else if (arguments["cmd"].compare("layeraskdelete") == 0)
206 {
207 HandleLayerAskDelete(arguments);
208 }
209 else if (arguments["cmd"].compare("layerdelete") == 0)
210 {
211 HandleLayerDelete(arguments);
212 }
213 else if (arguments["cmd"].compare("controledit") == 0)
214 {
215 HandleControlEdit(arguments);
216 }
217 else if (arguments["cmd"].compare("controlsave") == 0)
218 {
219 HandleControlSave(arguments);
220 }
221 else if (arguments["cmd"].compare("controllist") == 0)
222 {
223 HandleControlList();
224 }
225 else if (arguments["cmd"].compare("controlaskdelete") == 0)
226 {
227 HandleControlAskDelete(arguments);
228 }
229 else if (arguments["cmd"].compare("controldelete") == 0)
230 {
231 HandleControlDelete(arguments);
232 }
233 else if (arguments["cmd"].compare("loco") == 0)
234 {
235 HandleLoco(arguments);
236 }
237 else if (arguments["cmd"].compare("locospeed") == 0)
238 {
239 HandleLocoBaseSpeed(arguments);
240 }
241 else if (arguments["cmd"].compare("locoorientation") == 0)
242 {
243 HandleLocoBaseOrientation(arguments);
244 }
245 else if (arguments["cmd"].compare("locofunction") == 0)
246 {
247 HandleLocoFunction(arguments);
248 }
249 else if (arguments["cmd"].compare("locoedit") == 0)
250 {
251 HandleLocoEdit(arguments);
252 }
253 else if (arguments["cmd"].compare("locosave") == 0)
254 {
255 HandleLocoSave(arguments);
256 }
257 else if (arguments["cmd"].compare("locolist") == 0)
258 {
259 HandleLocoList();
260 }
261 else if (arguments["cmd"].compare("locoaskdelete") == 0)
262 {
263 HandleLocoAskDelete(arguments);
264 }
265 else if (arguments["cmd"].compare("locodelete") == 0)
266 {
267 HandleLocoDelete(arguments);
268 }
269 else if (arguments["cmd"].compare("locorelease") == 0)
270 {
271 HandleLocoRelease(arguments);
272 }
273 else if (arguments["cmd"].compare("locoaddtimetable") == 0)
274 {
275 HandleLocoAddTimeTable(arguments);
276 }
277 else if (arguments["cmd"].compare("multipleunitedit") == 0)
278 {
279 HandleMultipleUnitEdit(arguments);
280 }
281 else if (arguments["cmd"].compare("multipleunitsave") == 0)
282 {
283 HandleMultipleUnitSave(arguments);
284 }
285 else if (arguments["cmd"].compare("multipleunitlist") == 0)
286 {
287 HandleMultipleUnitList();
288 }
289 else if (arguments["cmd"].compare("multipleunitaskdelete") == 0)
290 {
291 HandleMultipleUnitAskDelete(arguments);
292 }
293 else if (arguments["cmd"].compare("multipleunitdelete") == 0)
294 {
295 HandleMultipleUnitDelete(arguments);
296 }
297 else if (arguments["cmd"].compare("multipleunitrelease") == 0)
298 {
299 HandleMultipleUnitRelease(arguments);
300 }
301 else if (arguments["cmd"].compare("accessoryedit") == 0)
302 {
303 HandleAccessoryEdit(arguments);
304 }
305 else if (arguments["cmd"].compare("accessorysave") == 0)
306 {
307 HandleAccessorySave(arguments);
308 }
309 else if (arguments["cmd"].compare("accessorystate") == 0)
310 {
311 HandleAccessoryState(arguments);
312 }
313 else if (arguments["cmd"].compare("accessorylist") == 0)
314 {
315 HandleAccessoryList();
316 }
317 else if (arguments["cmd"].compare("accessoryaskdelete") == 0)
318 {
319 HandleAccessoryAskDelete(arguments);
320 }
321 else if (arguments["cmd"].compare("accessorydelete") == 0)
322 {
323 HandleAccessoryDelete(arguments);
324 }
325 else if (arguments["cmd"].compare("accessoryget") == 0)
326 {
327 HandleAccessoryGet(arguments);
328 }
329 else if (arguments["cmd"].compare("accessoryrelease") == 0)
330 {
331 HandleAccessoryRelease(arguments);
332 }
333 else if (arguments["cmd"].compare("switchedit") == 0)
334 {
335 HandleSwitchEdit(arguments);
336 }
337 else if (arguments["cmd"].compare("switchsave") == 0)
338 {
339 HandleSwitchSave(arguments);
340 }
341 else if (arguments["cmd"].compare("switchstate") == 0)
342 {
343 HandleSwitchState(arguments);
344 }
345 else if (arguments["cmd"].compare("switchstates") == 0)
346 {
347 route.HandleRelationSwitchStates(arguments);
348 }
349 else if (arguments["cmd"].compare("switchlist") == 0)
350 {
351 HandleSwitchList();
352 }
353 else if (arguments["cmd"].compare("switchaskdelete") == 0)
354 {
355 HandleSwitchAskDelete(arguments);
356 }
357 else if (arguments["cmd"].compare("switchdelete") == 0)
358 {
359 HandleSwitchDelete(arguments);
360 }
361 else if (arguments["cmd"].compare("switchget") == 0)
362 {
363 HandleSwitchGet(arguments);
364 }
365 else if (arguments["cmd"].compare("switchrelease") == 0)
366 {
367 HandleSwitchRelease(arguments);
368 }
369 else if (arguments["cmd"].compare("signaladdresses") == 0)
370 {
371 signal.HandleSignalAddresses(arguments);
372 }
373 else if (arguments["cmd"].compare("signaledit") == 0)
374 {
375 signal.HandleSignalEdit(arguments);
376 }
377 else if (arguments["cmd"].compare("signalsave") == 0)
378 {
379 signal.HandleSignalSave(arguments);
380 }
381 else if (arguments["cmd"].compare("signalstate") == 0)
382 {
383 signal.HandleSignalState(arguments);
384 }
385 else if (arguments["cmd"].compare("signalstates") == 0)
386 {
387 signal.HandleSignalStates(arguments);
388 }
389 else if (arguments["cmd"].compare("signallist") == 0)
390 {
391 signal.HandleSignalList();
392 }
393 else if (arguments["cmd"].compare("signalaskdelete") == 0)
394 {
395 signal.HandleSignalAskDelete(arguments);
396 }
397 else if (arguments["cmd"].compare("signaldelete") == 0)
398 {
399 signal.HandleSignalDelete(arguments);
400 }
401 else if (arguments["cmd"].compare("signalget") == 0)
402 {
403 signal.HandleSignalGet(arguments);
404 }
405 else if (arguments["cmd"].compare("signalrelease") == 0)
406 {
407 signal.HandleSignalRelease(arguments);
408 }
409 else if (arguments["cmd"].compare("routeedit") == 0)
410 {
411 route.HandleRouteEdit(arguments);
412 }
413 else if (arguments["cmd"].compare("routesave") == 0)
414 {
415 route.HandleRouteSave(arguments);
416 }
417 else if (arguments["cmd"].compare("routelist") == 0)
418 {
419 route.HandleRouteList();
420 }
421 else if (arguments["cmd"].compare("routeaskdelete") == 0)
422 {
423 route.HandleRouteAskDelete(arguments);
424 }
425 else if (arguments["cmd"].compare("routedelete") == 0)
426 {
427 route.HandleRouteDelete(arguments);
428 }
429 else if (arguments["cmd"].compare("routeget") == 0)
430 {
431 route.HandleRouteGet(arguments);
432 }
433 else if (arguments["cmd"].compare("routeexecute") == 0)
434 {
435 route.HandleRouteExecute(arguments);
436 }
437 else if (arguments["cmd"].compare("routerelease") == 0)
438 {
439 route.HandleRouteRelease(arguments);
440 }
441 else if (arguments["cmd"].compare("textedit") == 0)
442 {
443 text.HandleTextEdit(arguments);
444 }
445 else if (arguments["cmd"].compare("textsave") == 0)
446 {
447 text.HandleTextSave(arguments);
448 }
449 else if (arguments["cmd"].compare("textlist") == 0)
450 {
451 text.HandleTextList();
452 }
453 else if (arguments["cmd"].compare("textaskdelete") == 0)
454 {
455 text.HandleTextAskDelete(arguments);
456 }
457 else if (arguments["cmd"].compare("textdelete") == 0)
458 {
459 text.HandleTextDelete(arguments);
460 }
461 else if (arguments["cmd"].compare("textget") == 0)
462 {
463 text.HandleTextGet(arguments);
464 }
465 else if (arguments["cmd"].compare("trackedit") == 0)
466 {
467 track.HandleTrackEdit(arguments);
468 }
469 else if (arguments["cmd"].compare("tracksave") == 0)
470 {
471 track.HandleTrackSave(arguments);
472 }
473 else if (arguments["cmd"].compare("tracklist") == 0)
474 {
475 track.HandleTrackList();
476 }
477 else if (arguments["cmd"].compare("trackaskdelete") == 0)
478 {
479 track.HandleTrackAskDelete(arguments);
480 }
481 else if (arguments["cmd"].compare("trackdelete") == 0)
482 {
483 track.HandleTrackDelete(arguments);
484 }
485 else if (arguments["cmd"].compare("trackget") == 0)
486 {
487 track.HandleTrackGet(arguments);
488 }
489 else if (arguments["cmd"].compare("tracksetloco") == 0)
490 {
491 track.HandleTrackSetLoco(arguments);
492 }
493 else if (arguments["cmd"].compare("trackrelease") == 0)
494 {
495 track.HandleTrackRelease(arguments);
496 }
497 else if (arguments["cmd"].compare("trackstartloco") == 0)
498 {
499 track.HandleTrackStartLoco(arguments);
500 }
501 else if (arguments["cmd"].compare("trackstoploco") == 0)
502 {
503 track.HandleTrackStopLoco(arguments);
504 }
505 else if (arguments["cmd"].compare("trackblock") == 0)
506 {
507 track.HandleTrackBlock(arguments);
508 }
509 else if (arguments["cmd"].compare("trackorientation") == 0)
510 {
511 track.HandleTrackOrientation(arguments);
512 }
513 else if (arguments["cmd"].compare("feedbackedit") == 0)
514 {
515 HandleFeedbackEdit(arguments);
516 }
517 else if (arguments["cmd"].compare("feedbacksave") == 0)
518 {
519 HandleFeedbackSave(arguments);
520 }
521 else if (arguments["cmd"].compare("feedbackstate") == 0)
522 {
523 HandleFeedbackState(arguments);
524 }
525 else if (arguments["cmd"].compare("feedbacklist") == 0)
526 {
527 HandleFeedbackList();
528 }
529 else if (arguments["cmd"].compare("feedbackaskdelete") == 0)
530 {
531 HandleFeedbackAskDelete(arguments);
532 }
533 else if (arguments["cmd"].compare("feedbackdelete") == 0)
534 {
535 HandleFeedbackDelete(arguments);
536 }
537 else if (arguments["cmd"].compare("feedbackget") == 0)
538 {
539 HandleFeedbackGet(arguments);
540 }
541 else if (arguments["cmd"].compare("feedbacksoftrack") == 0)
542 {
543 route.HandleFeedbacksOfTrack(arguments);
544 }
545 else if (arguments["cmd"].compare("protocol") == 0)
546 {
547 HandleProtocol(arguments);
548 }
549 else if (arguments["cmd"].compare("accessoryaddress") == 0)
550 {
551 HandleAccessoryAddress(arguments);
552 }
553 else if (arguments["cmd"].compare("feedbackadd") == 0)
554 {
555 HandleFeedbackAdd(arguments);
556 }
557 else if (arguments["cmd"].compare("relationadd") == 0)
558 {
559 route.HandleRelationAdd(arguments);
560 }
561 else if (arguments["cmd"].compare("relationobject") == 0)
562 {
563 route.HandleRelationObject(arguments);
564 }
565 else if (arguments["cmd"].compare("layout") == 0)
566 {
567 HandleLayout(arguments);
568 }
569 else if (arguments["cmd"].compare("locoselector") == 0)
570 {
571 HandleLocoSelector(arguments);
572 }
573 else if (arguments["cmd"].compare("layerselector") == 0)
574 {
575 HandleLayerSelector(arguments);
576 }
577 else if (arguments["cmd"].compare("stopallimmediately") == 0)
578 {
579 manager.LocoBaseStopAllImmediately(ControlTypeWebServer);
580 }
581 else if (arguments["cmd"].compare("startall") == 0)
582 {
583 manager.LocoBaseStartAll();
584 }
585 else if (arguments["cmd"].compare("stopall") == 0)
586 {
587 manager.LocoBaseStopAll();
588 }
589 else if (arguments["cmd"].compare("settingsedit") == 0)
590 {
591 HandleSettingsEdit();
592 }
593 else if (arguments["cmd"].compare("settingssave") == 0)
594 {
595 HandleSettingsSave(arguments);
596 }
597 else if (arguments["cmd"].compare("slaveadd") == 0)
598 {
599 HandleSlaveAdd(arguments);
600 }
601 else if (arguments["cmd"].compare("timestamp") == 0)
602 {
603 HandleTimestamp(arguments);
604 }
605 else if (arguments["cmd"].compare("controlarguments") == 0)
606 {
607 HandleControlArguments(arguments);
608 }
609 else if (arguments["cmd"].compare("program") == 0)
610 {
611 HandleProgram();
612 }
613 else if (arguments["cmd"].compare("programmodeselector") == 0)
614 {
615 HandleProgramModeSelector(arguments);
616 }
617 else if (arguments["cmd"].compare("programread") == 0)
618 {
619 HandleProgramRead(arguments);
620 }
621 else if (arguments["cmd"].compare("programwrite") == 0)
622 {
623 HandleProgramWrite(arguments);
624 }
625 else if (arguments["cmd"].compare("getcvfields") == 0)
626 {
627 HandleCvFields(arguments);
628 }
629 else if (arguments["cmd"].compare("clusterlist") == 0)
630 {
631 cluster.HandleClusterList();
632 }
633 else if (arguments["cmd"].compare("clusteredit") == 0)
634 {
635 cluster.HandleClusterEdit(arguments);
636 }
637 else if (arguments["cmd"].compare("clustersave") == 0)
638 {
639 cluster.HandleClusterSave(arguments);
640 }
641 else if (arguments["cmd"].compare("clusteraskdelete") == 0)
642 {
643 cluster.HandleClusterAskDelete(arguments);
644 }
645 else if (arguments["cmd"].compare("clusterdelete") == 0)
646 {
647 cluster.HandleClusterDelete(arguments);
648 }
649 else if (arguments["cmd"].compare("counterlist") == 0)
650 {
651 counter.HandleCounterList();
652 }
653 else if (arguments["cmd"].compare("counteredit") == 0)
654 {
655 counter.HandleCounterEdit(arguments);
656 }
657 else if (arguments["cmd"].compare("countersave") == 0)
658 {
659 counter.HandleCounterSave(arguments);
660 }
661 else if (arguments["cmd"].compare("counteraskdelete") == 0)
662 {
663 counter.HandleCounterAskDelete(arguments);
664 }
665 else if (arguments["cmd"].compare("counterdelete") == 0)
666 {
667 counter.HandleCounterDelete(arguments);
668 }
669 else if (arguments["cmd"].compare("counterget") == 0)
670 {
671 counter.HandleCounterGet(arguments);
672 }
673 else if (arguments["cmd"].compare("counterincrement") == 0)
674 {
675 counter.HandleCounterIncrement(arguments);
676 }
677 else if (arguments["cmd"].compare("counterdecrement") == 0)
678 {
679 counter.HandleCounterDecrement(arguments);
680 }
681 else if (arguments["cmd"].compare("newposition") == 0)
682 {
683 HandleNewPosition(arguments);
684 }
685 else if (arguments["cmd"].compare("rotate") == 0)
686 {
687 HandleRotate(arguments);
688 }
689 else if (arguments["cmd"].compare("getlocolist") == 0)
690 {
691 string s = manager.GetLocoList();
692 connection->Send(ResponseCsv(s));
693 }
694 else if (arguments["cmd"].compare("getroutelist") == 0)
695 {
696 string s = manager.GetRouteList();
697 connection->Send(ResponseCsv(s));
698 }
699 else if (arguments["cmd"].compare("updater") == 0)
700 {
701 HandleUpdater(headers);
702 }
703 else
704 {
705 DeliverFile(uri);
706 }
707 }
708 }
709
710 void WebClient::InterpretClientRequest(const deque<string>& lines, string& method, string& uri, string& protocol, map<string,string>& arguments, map<string,string>& headers)
711 {
712 if (lines.size() == 0)
713 {
714 return;
715 }
716
717 for (auto& line : lines)
718 {
719 if (line.find("HTTP/1.") == string::npos)
720 {
721 deque<string> list;
722 Utils::Utils::SplitString(line, string(": "), list);
723 if (list.size() == 2)
724 {
725 headers[list[0]] = list[1];
726 }
727 continue;
728 }
729
730 deque<string> list;
731 Utils::Utils::SplitString(line, string(" "), list);
732 if (list.size() != 3)
733 {
734 continue;
735 }
736
737 method = list[0];
738 // transform method to uppercase
739 std::transform(method.begin(), method.end(), method.begin(), ::toupper);
740
741 // if method == HEAD set membervariable
742 headOnly = method.compare("HEAD") == 0;
743
744 // set uri and protocol
745 uri = list[1];
746 protocol = list[2];
747
748 // read GET-arguments from uri
749 deque<string> uriParts;
750 Utils::Utils::SplitString(uri, "?", uriParts);
751 if (uriParts.size() != 2)
752 {
753 continue;
754 }
755
756 deque<string> argumentStrings;
757 Utils::Utils::SplitString(uriParts[1], "&", argumentStrings);
758 for (auto& argument : argumentStrings)
759 {
760 if (argument.length() == 0)
761 {
762 continue;
763 }
764 string key;
765 string value;
766 Utils::Utils::SplitString(argument, "=", key, value);
767 arguments[key] = Utils::Utils::UrlDecode(value);
768 }
769 }
770 }
771
772 void WebClient::DeliverFile(const string& virtualFile)
773 {
774 std::stringstream ss;
775 char workingDir[128];
776 if (getcwd(workingDir, sizeof(workingDir)))
777 {
778 ss << workingDir << "/html" << virtualFile;
779 }
780 string sFile = ss.str();
781 const char* realFile = sFile.c_str();
782 FILE* f = fopen(realFile, "r");
783 if (f == nullptr)
784 {
785 ResponseHtmlNotFound response(virtualFile);
786 connection->Send(response);
787 logger->Info(Languages::TextFileNotFound, virtualFile);
788 return;
789 }
790
791 DeliverFileInternal(f, realFile, virtualFile);
792 fclose(f);
793 }
794
795 void WebClient::DeliverFileInternal(FILE* f, const char* realFile, const string& virtualFile)
796 {
797 struct stat s;
798 int rc = stat(realFile, &s);
799 if (rc != 0)
800 {
801 return;
802 }
803
804 size_t length = virtualFile.length();
805 const char* contentType = nullptr;
806 if (length > 4 && virtualFile[length - 4] == '.')
807 {
808 if (virtualFile[length - 3] == 'i' && virtualFile[length - 2] == 'c' && virtualFile[length - 1] == 'o')
809 {
810 contentType = "image/x-icon";
811 }
812 else if (virtualFile[length - 3] == 'c' && virtualFile[length - 2] == 's' && virtualFile[length - 1] == 's')
813 {
814 contentType = "text/css";
815 }
816 else if (virtualFile[length - 3] == 'p' && virtualFile[length - 2] == 'n' && virtualFile[length - 1] == 'g')
817 {
818 contentType = "image/png";
819 }
820 else if (virtualFile[length - 3] == 't' && virtualFile[length - 2] == 't' && virtualFile[length - 1] == 'f')
821 {
822 contentType = "application/x-font-ttf";
823 }
824 }
825 else if (length > 3 && virtualFile[length - 3] == '.' && virtualFile[length - 2] == 'j' && virtualFile[length - 1] == 's')
826 {
827 contentType = "application/javascript";
828 }
829
830 Response response;
831 response.AddHeader("Cache-Control", "no-cache, must-revalidate");
832 response.AddHeader("Pragma", "no-cache");
833 response.AddHeader("Expires", "Sun, 12 Feb 2016 00:00:00 GMT");
834 response.AddHeader("Content-Length", to_string(s.st_size));
835 if (contentType != nullptr)
836 {
837 response.AddHeader("Content-Type", contentType);
838 }
839 connection->Send(response);
840
841 if (headOnly == true)
842 {
843 return;
844 }
845
846 char* buffer = static_cast<char*>(malloc(s.st_size));
847 if (buffer == nullptr)
848 {
849 return;
850 }
851
852 size_t r = fread(buffer, 1, s.st_size, f);
853 connection->Send(buffer, r, 0);
854 free(buffer);
855 }
856
857 void WebClient::HandleAskShutdown()
858 {
859 HtmlTag content;
860 content.AddContent(HtmlTag("h1").AddContent(Languages::TextShutdown));
861 content.AddContent(HtmlTag("p").AddContent(Languages::TextAreYouSureToShutdown));
862 content.AddContent(HtmlTag("form").AddId("editform").AddContent(HtmlTagInputHidden("cmd", "shutdown")));
863 content.AddContent(HtmlTagButtonCancel());
864 content.AddContent(HtmlTagButtonOK());
865 ReplyHtmlWithHeader(content);
866 }
867
868 void WebClient::HandleLayerEdit(const map<string, string>& arguments)
869 {
870 HtmlTag content;
871 LayerID layerID = Utils::Utils::GetIntegerMapEntry(arguments, "layer", LayerNone);
872 string name = Languages::GetText(Languages::TextNew);
873
874 if (layerID != LayerNone)
875 {
876 Layer* layer = manager.GetLayer(layerID);
877 if (layer != nullptr)
878 {
879 name = layer->GetName();
880 }
881 }
882
883 content.AddChildTag(HtmlTag("h1").AddContent(name).AddId("popup_title"));
884 HtmlTag form("form");
885 form.AddId("editform");
886 form.AddChildTag(HtmlTagInputHidden("cmd", "layersave"));
887 form.AddChildTag(HtmlTagInputHidden("layer", to_string(layerID)));
888 form.AddChildTag(HtmlTagInputTextWithLabel("name", Languages::TextName, name).AddAttribute("onkeyup", "updateName();"));
889 content.AddChildTag(HtmlTag("div").AddClass("popup_content").AddChildTag(form));
890 content.AddChildTag(HtmlTagButtonCancel());
891 content.AddChildTag(HtmlTagButtonOK());
892 ReplyHtmlWithHeader(content);
893 }
894
895 void WebClient::HandleLayerSave(const map<string, string>& arguments)
896 {
897 LayerID layerID = Utils::Utils::GetIntegerMapEntry(arguments, "layer", LayerNone);
898 string name = Utils::Utils::GetStringMapEntry(arguments, "name");
899 string result;
900
901 if (!manager.LayerSave(layerID, name, result))
902 {
903 ReplyResponse(ResponseError, result);
904 return;
905 }
906
907 ReplyResponse(ResponseInfo, Languages::TextLayerSaved, name);
908 }
909
910 void WebClient::HandleLayerAskDelete(const map<string, string>& arguments)
911 {
912 LayerID layerID = Utils::Utils::GetIntegerMapEntry(arguments, "layer", LayerNone);
913
914 if (layerID == LayerNone)
915 {
916 ReplyHtmlWithHeaderAndParagraph(Languages::TextLayerDoesNotExist);
917 return;
918 }
919
920 if (layerID == LayerUndeletable)
921 {
922 ReplyHtmlWithHeaderAndParagraph(Languages::TextLayer1IsUndeletable);
923 return;
924 }
925
926 const Layer* layer = manager.GetLayer(layerID);
927 if (layer == nullptr)
928 {
929 ReplyHtmlWithHeaderAndParagraph(Languages::GetText(Languages::TextLayerDoesNotExist));
930 return;
931 }
932
933 HtmlTag content;
934 content.AddContent(HtmlTag("h1").AddContent(Languages::TextDeleteLayer));
935 content.AddContent(HtmlTag("p").AddContent(Languages::TextAreYouSureToDelete, layer->GetName()));
936 content.AddContent(HtmlTag("form").AddId("editform")
937 .AddContent(HtmlTagInputHidden("cmd", "layerdelete"))
938 .AddContent(HtmlTagInputHidden("layer", to_string(layerID))
939 ));
940 content.AddContent(HtmlTagButtonCancel());
941 content.AddContent(HtmlTagButtonOK());
942 ReplyHtmlWithHeader(content);
943 }
944
945 void WebClient::HandleLayerDelete(const map<string, string>& arguments)
946 {
947 LayerID layerID = Utils::Utils::GetIntegerMapEntry(arguments, "layer", LayerNone);
948
949 if (layerID == LayerNone)
950 {
951 ReplyResponse(ResponseError, Languages::TextLayerDoesNotExist);
952 return;
953 }
954
955 if (layerID == LayerUndeletable)
956 {
957 ReplyResponse(ResponseError, Languages::TextLayer1IsUndeletable);
958 return;
959 }
960
961 const Layer* layer = manager.GetLayer(layerID);
962 if (layer == nullptr)
963 {
964 ReplyResponse(ResponseError, Languages::TextLayerDoesNotExist);
965 return;
966 }
967
968 string name = layer->GetName();
969 string result;
970 if (!manager.LayerDelete(layerID, result))
971 {
972 ReplyResponse(ResponseError, result);
973 return;
974 }
975
976 ReplyResponse(ResponseInfo, Languages::TextLayerDeleted, name);
977 }
978
979 void WebClient::HandleLayerList()
980 {
981 HtmlTag content;
982 content.AddChildTag(HtmlTag("h1").AddContent(Languages::TextLayers));
983 HtmlTag table("table");
984 const map<string,LayerID> layerList = manager.LayerListByName();
985 map<string,string> layerArgument;
986 for (auto& layer : layerList)
987 {
988 HtmlTag row("tr");
989 row.AddChildTag(HtmlTag("td").AddContent(layer.first));
990 string layerIdString = to_string(layer.second);
991 layerArgument["layer"] = layerIdString;
992 row.AddChildTag(HtmlTag("td").AddChildTag(HtmlTagButtonPopupWide(Languages::TextEdit, "layeredit_list_" + layerIdString, layerArgument)));
993 if (layer.second != LayerUndeletable)
994 {
995 row.AddChildTag(HtmlTag("td").AddChildTag(HtmlTagButtonPopupWide(Languages::TextDelete, "layeraskdelete_" + layerIdString, layerArgument)));
996 }
997 table.AddChildTag(row);
998 }
999 content.AddChildTag(HtmlTag("div").AddClass("popup_content").AddChildTag(table));
1000 content.AddChildTag(HtmlTagButtonCancel());
1001 content.AddChildTag(HtmlTagButtonPopupWide(Languages::TextNew, "layeredit_0"));
1002 ReplyHtmlWithHeader(content);
1003 }
1004
1005 void WebClient::HandleControlEdit(const map<string, string>& arguments)
1006 {
1007 HtmlTag content;
1008 ControlID controlID = Utils::Utils::GetIntegerMapEntry(arguments, "control", ControlIdNone);
1009 HardwareType hardwareType = HardwareTypeNone;
1010 string name = Languages::GetText(Languages::TextNew);
1011 string arg1;
1012 string arg2;
1013 string arg3;
1014 string arg4;
1015 string arg5;
1016
1017 if (controlID != ControlIdNone)
1018 {
1019 Hardware::HardwareParams* params = manager.GetHardware(controlID);
1020 if (params != nullptr)
1021 {
1022 hardwareType = params->GetHardwareType();
1023 name = params->GetName();
1024 arg1 = params->GetArg1();
1025 arg2 = params->GetArg2();
1026 arg3 = params->GetArg3();
1027 arg4 = params->GetArg4();
1028 arg5 = params->GetArg5();
1029 }
1030 }
1031
1032 const std::map<string,HardwareType> hardwareOptions = WebClientStatic::ListHardwareNames();
1033
1034 content.AddChildTag(HtmlTag("h1").AddContent(name).AddId("popup_title"));
1035 HtmlTag form("form");
1036 form.AddId("editform");
1037 form.AddChildTag(HtmlTagInputHidden("cmd", "controlsave"));
1038 form.AddChildTag(HtmlTagInputHidden("control", to_string(controlID)));
1039 form.AddChildTag(HtmlTagInputTextWithLabel("name", Languages::TextName, name).AddAttribute("onkeyup", "updateName();"));
1040
1041 HtmlTagSelectWithLabel selectHardwareType("hardwaretype", Languages::TextType, hardwareOptions, hardwareType);
1042 selectHardwareType.AddAttribute("onchange", "getArgumentsOfHardwareType();");
1043 form.AddChildTag(selectHardwareType);
1044
1045 HtmlTag controlArguments("div");
1046 controlArguments.AddId("controlarguments");
1047 controlArguments.AddChildTag(WebClientStatic::HtmlTagControlArguments(hardwareType, arg1, arg2, arg3, arg4, arg5));
1048 form.AddChildTag(controlArguments);
1049
1050 content.AddChildTag(HtmlTag("div").AddClass("popup_content").AddChildTag(form));
1051 content.AddChildTag(HtmlTagButtonCancel());
1052 content.AddChildTag(HtmlTagButtonOK());
1053 ReplyHtmlWithHeader(content);
1054 }
1055
1056 void WebClient::HandleControlSave(const map<string, string>& arguments)
1057 {
1058 ControlID controlID = Utils::Utils::GetIntegerMapEntry(arguments, "control", ControlIdNone);
1059 string name = Utils::Utils::GetStringMapEntry(arguments, "name");
1060 HardwareType hardwareType = static_cast<HardwareType>(Utils::Utils::GetIntegerMapEntry(arguments, "hardwaretype", HardwareTypeNone));
1061 string arg1 = Utils::Utils::GetStringMapEntry(arguments, "arg1");
1062 string arg2 = Utils::Utils::GetStringMapEntry(arguments, "arg2");
1063 string arg3 = Utils::Utils::GetStringMapEntry(arguments, "arg3");
1064 string arg4 = Utils::Utils::GetStringMapEntry(arguments, "arg4");
1065 string arg5 = Utils::Utils::GetStringMapEntry(arguments, "arg5");
1066 string result;
1067
1068 if (!manager.ControlSave(controlID, hardwareType, name, arg1, arg2, arg3, arg4, arg5, result))
1069 {
1070 ReplyResponse(ResponseError, result);
1071 return;
1072 }
1073
1074 ReplyResponse(ResponseInfo, Languages::TextControlSaved, name);
1075 }
1076
1077 void WebClient::HandleControlAskDelete(const map<string, string>& arguments)
1078 {
1079 ControlID controlID = Utils::Utils::GetIntegerMapEntry(arguments, "control", ControlNone);
1080
1081 if (controlID == ControlNone)
1082 {
1083 ReplyHtmlWithHeaderAndParagraph(Languages::TextControlDoesNotExist);
1084 return;
1085 }
1086
1087 const Hardware::HardwareParams* control = manager.GetHardware(controlID);
1088 if (control == nullptr)
1089 {
1090 ReplyHtmlWithHeaderAndParagraph(Languages::TextControlDoesNotExist);
1091 return;
1092 }
1093
1094 HtmlTag content;
1095 content.AddContent(HtmlTag("h1").AddContent(Languages::TextDeleteControl));
1096 content.AddContent(HtmlTag("p").AddContent(Languages::TextAreYouSureToDelete, control->GetName()));
1097 content.AddContent(HtmlTag("form").AddId("editform")
1098 .AddContent(HtmlTagInputHidden("cmd", "controldelete"))
1099 .AddContent(HtmlTagInputHidden("control", to_string(controlID))
1100 ));
1101 content.AddContent(HtmlTagButtonCancel());
1102 content.AddContent(HtmlTagButtonOK());
1103 ReplyHtmlWithHeader(content);
1104 }
1105
1106 void WebClient::HandleControlDelete(const map<string, string>& arguments)
1107 {
1108 ControlID controlID = Utils::Utils::GetIntegerMapEntry(arguments, "control", ControlNone);
1109 const Hardware::HardwareParams* control = manager.GetHardware(controlID);
1110 if (control == nullptr)
1111 {
1112 ReplyResponse(ResponseError, Languages::TextControlDoesNotExist);
1113 return;
1114 }
1115
1116 string name = control->GetName();
1117
1118 if (!manager.ControlDelete(controlID))
1119 {
1120 ReplyResponse(ResponseError, Languages::TextControlDoesNotExist);
1121 return;
1122 }
1123
1124 ReplyResponse(ResponseInfo, Languages::TextControlDeleted, name);
1125 }
1126
1127 void WebClient::HandleControlList()
1128 {
1129 HtmlTag content;
1130 content.AddChildTag(HtmlTag("h1").AddContent(Languages::TextControls));
1131 HtmlTag table("table");
1132 const map<string,Hardware::HardwareParams*> hardwareList = manager.ControlListByName();
1133 map<string,string> hardwareArgument;
1134 for (auto& hardware : hardwareList)
1135 {
1136 HtmlTag row("tr");
1137 row.AddChildTag(HtmlTag("td").AddContent(hardware.first));
1138 string controlIdString = to_string(hardware.second->GetControlID());
1139 hardwareArgument["control"] = controlIdString;
1140 row.AddChildTag(HtmlTag("td").AddChildTag(HtmlTagButtonPopupWide(Languages::TextEdit, "controledit_list_" + controlIdString, hardwareArgument)));
1141 row.AddChildTag(HtmlTag("td").AddChildTag(HtmlTagButtonPopupWide(Languages::TextDelete, "controlaskdelete_" + controlIdString, hardwareArgument)));
1142 table.AddChildTag(row);
1143 }
1144 content.AddChildTag(HtmlTag("div").AddClass("popup_content").AddChildTag(table));
1145 content.AddChildTag(HtmlTagButtonCancel());
1146 content.AddChildTag(HtmlTagButtonPopupWide(Languages::TextNew, "controledit_0"));
1147 ReplyHtmlWithHeader(content);
1148 }
1149
1150 void WebClient::HandleLocoBaseSpeed(const map<string, string>& arguments)
1151 {
1152 const LocoID locoID = Utils::Utils::GetIntegerMapEntry(arguments, "loco", LocoNone);
1153 const Speed speed = Utils::Utils::GetIntegerMapEntry(arguments, "speed", MinSpeed);
1154
1155 const ObjectIdentifier locoBaseIdentifier(WebClientStatic::LocoIdToObjectIdentifier(locoID));
1156
1157 manager.LocoBaseSpeed(ControlTypeWebServer, locoBaseIdentifier, speed);
1158
1159 ReplyHtmlWithHeaderAndParagraph(Languages::TextLocoSpeedIs, manager.GetLocoBaseName(locoBaseIdentifier), speed);
1160 }
1161
1162 void WebClient::HandleLocoBaseOrientation(const map<string, string>& arguments)
1163 {
1164 const LocoID locoID = Utils::Utils::GetIntegerMapEntry(arguments, "loco", LocoNone);
1165 const Orientation orientation = (Utils::Utils::GetBoolMapEntry(arguments, "on") ? OrientationRight : OrientationLeft);
1166
1167 const ObjectIdentifier locoBaseIdentifier(WebClientStatic::LocoIdToObjectIdentifier(locoID));
1168
1169 manager.LocoBaseOrientation(ControlTypeWebServer, locoBaseIdentifier, orientation);
1170
1171 ReplyHtmlWithHeaderAndParagraph(orientation == OrientationLeft ? Languages::TextLocoDirectionOfTravelIsLeft : Languages::TextLocoDirectionOfTravelIsRight, manager.GetLocoBaseName(locoBaseIdentifier));
1172 }
1173
1174 void WebClient::HandleLocoFunction(const map<string, string>& arguments)
1175 {
1176 const LocoID locoID = Utils::Utils::GetIntegerMapEntry(arguments, "loco", LocoNone);
1177 const DataModel::LocoFunctionNr function = Utils::Utils::GetIntegerMapEntry(arguments, "function", 0);
1178 const DataModel::LocoFunctionState state = static_cast<DataModel::LocoFunctionState>(Utils::Utils::GetBoolMapEntry(arguments, "on"));
1179
1180 const ObjectIdentifier locoBaseIdentifier(WebClientStatic::LocoIdToObjectIdentifier(locoID));
1181
1182 manager.LocoBaseFunctionState(ControlTypeWebServer, locoBaseIdentifier, function, state);
1183
1184 ReplyHtmlWithHeaderAndParagraph(state ? Languages::TextLocoFunctionIsOn : Languages::TextLocoFunctionIsOff, manager.GetLocoBaseName(locoBaseIdentifier), function);
1185 }
1186
1187 void WebClient::HandleLocoRelease(const map<string, string>& arguments)
1188 {
1189 bool ret = false;
1190 const LocoID locoID = Utils::Utils::GetIntegerMapEntry(arguments, "loco", LocoNone);
1191 if (locoID != LocoNone)
1192 {
1193 ret = manager.LocoRelease(locoID);
1194 }
1195 else
1196 {
1197 TrackID trackID = static_cast<TrackID>(Utils::Utils::GetIntegerMapEntry(arguments, "track", TrackNone));
1198 ret = manager.LocoBaseReleaseOnTrack(trackID);
1199 }
1200 ReplyHtmlWithHeaderAndParagraph(ret ? "Loco released" : "Loco not released");
1201 }
1202
1203 void WebClient::HandleMultipleUnitRelease(const map<string, string>& arguments)
1204 {
1205 bool ret = false;
1206 MultipleUnitID multipleUnitID = Utils::Utils::GetIntegerMapEntry(arguments, "multipleunit", MultipleUnitNone);
1207 if (multipleUnitID != LocoNone)
1208 {
1209 ret = manager.MultipleUnitRelease(multipleUnitID);
1210 }
1211 else
1212 {
1213 TrackID trackID = static_cast<TrackID>(Utils::Utils::GetIntegerMapEntry(arguments, "track", TrackNone));
1214 ret = manager.LocoBaseReleaseOnTrack(trackID);
1215 }
1216 ReplyHtmlWithHeaderAndParagraph(ret ? "Loco released" : "Loco not released");
1217 }
1218
1219 void WebClient::HandleLocoAddTimeTable(const map<string, string>& arguments)
1220 {
1221 const TrackID trackID = Utils::Utils::GetIntegerMapEntry(arguments, "track", TrackNone);
1222 const ObjectIdentifier locoBaseIdentifier = manager.GetLocoBaseIdentifierOfTrack(trackID);
1223 const RouteID routeID = static_cast<RouteID>(Utils::Utils::GetIntegerMapEntry(arguments, "route"));
1224 const bool automode = Utils::Utils::GetStringMapEntry(arguments, "followup", "manual").compare("automode") == 0;
1225 bool ret = manager.LocoBaseAddTimeTable(locoBaseIdentifier, routeID, automode);
1226 manager.TrackStartLocoBase(trackID);
1227 ReplyHtmlWithHeaderAndParagraph(ret ? "Route added" : "Route not added");
1228 }
1229
1230 HtmlTag WebClient::HtmlTagMatchKeyProtocolLoco(const ControlID controlId,
1231 const string& selectedMatchKey,
1232 const Protocol selectedProtocol) const
1233 {
1234 HtmlTag content;
1235 map<string,LocoConfig> matchKeyMap = manager.GetUnmatchedLocosOfControl(controlId, selectedMatchKey);
1236 content.AddChildTag(WebClientStatic::HtmlTagMatchKey(matchKeyMap, selectedMatchKey));
1237 map<string,Protocol> protocolMap = manager.LocoProtocolsOfControl(controlId);
1238 content.AddChildTag(WebClientStatic::HtmlTagProtocol(protocolMap, selectedProtocol));
1239 return content;
1240 }
1241
1242 HtmlTag WebClient::HtmlTagMatchKeyProtocolAccessory(const ControlID controlId,
1243 const string& selectedMatchKey,
1244 const Protocol selectedProtocol) const
1245 {
1246 HtmlTag content;
1247 map<string,AccessoryConfig> matchKeyMap = manager.GetUnmatchedAccessoriesOfControl(controlId, selectedMatchKey);
1248 content.AddChildTag(WebClientStatic::HtmlTagMatchKey(matchKeyMap, selectedMatchKey));
1249 map<string,Protocol> protocolMap = manager.AccessoryProtocolsOfControl(controlId);
1250 content.AddChildTag(WebClientStatic::HtmlTagProtocol(protocolMap, selectedProtocol));
1251 return content;
1252 }
1253
1254 HtmlTag WebClient::HtmlTagMatchKeyFeedback(const ControlID controlId,
1255 const string& selectedMatchKey) const
1256 {
1257 HtmlTag content;
1258 map<string,FeedbackConfig> matchKeyMap = manager.GetUnmatchedFeedbacksOfControl(controlId, selectedMatchKey);
1259 content.AddChildTag(WebClientStatic::HtmlTagMatchKey(matchKeyMap, selectedMatchKey));
1260 return content;
1261 }
1262
1263 HtmlTag WebClient::HtmlTagProtocolAccessory(const ControlID controlID, const Protocol selectedProtocol)
1264 {
1265 map<string,Protocol> protocolMap = manager.AccessoryProtocolsOfControl(controlID);
1266 return WebClientStatic::HtmlTagProtocol(protocolMap, selectedProtocol);
1267 }
1268
1269 void WebClient::HandleProtocol(const map<string, string>& arguments)
1270 {
1271 ControlID controlId = Utils::Utils::GetIntegerMapEntry(arguments, "control", ControlIdNone);
1272 if (controlId == ControlIdNone)
1273 {
1274 ReplyHtmlWithHeaderAndParagraph(Languages::TextControlDoesNotExist);
1275 return;
1276 }
1277
1278 if (Utils::Utils::IsMapEntrySet(arguments, "loco"))
1279 {
1280 LocoID locoId = Utils::Utils::GetIntegerMapEntry(arguments, "loco", LocoNone);
1281 string matchKey;
1282 Protocol protocol = ProtocolNone;
1283 Loco* loco = manager.GetLoco(locoId);
1284 if (loco != nullptr)
1285 {
1286 matchKey = loco->GetMatchKey();
1287 protocol = loco->GetProtocol();
1288 }
1289 ReplyHtmlWithHeader(HtmlTagMatchKeyProtocolLoco(controlId, matchKey, protocol));
1290 return;
1291 }
1292 AccessoryID accessoryId = Utils::Utils::GetIntegerMapEntry(arguments, "accessory", AccessoryNone);
1293 if (accessoryId != AccessoryNone)
1294 {
1295 Accessory *accessory = manager.GetAccessory(accessoryId);
1296 ReplyHtmlWithHeader(HtmlTagProtocolAccessory(controlId, accessory == nullptr ? ProtocolNone : accessory->GetProtocol()));
1297 return;
1298 }
1299 SwitchID switchId = Utils::Utils::GetIntegerMapEntry(arguments, "switch", SwitchNone);
1300 if (switchId != SwitchNone)
1301 {
1302 Switch *mySwitch = manager.GetSwitch(switchId);
1303 ReplyHtmlWithHeader(HtmlTagProtocolAccessory(controlId, mySwitch == nullptr ? ProtocolNone : mySwitch->GetProtocol()));
1304 return;
1305 }
1306 SignalID signalId = Utils::Utils::GetIntegerMapEntry(arguments, "signal", SignalNone);
1307 if (signalId != SignalNone)
1308 {
1309 Signal *signal = manager.GetSignal(signalId);
1310 ReplyHtmlWithHeader(HtmlTagProtocolAccessory(controlId, signal == nullptr ? ProtocolNone : signal->GetProtocol()));
1311 return;
1312 }
1313
1314 ReplyHtmlWithHeader(HtmlTagProtocolAccessory(controlId, ProtocolNone));
1315 }
1316
1317 void WebClient::HandleAccessoryAddress(const map<string, string>& arguments)
1318 {
1319 const AccessoryType type = static_cast<AccessoryType>(Utils::Utils::GetIntegerMapEntry(arguments, "type", AccessoryTypeDefault));
1320 const Address address = static_cast<Address>(Utils::Utils::GetIntegerMapEntry(arguments, "address", AddressDefault));
1321 const AddressPort port = static_cast<AddressPort>(Utils::Utils::GetIntegerMapEntry(arguments, "port", AddressPortRed));
1322 ReplyHtmlWithHeader(WebClientStatic::HtmlTagAccessoryAddress(type, address, port));
1323 }
1324
1325 HtmlTag WebClient::HtmlTagPosition(const LayoutPosition posx,
1326 const LayoutPosition posy,
1327 const LayoutPosition posz) const
1328 {
1329 HtmlTag content("div");
1330 content.AddId("position");;
1331 content.AddChildTag(HtmlTagInputIntegerWithLabel("posx", Languages::TextPosX, Languages::TextHintPositionMove, posx, 0, 255));
1332 content.AddChildTag(HtmlTagInputIntegerWithLabel("posy", Languages::TextPosY, Languages::TextHintPositionMove, posy, 0, 255));
1333 map<string,LayerID> layerList = manager.LayerListByName();
1334 content.AddChildTag(HtmlTagSelectWithLabel("posz", Languages::TextPosZ, layerList, posz));
1335 return content;
1336 }
1337
1338 HtmlTag WebClient::HtmlTagPosition(const LayoutPosition posx,
1339 const LayoutPosition posy,
1340 const LayoutPosition posz,
1341 const Visible visible) const
1342 {
1343 HtmlTag content;
1344 HtmlTagInputCheckboxWithLabel checkboxVisible("visible", Languages::TextVisible, "visible", static_cast<bool>(visible));
1345 checkboxVisible.AddId("visible");
1346 checkboxVisible.AddAttribute("onchange", "onChangeCheckboxShowHide('visible', 'position');");
1347 content.AddChildTag(checkboxVisible);
1348 HtmlTag posDiv = HtmlTagPosition(posx, posy, posz);
1349 if (visible == DataModel::LayoutItem::VisibleNo)
1350 {
1351 posDiv.AddAttribute("hidden");
1352 }
1353 content.AddChildTag(posDiv);
1354 return content;
1355 }
1356
1357 HtmlTag WebClient::HtmlTagSelectSlave(const string& prefix,
1358 const vector<Relation*>& relations,
1359 const map<string,ObjectID>& options,
1360 const bool allowNew) const
1361 {
1362 HtmlTag content("div");
1363 content.AddId("tab_" + prefix + "s");
1364 content.AddClass("tab_content");
1365 content.AddClass("hidden");
1366
1367 HtmlTag div("div");
1368 div.AddChildTag(HtmlTagInputHidden(prefix + "counter", to_string(relations.size())));
1369 div.AddId(prefix + "s");
1370
1371 unsigned int counter = 1;
1372 for (auto relation : relations)
1373 {
1374 ObjectID objectID = relation->ObjectID2();
1375 div.AddChildTag(WebClientStatic::HtmlTagSlaveEntry(prefix, to_string(counter), objectID, options));
1376 ++counter;
1377 }
1378 div.AddChildTag(HtmlTag("div").AddId(prefix + "_new_" + to_string(counter)));
1379
1380 content.AddChildTag(div);
1381 if (allowNew)
1382 {
1383 HtmlTagButton newTrackButton(Languages::TextNew, "new" + prefix);
1384 newTrackButton.AddAttribute("onclick", "addSlave('" + prefix + "');return false;");
1385 newTrackButton.AddClass("wide_button");
1386 content.AddChildTag(newTrackButton);
1387 }
1388 content.AddChildTag(HtmlTag("br"));
1389 return content;
1390 }
1391
1392 HtmlTag WebClient::HtmlTagSelectFeedbackForTrack(const unsigned int counter,
1393 const TrackID trackID,
1394 const FeedbackID feedbackID) const
1395 {
1396 string counterString = to_string(counter);
1397 HtmlTag content("div");
1398 content.AddId("feedback_container_" + counterString);
1399 HtmlTagButton deleteButton(Languages::TextDelete, "delete_feedback_" + counterString);
1400 deleteButton.AddAttribute("onclick", "deleteElement('feedback_container_" + counterString + "');return false;");
1401 deleteButton.AddClass("wide_button");
1402 content.AddChildTag(deleteButton);
1403
1404 map<string, Feedback*> feedbacks = manager.FeedbackListByName();
1405 map<string, FeedbackID> feedbackOptions;
1406 for (auto& feedback : feedbacks)
1407 {
1408 const Track* track = feedback.second->GetTrack();
1409 if ((!track) || (track->GetID() != trackID))
1410 {
1411 continue;
1412 }
1413 feedbackOptions[feedback.first] = feedback.second->GetID();
1414 }
1415 content.AddChildTag(HtmlTagSelect("feedback_" + counterString, feedbackOptions, feedbackID));
1416 content.AddChildTag(HtmlTag("div").AddId("div_feedback_" + to_string(counter + 1)));
1417 return content;
1418 }
1419
1420 void WebClient::HandleSlaveAdd(const map<string, string>& arguments)
1421 {
1422 string priorityString = Utils::Utils::GetStringMapEntry(arguments, "priority", "1");
1423 Priority priority = Utils::Integer::StringToInteger(priorityString, 1);
1424 string prefix = Utils::Utils::GetStringMapEntry(arguments, "prefix");
1425 HtmlTag container;
1426 std::map<std::string,ObjectID> options;
1427 if (prefix.compare("track") == 0)
1428 {
1429 options = cluster.GetTrackOptions();
1430 }
1431 else if (prefix.compare("feedback") == 0)
1432 {
1433 options = track.GetFeedbackOptions();
1434 }
1435 else if (prefix.compare("signal") == 0)
1436 {
1437 options = track.GetSignalOptions();
1438 }
1439 else if (prefix.compare("slave") == 0)
1440 {
1441 options = GetMultipleUnitSlaveOptions();
1442 }
1443 container.AddChildTag(WebClientStatic::HtmlTagSlaveEntry(prefix, priorityString, ObjectNone, options));
1444 container.AddChildTag(HtmlTag("div").AddId(prefix + "_new_" + to_string(priority + 1)));
1445 ReplyHtmlWithHeader(container);
1446 }
1447
1448 void WebClient::HandleFeedbackAdd(const map<string, string>& arguments)
1449 {
1450 const unsigned int counter = Utils::Utils::GetIntegerMapEntry(arguments, "counter", 1);
1451 const TrackID trackID = Utils::Utils::GetIntegerMapEntry(arguments, "track", TrackNone);
1452 ReplyHtmlWithHeader(HtmlTagSelectFeedbackForTrack(counter, trackID));
1453 }
1454
1455 map<string,ObjectID> WebClient::GetMultipleUnitSlaveOptions() const
1456 {
1457 map<string, ObjectID> options;
1458
1459 map<string, LocoConfig> allLocos = manager.LocoConfigByName();
1460 for (auto& loco : allLocos)
1461 {
1462 options[loco.first] = loco.second.GetLocoId();
1463 }
1464 return options;
1465 }
1466
1467 void WebClient::HandleLocoEdit(const map<string, string>& arguments)
1468 {
1469 HtmlTag content;
1470 const LocoID locoId = Utils::Utils::GetIntegerMapEntry(arguments, "loco", LocoNone);
1471 ControlID controlId = Utils::Utils::GetIntegerMapEntry(arguments, "control", ControlNone);
1472 if (controlId == ControlNone)
1473 {
1474 controlId = manager.GetPossibleControlForLoco();
1475 }
1476 string matchKey = Utils::Utils::GetStringMapEntry(arguments, "matchkey");
1477 Protocol protocol = ProtocolNone;
1478 Address address = AddressDefault;
1479 Address serverAddress = AddressNone;
1480 string name = Languages::GetText(Languages::TextNew);
1481 bool pushpull = false;
1482 Length length = 0;
1483 Speed maxSpeed = MaxSpeed;
1484 Speed travelSpeed = DefaultTravelSpeed;
1485 Speed reducedSpeed = DefaultReducedSpeed;
1486 Speed creepingSpeed = DefaultCreepingSpeed;
1487 Propulsion propulsion = PropulsionOther;
1488 TrainType trainType = TrainTypeOther;
1489 LocoFunctionEntry locoFunctions[NumberOfLocoFunctions];
1490 vector<Relation*> slaves;
1491
1492 if (locoId > LocoNone)
1493 {
1494 // existing loco
1495 const DataModel::Loco* loco = manager.GetLoco(locoId);
1496 if (loco != nullptr)
1497 {
1498 controlId = loco->GetControlID();
1499 matchKey = loco->GetMatchKey();
1500 protocol = loco->GetProtocol();
1501 address = loco->GetAddress();
1502 serverAddress = loco->GetServerAddress();
1503 name = loco->GetName();
1504 pushpull = loco->GetPushpull();
1505 length = loco->GetLength();
1506 maxSpeed = loco->GetMaxSpeed();
1507 travelSpeed = loco->GetTravelSpeed();
1508 reducedSpeed = loco->GetReducedSpeed();
1509 creepingSpeed = loco->GetCreepingSpeed();
1510 propulsion = loco->GetPropulsion();
1511 trainType = loco->GetTrainType();
1512 loco->GetFunctions(locoFunctions);
1513 }
1514 }
1515 else if (controlId > ControlNone)
1516 {
1517 // loco from hardware database
1518 DataModel::LocoConfig loco = manager.GetLocoOfConfigByMatchKey(controlId, matchKey);
1519
1520 if ((loco.GetControlId() == controlId) && (loco.GetMatchKey() == matchKey))
1521 {
1522 protocol = loco.GetProtocol();
1523 address = loco.GetAddress();
1524 name = loco.GetName();
1525 loco.GetFunctions(locoFunctions);
1526 }
1527 }
1528 // else new loco
1529
1530 content.AddChildTag(HtmlTag("h1").AddContent(name).AddId("popup_title"));
1531 HtmlTag tabMenu("div");
1532 tabMenu.AddChildTag(WebClientStatic::HtmlTagTabMenuItem("basic", Languages::TextBasic, true));
1533 tabMenu.AddChildTag(WebClientStatic::HtmlTagTabMenuItem("functions", Languages::TextFunctions));
1534 tabMenu.AddChildTag(WebClientStatic::HtmlTagTabMenuItem("automode", Languages::TextAutomode));
1535 content.AddChildTag(tabMenu);
1536
1537 HtmlTag formContent("form");
1538 formContent.AddId("editform");
1539 formContent.AddChildTag(HtmlTagInputHidden("cmd", "locosave"));
1540 formContent.AddChildTag(HtmlTagInputHidden("loco", to_string(locoId)));
1541
1542 HtmlTag basicContent("div");
1543 basicContent.AddId("tab_basic");
1544 basicContent.AddClass("tab_content");
1545 basicContent.AddChildTag(HtmlTagInputTextWithLabel("name", Languages::TextName, name).AddAttribute("onkeyup", "updateName();"));
1546 basicContent.AddChildTag(HtmlTagControlLoco(controlId, "loco", locoId));
1547 basicContent.AddChildTag(HtmlTag("div").AddId("select_protocol").AddChildTag(HtmlTagMatchKeyProtocolLoco(controlId, matchKey, protocol)));
1548 basicContent.AddChildTag(HtmlTagInputIntegerWithLabel("address", Languages::TextAddress, address, 1, 9999));
1549 if (manager.IsServerEnabled())
1550 {
1551 basicContent.AddChildTag(HtmlTagInputIntegerWithLabel("serveraddress", Languages::TextServerAddress, serverAddress, 0, 9999));
1552 }
1553 basicContent.AddChildTag(HtmlTagInputIntegerWithLabel("length", Languages::TextTrainLength, length, 0, 99999));
1554 basicContent.AddChildTag(WebClientStatic::HtmlTagSelectPropulsion(propulsion));
1555 basicContent.AddChildTag(WebClientStatic::HtmlTagSelectTrainType(trainType));
1556 formContent.AddChildTag(basicContent);
1557
1558 formContent.AddChildTag(WebClientStatic::HtmlTagTabFunctions(locoFunctions));
1559
1560 formContent.AddChildTag(WebClientStatic::HtmlTagTabAutomode(pushpull, maxSpeed, travelSpeed, reducedSpeed, creepingSpeed));
1561
1562 content.AddChildTag(HtmlTag("div").AddClass("popup_content").AddChildTag(formContent));
1563 content.AddChildTag(HtmlTagButtonCancel());
1564 content.AddChildTag(HtmlTagButtonOK());
1565 ReplyHtmlWithHeader(content);
1566 }
1567
1568 void WebClient::HandleMultipleUnitEdit(const map<string, string>& arguments)
1569 {
1570 HtmlTag content;
1571 const MultipleUnitID multipleUnitId = Utils::Utils::GetIntegerMapEntry(arguments, "multipleunit", MultipleUnitNone);
1572 ControlID controlId = Utils::Utils::GetIntegerMapEntry(arguments, "control", ControlNone);
1573 string matchKey = Utils::Utils::GetStringMapEntry(arguments, "matchkey");
1574 string name = Languages::GetText(Languages::TextNew);
1575 bool pushpull = false;
1576 Address serverAddress = AddressNone;
1577 Length length = 0;
1578 Speed maxSpeed = MaxSpeed;
1579 Speed travelSpeed = DefaultTravelSpeed;
1580 Speed reducedSpeed = DefaultReducedSpeed;
1581 Speed creepingSpeed = DefaultCreepingSpeed;
1582 TrainType trainType = TrainTypeOther;
1583 LocoFunctionEntry locoFunctions[NumberOfLocoFunctions];
1584 vector<Relation*> slaves;
1585
1586 if (multipleUnitId > MultipleUnitNone)
1587 {
1588 // existing multiple unit
1589 const DataModel::MultipleUnit* multipleUnit = manager.GetMultipleUnit(multipleUnitId);
1590 if (multipleUnit != nullptr)
1591 {
1592 controlId = multipleUnit->GetControlID();
1593 matchKey = multipleUnit->GetMatchKey();
1594 name = multipleUnit->GetName();
1595 pushpull = multipleUnit->GetPushpull();
1596 serverAddress = multipleUnit->GetServerAddress();
1597 length = multipleUnit->GetLength();
1598 maxSpeed = multipleUnit->GetMaxSpeed();
1599 travelSpeed = multipleUnit->GetTravelSpeed();
1600 reducedSpeed = multipleUnit->GetReducedSpeed();
1601 creepingSpeed = multipleUnit->GetCreepingSpeed();
1602 trainType = multipleUnit->GetTrainType();
1603 multipleUnit->GetFunctions(locoFunctions);
1604 slaves = multipleUnit->GetSlaves();
1605 }
1606 }
1607 else if (controlId > ControlNone)
1608 {
1609 // multiple unit from hardware database
1610 DataModel::LocoConfig multipleUnit = manager.GetMultipleUnitOfConfigByMatchKey(controlId, matchKey);
1611
1612 if ((multipleUnit.GetControlId() == controlId) && (multipleUnit.GetMatchKey() == matchKey))
1613 {
1614 name = multipleUnit.GetName();
1615 multipleUnit.GetFunctions(locoFunctions);
1616 slaves = WebClientStatic::ConvertSlaveIDVectorToRelation(manager, multipleUnitId, multipleUnit.GetSlaves());
1617 }
1618 }
1619 // else new multiple unit
1620
1621 content.AddChildTag(HtmlTag("h1").AddContent(name).AddId("popup_title"));
1622 HtmlTag tabMenu("div");
1623 tabMenu.AddChildTag(WebClientStatic::HtmlTagTabMenuItem("basic", Languages::TextBasic, true));
1624 tabMenu.AddChildTag(WebClientStatic::HtmlTagTabMenuItem("functions", Languages::TextFunctions));
1625 tabMenu.AddChildTag(WebClientStatic::HtmlTagTabMenuItem("slaves", Languages::TextMultipleUnit));
1626 tabMenu.AddChildTag(WebClientStatic::HtmlTagTabMenuItem("automode", Languages::TextAutomode));
1627 content.AddChildTag(tabMenu);
1628
1629 HtmlTag formContent("form");
1630 formContent.AddId("editform");
1631 formContent.AddChildTag(HtmlTagInputHidden("cmd", "multipleunitsave"));
1632 formContent.AddChildTag(HtmlTagInputHidden("multipleunit", to_string(multipleUnitId)));
1633
1634 HtmlTag basicContent("div");
1635 basicContent.AddId("tab_basic");
1636 basicContent.AddClass("tab_content");
1637 basicContent.AddChildTag(HtmlTagInputTextWithLabel("name", Languages::TextName, name).AddAttribute("onkeyup", "updateName();"));
1638 basicContent.AddChildTag(HtmlTagControlMultipleUnit(controlId, "multipleunit", multipleUnitId));
1639 if (manager.IsServerEnabled())
1640 {
1641 basicContent.AddChildTag(HtmlTagInputIntegerWithLabel("serveraddress", Languages::TextServerAddress, serverAddress, 0, 9999));
1642 }
1643 basicContent.AddChildTag(HtmlTagInputIntegerWithLabel("length", Languages::TextTrainLength, length, 0, 99999));
1644
1645 basicContent.AddChildTag(WebClientStatic::HtmlTagSelectTrainType(trainType));
1646 formContent.AddChildTag(basicContent);
1647
1648 formContent.AddChildTag(WebClientStatic::HtmlTagTabFunctions(locoFunctions));
1649
1650 formContent.AddChildTag(HtmlTagSelectSlave("slave", slaves, GetMultipleUnitSlaveOptions()));
1651
1652 formContent.AddChildTag(WebClientStatic::HtmlTagTabAutomode(pushpull, maxSpeed, travelSpeed, reducedSpeed, creepingSpeed));
1653
1654 content.AddChildTag(HtmlTag("div").AddClass("popup_content").AddChildTag(formContent));
1655 content.AddChildTag(HtmlTagButtonCancel());
1656 content.AddChildTag(HtmlTagButtonOK());
1657 ReplyHtmlWithHeader(content);
1658 }
1659
1660 void WebClient::HandleLocoSave(const map<string, string>& arguments)
1661 {
1662 const LocoID locoId = Utils::Utils::GetIntegerMapEntry(arguments, "loco", LocoNone);
1663 const string name = Utils::Utils::GetStringMapEntry(arguments, "name", Languages::GetText(Languages::TextLoco));
1664 const ControlID controlId = Utils::Utils::GetIntegerMapEntry(arguments, "control", ControlIdNone);
1665 const string matchKey = Utils::Utils::GetStringMapEntry(arguments, "matchkey");
1666 const Protocol protocol = static_cast<Protocol>(Utils::Utils::GetIntegerMapEntry(arguments, "protocol", ProtocolNone));
1667 const Address address = Utils::Utils::GetIntegerMapEntry(arguments, "address", AddressDefault);
1668 const Address serverAddress = Utils::Utils::GetIntegerMapEntry(arguments, "serveraddress", AddressNone);
1669 const Length length = Utils::Utils::GetIntegerMapEntry(arguments, "length", 0);
1670 const bool pushpull = Utils::Utils::GetBoolMapEntry(arguments, "pushpull", false);
1671 const Speed maxSpeed = Utils::Utils::GetIntegerMapEntry(arguments, "maxspeed", MaxSpeed);
1672 Speed travelSpeed = Utils::Utils::GetIntegerMapEntry(arguments, "travelspeed", DefaultTravelSpeed);
1673 if (travelSpeed > maxSpeed)
1674 {
1675 travelSpeed = maxSpeed;
1676 }
1677 Speed reducedSpeed = Utils::Utils::GetIntegerMapEntry(arguments, "reducedspeed", DefaultReducedSpeed);
1678 if (reducedSpeed > travelSpeed)
1679 {
1680 reducedSpeed = travelSpeed;
1681 }
1682 Speed creepingSpeed = Utils::Utils::GetIntegerMapEntry(arguments, "creepingspeed", DefaultCreepingSpeed);
1683 if (creepingSpeed > reducedSpeed)
1684 {
1685 creepingSpeed = reducedSpeed;
1686 }
1687 const Propulsion propulsion = static_cast<Propulsion>(Utils::Utils::GetIntegerMapEntry(arguments, "propulsion", PropulsionOther));
1688 const TrainType type = static_cast<TrainType>(Utils::Utils::GetIntegerMapEntry(arguments, "type", TrainTypeOther));
1689
1690 vector<DataModel::LocoFunctionEntry> locoFunctions;
1691 DataModel::LocoFunctionEntry locoFunctionEntry;
1692 for (DataModel::LocoFunctionNr nr = 0; nr < NumberOfLocoFunctions; ++nr)
1693 {
1694 string nrString = "f" + to_string(nr) + "_";
1695 locoFunctionEntry.nr = nr;
1696 locoFunctionEntry.type = static_cast<DataModel::LocoFunctionType>(Utils::Utils::GetIntegerMapEntry(arguments, nrString + "type", DataModel::LocoFunctionTypeNone));
1697 if (locoFunctionEntry.type == DataModel::LocoFunctionTypeNone)
1698 {
1699 continue;
1700 }
1701 locoFunctionEntry.icon = static_cast<DataModel::LocoFunctionIcon>(Utils::Utils::GetIntegerMapEntry(arguments, nrString + "icon", DataModel::LocoFunctionIconNone));
1702 if (locoFunctionEntry.type == DataModel::LocoFunctionTypeTimer)
1703 {
1704 locoFunctionEntry.timer = Utils::Utils::GetIntegerMapEntry(arguments, nrString + "timer", 1);
1705 if (locoFunctionEntry.timer == 0)
1706 {
1707 locoFunctionEntry.timer = 1;
1708 }
1709 }
1710 else
1711 {
1712 locoFunctionEntry.timer = 0;
1713 }
1714 locoFunctions.push_back(locoFunctionEntry);
1715 }
1716
1717 string result;
1718
1719 if (!manager.LocoSave(locoId,
1720 name,
1721 controlId,
1722 matchKey,
1723 protocol,
1724 address,
1725 serverAddress,
1726 length,
1727 pushpull,
1728 maxSpeed,
1729 travelSpeed,
1730 reducedSpeed,
1731 creepingSpeed,
1732 propulsion,
1733 type,
1734 locoFunctions,
1735 result))
1736 {
1737 ReplyResponse(ResponseError, result);
1738 return;
1739 }
1740
1741 ReplyResponse(ResponseInfo, Languages::TextLocoSaved, name);
1742 }
1743
1744 void WebClient::HandleMultipleUnitSave(__attribute__((unused)) const map<string, string>& arguments)
1745 {
1746 const MultipleUnitID multipleUnitId = Utils::Utils::GetIntegerMapEntry(arguments, "multipleunit", MultipleUnitNone);
1747 const string name = Utils::Utils::GetStringMapEntry(arguments, "name");
1748 const ControlID controlId = Utils::Utils::GetIntegerMapEntry(arguments, "control", ControlIdNone);
1749 const string matchKey = Utils::Utils::GetStringMapEntry(arguments, "matchkey");
1750 const Address address = Utils::Utils::GetIntegerMapEntry(arguments, "address", AddressDefault);
1751 const Address serverAddress = Utils::Utils::GetIntegerMapEntry(arguments, "serveraddress", AddressNone);
1752 const Length length = Utils::Utils::GetIntegerMapEntry(arguments, "length", 0);
1753 const bool pushpull = Utils::Utils::GetBoolMapEntry(arguments, "pushpull", false);
1754 const Speed maxSpeed = Utils::Utils::GetIntegerMapEntry(arguments, "maxspeed", MaxSpeed);
1755 Speed travelSpeed = Utils::Utils::GetIntegerMapEntry(arguments, "travelspeed", DefaultTravelSpeed);
1756 if (travelSpeed > maxSpeed)
1757 {
1758 travelSpeed = maxSpeed;
1759 }
1760 Speed reducedSpeed = Utils::Utils::GetIntegerMapEntry(arguments, "reducedspeed", DefaultReducedSpeed);
1761 if (reducedSpeed > travelSpeed)
1762 {
1763 reducedSpeed = travelSpeed;
1764 }
1765 Speed creepingSpeed = Utils::Utils::GetIntegerMapEntry(arguments, "creepingspeed", DefaultCreepingSpeed);
1766 if (creepingSpeed > reducedSpeed)
1767 {
1768 creepingSpeed = reducedSpeed;
1769 }
1770 const TrainType type = static_cast<TrainType>(Utils::Utils::GetIntegerMapEntry(arguments, "type", TrainTypeOther));
1771
1772 vector<DataModel::LocoFunctionEntry> locoFunctions;
1773 DataModel::LocoFunctionEntry locoFunctionEntry;
1774 for (DataModel::LocoFunctionNr nr = 0; nr < NumberOfLocoFunctions; ++nr)
1775 {
1776 string nrString = "f" + to_string(nr) + "_";
1777 locoFunctionEntry.nr = nr;
1778 locoFunctionEntry.type = static_cast<DataModel::LocoFunctionType>(Utils::Utils::GetIntegerMapEntry(arguments, nrString + "type", DataModel::LocoFunctionTypeNone));
1779 if (locoFunctionEntry.type == DataModel::LocoFunctionTypeNone)
1780 {
1781 continue;
1782 }
1783 locoFunctionEntry.icon = static_cast<DataModel::LocoFunctionIcon>(Utils::Utils::GetIntegerMapEntry(arguments, nrString + "icon", DataModel::LocoFunctionIconNone));
1784 if (locoFunctionEntry.type == DataModel::LocoFunctionTypeTimer)
1785 {
1786 locoFunctionEntry.timer = Utils::Utils::GetIntegerMapEntry(arguments, nrString + "timer", 1);
1787 if (locoFunctionEntry.timer == 0)
1788 {
1789 locoFunctionEntry.timer = 1;
1790 }
1791 }
1792 else
1793 {
1794 locoFunctionEntry.timer = 0;
1795 }
1796 locoFunctions.push_back(locoFunctionEntry);
1797 }
1798
1799 vector<LocoID> slaveIDs = WebClientStatic::InterpretSlaveData("slave", arguments);
1800 vector<Relation*> slaves = WebClientStatic::ConvertSlaveIDVectorToRelation(manager, multipleUnitId, slaveIDs);
1801
1802 string result;
1803
1804 if (!manager.MultipleUnitSave(multipleUnitId,
1805 name,
1806 controlId,
1807 matchKey,
1808 address,
1809 serverAddress,
1810 length,
1811 pushpull,
1812 maxSpeed,
1813 travelSpeed,
1814 reducedSpeed,
1815 creepingSpeed,
1816 type,
1817 locoFunctions,
1818 slaves,
1819 result))
1820 {
1821 ReplyResponse(ResponseError, result);
1822 return;
1823 }
1824
1825 ReplyResponse(ResponseInfo, Languages::TextMultipleUnitSaved, name);
1826 }
1827
1828 void WebClient::HandleLocoList()
1829 {
1830 HtmlTag content;
1831 content.AddChildTag(HtmlTag("h1").AddContent(Languages::TextLocos));
1832 HtmlTag table("table");
1833 const map<string,LocoConfig> locoList = manager.LocoConfigByName();
1834 map<string,string> locoArgument;
1835 for (auto& loco : locoList)
1836 {
1837 const LocoConfig& locoConfig = loco.second;
1838 HtmlTag row("tr");
1839 row.AddChildTag(HtmlTag("td").AddContent(loco.first));
1840 row.AddChildTag(HtmlTag("td").AddContent(ProtocolName(locoConfig.GetProtocol())));
1841 row.AddChildTag(HtmlTag("td").AddContent(to_string(locoConfig.GetAddress())));
1842 const LocoID locoId = locoConfig.GetLocoId();
1843 const string& locoIdString = to_string(locoId);
1844 locoArgument["loco"] = locoIdString;
1845 if (locoId == LocoNone)
1846 {
1847 locoArgument["control"] = to_string(locoConfig.GetControlId());
1848 locoArgument["matchkey"] = locoConfig.GetMatchKey();
1849 row.AddChildTag(HtmlTag("td").AddChildTag(HtmlTagButtonPopupWide(Languages::TextImport, "locoedit_list_0", locoArgument)));
1850 row.AddChildTag(HtmlTag("td").AddContent("&nbsp;"));
1851 row.AddChildTag(HtmlTag("td").AddContent("&nbsp;"));
1852 }
1853 else
1854 {
1855 row.AddChildTag(HtmlTag("td").AddChildTag(HtmlTagButtonPopupWide(Languages::TextEdit, "locoedit_list_" + locoIdString, locoArgument)));
1856 row.AddChildTag(HtmlTag("td").AddChildTag(HtmlTagButtonPopupWide(Languages::TextDelete, "locoaskdelete_" + locoIdString, locoArgument)));
1857 if (loco.second.IsInUse())
1858 {
1859 row.AddChildTag(HtmlTag("td").AddChildTag(HtmlTagButtonCommandWide(Languages::TextRelease, "locorelease_" + locoIdString, locoArgument, "hideElement('b_locorelease_" + locoIdString + "');")));
1860 }
1861 else
1862 {
1863 row.AddChildTag(HtmlTag("td").AddContent("&nbsp;"));
1864 }
1865 }
1866 table.AddChildTag(row);
1867 }
1868 content.AddChildTag(HtmlTag("div").AddClass("popup_content").AddChildTag(table));
1869 content.AddChildTag(HtmlTagButtonCancel());
1870 content.AddChildTag(HtmlTagButtonPopupWide(Languages::TextNew, "locoedit_0"));
1871 ReplyHtmlWithHeader(content);
1872 }
1873
1874 void WebClient::HandleMultipleUnitList()
1875 {
1876 HtmlTag content;
1877 content.AddChildTag(HtmlTag("h1").AddContent(Languages::TextMultipleUnits));
1878 HtmlTag table("table");
1879 const map<string,LocoConfig> multipleUnitList = manager.MultipleUnitConfigByName();
1880 map<string,string> multipleUnitArgument;
1881 for (auto& multipleUnit : multipleUnitList)
1882 {
1883 const LocoConfig& locoConfig = multipleUnit.second;
1884 HtmlTag row("tr");
1885 row.AddChildTag(HtmlTag("td").AddContent(multipleUnit.first));
1886 const MultipleUnitID multipleUnitId = locoConfig.GetLocoId();
1887 const string& multipleUnitIdString = to_string(multipleUnitId);
1888 multipleUnitArgument["multipleunit"] = multipleUnitIdString;
1889 if (multipleUnitId == LocoNone)
1890 {
1891 multipleUnitArgument["control"] = to_string(locoConfig.GetControlId());
1892 multipleUnitArgument["matchkey"] = locoConfig.GetMatchKey();
1893 row.AddChildTag(HtmlTag("td").AddChildTag(HtmlTagButtonPopupWide(Languages::TextImport, "multipleunitedit_list_" + multipleUnitIdString, multipleUnitArgument)));
1894 row.AddChildTag(HtmlTag("td").AddContent("&nbsp;"));
1895 row.AddChildTag(HtmlTag("td").AddContent("&nbsp;"));
1896 }
1897 else
1898 {
1899 row.AddChildTag(HtmlTag("td").AddChildTag(HtmlTagButtonPopupWide(Languages::TextEdit, "multipleunitedit_list_" + multipleUnitIdString, multipleUnitArgument)));
1900 row.AddChildTag(HtmlTag("td").AddChildTag(HtmlTagButtonPopupWide(Languages::TextDelete, "multipleunitaskdelete_" + multipleUnitIdString, multipleUnitArgument)));
1901 if (multipleUnit.second.IsInUse())
1902 {
1903 row.AddChildTag(HtmlTag("td").AddChildTag(HtmlTagButtonCommandWide(Languages::TextRelease, "multipleunitrelease_" + multipleUnitIdString, multipleUnitArgument, "hideElement('b_locorelease_" + multipleUnitIdString + "');")));
1904 }
1905 else
1906 {
1907 row.AddChildTag(HtmlTag("td").AddContent("&nbsp;"));
1908 }
1909 }
1910 table.AddChildTag(row);
1911 }
1912 content.AddChildTag(HtmlTag("div").AddClass("popup_content").AddChildTag(table));
1913 content.AddChildTag(HtmlTagButtonCancel());
1914 content.AddChildTag(HtmlTagButtonPopupWide(Languages::TextNew, "multipleunitedit_0"));
1915 ReplyHtmlWithHeader(content);
1916 }
1917
1918 void WebClient::HandleLocoAskDelete(const map<string, string>& arguments)
1919 {
1920 LocoID locoID = Utils::Utils::GetIntegerMapEntry(arguments, "loco", LocoNone);
1921
1922 if (locoID == LocoNone)
1923 {
1924 ReplyHtmlWithHeaderAndParagraph(Languages::TextLocoDoesNotExist);
1925 return;
1926 }
1927
1928 const DataModel::Loco* loco = manager.GetLoco(locoID);
1929 if (loco == nullptr)
1930 {
1931 ReplyHtmlWithHeaderAndParagraph(Languages::TextLocoDoesNotExist);
1932 return;
1933 }
1934
1935 HtmlTag content;
1936 const string& locoName = loco->GetName();
1937 content.AddContent(HtmlTag("h1").AddContent(Languages::TextDeleteLoco));
1938 content.AddContent(HtmlTag("p").AddContent(Languages::TextAreYouSureToDelete, locoName));
1939 content.AddContent(HtmlTag("form").AddId("editform")
1940 .AddContent(HtmlTagInputHidden("cmd", "locodelete"))
1941 .AddContent(HtmlTagInputHidden("loco", to_string(locoID))
1942 ));
1943 content.AddContent(HtmlTagButtonCancel());
1944 content.AddContent(HtmlTagButtonOK());
1945 ReplyHtmlWithHeader(content);
1946 }
1947
1948 void WebClient::HandleMultipleUnitAskDelete(const map<string, string>& arguments)
1949 {
1950 MultipleUnitID multipleUnitID = Utils::Utils::GetIntegerMapEntry(arguments, "multipleunit", MultipleUnitNone);
1951
1952 if (multipleUnitID == MultipleUnitNone)
1953 {
1954 ReplyHtmlWithHeaderAndParagraph(Languages::TextMultipleUnitDoesNotExist);
1955 return;
1956 }
1957
1958 const DataModel::MultipleUnit* multipleUnit = manager.GetMultipleUnit(multipleUnitID);
1959 if (multipleUnit == nullptr)
1960 {
1961 ReplyHtmlWithHeaderAndParagraph(Languages::TextMultipleUnitDoesNotExist);
1962 return;
1963 }
1964
1965 HtmlTag content;
1966 const string& multipleUnitName = multipleUnit->GetName();
1967 content.AddContent(HtmlTag("h1").AddContent(Languages::TextDeleteMultipleUnit));
1968 content.AddContent(HtmlTag("p").AddContent(Languages::TextAreYouSureToDelete, multipleUnitName));
1969 content.AddContent(HtmlTag("form").AddId("editform")
1970 .AddContent(HtmlTagInputHidden("cmd", "multipleunitdelete"))
1971 .AddContent(HtmlTagInputHidden("multipleunit", to_string(multipleUnitID))
1972 ));
1973 content.AddContent(HtmlTagButtonCancel());
1974 content.AddContent(HtmlTagButtonOK());
1975 ReplyHtmlWithHeader(content);
1976 }
1977
1978 void WebClient::HandleLocoDelete(const map<string, string>& arguments)
1979 {
1980 LocoID locoID = Utils::Utils::GetIntegerMapEntry(arguments, "loco", LocoNone);
1981 const DataModel::Loco* loco = manager.GetLoco(locoID);
1982 if (loco == nullptr)
1983 {
1984 ReplyResponse(ResponseError, Languages::TextLocoDoesNotExist);
1985 return;
1986 }
1987
1988 string name = loco->GetName();
1989 string result;
1990 if (!manager.LocoDelete(locoID, result))
1991 {
1992 ReplyResponse(ResponseError, result);
1993 return;
1994 }
1995
1996 ReplyResponse(ResponseInfo, Languages::TextLocoDeleted, name);
1997 }
1998
1999 void WebClient::HandleMultipleUnitDelete(const map<string, string>& arguments)
2000 {
2001 MultipleUnitID multipleUnitID = Utils::Utils::GetIntegerMapEntry(arguments, "multipleunit", MultipleUnitNone);
2002 const DataModel::MultipleUnit* multipleUnit = manager.GetMultipleUnit(multipleUnitID);
2003 if (multipleUnit == nullptr)
2004 {
2005 ReplyResponse(ResponseError, Languages::TextMultipleUnitDoesNotExist);
2006 return;
2007 }
2008
2009 string name = multipleUnit->GetName();
2010 string result;
2011 if (!manager.MultipleUnitDelete(multipleUnitID, result))
2012 {
2013 ReplyResponse(ResponseError, result);
2014 return;
2015 }
2016
2017 ReplyResponse(ResponseInfo, Languages::TextMultipleUnitDeleted, name);
2018 }
2019
2020 HtmlTag WebClient::HtmlTagLayerSelector(const LayerID layerID) const
2021 {
2022 map<string,LayerID> options = manager.LayerListByNameWithFeedback();
2023 return HtmlTagSelect("layer", options, layerID).AddAttribute("onchange", "loadLayout();");
2024 }
2025
2026 void WebClient::HandleLayout(const map<string, string>& arguments)
2027 {
2028 LayerID layer = static_cast<LayerID>(Utils::Utils::GetIntegerMapEntry(arguments, "layer", CHAR_MIN));
2029 HtmlTag content;
2030
2031 if (layer < LayerUndeletable)
2032 {
2033 const map<FeedbackID,Feedback*>& feedbacks = manager.FeedbackList();
2034 for (auto& feedback : feedbacks)
2035 {
2036 if (feedback.second->GetControlID() != -layer)
2037 {
2038 continue;
2039 }
2040
2041 content.AddChildTag(HtmlTagFeedback(feedback.second, true));
2042 }
2043 ReplyHtmlWithHeader(content);
2044 return;
2045 }
2046
2047 const map<TextID,DataModel::Text*>& texts = manager.TextList();
2048 for (auto& text : texts)
2049 {
2050 if (text.second->IsVisibleOnLayer(layer) == false)
2051 {
2052 continue;
2053 }
2054 content.AddChildTag(HtmlTagText(text.second));
2055 }
2056
2057 const map<SwitchID,DataModel::Track*>& tracks = manager.TrackList();
2058 for (auto& track : tracks)
2059 {
2060 if (track.second->IsVisibleOnLayer(layer) == false)
2061 {
2062 continue;
2063 }
2064 content.AddChildTag(HtmlTagTrack(manager, track.second));
2065 }
2066
2067 const map<SignalID,DataModel::Signal*>& signals = manager.SignalList();
2068 for (auto& signal : signals)
2069 {
2070 if (signal.second->IsVisibleOnLayer(layer) == false)
2071 {
2072 continue;
2073 }
2074 content.AddChildTag(HtmlTagSignal(manager, signal.second));
2075 }
2076
2077 const map<AccessoryID,DataModel::Accessory*>& accessories = manager.AccessoryList();
2078 for (auto& accessory : accessories)
2079 {
2080 if (accessory.second->IsVisibleOnLayer(layer) == false)
2081 {
2082 continue;
2083 }
2084 content.AddChildTag(HtmlTagAccessory(accessory.second));
2085 }
2086
2087 const map<SwitchID,DataModel::Switch*>& switches = manager.SwitchList();
2088 for (auto& mySwitch : switches)
2089 {
2090 if (mySwitch.second->IsVisibleOnLayer(layer) == false)
2091 {
2092 continue;
2093 }
2094 content.AddChildTag(HtmlTagSwitch(mySwitch.second));
2095 }
2096
2097 const map<FeedbackID,Feedback*>& feedbacks = manager.FeedbackList();
2098 for (auto& feedback : feedbacks)
2099 {
2100 if (feedback.second->IsVisibleOnLayer(layer) == false)
2101 {
2102 continue;
2103 }
2104 content.AddChildTag(HtmlTagFeedback(feedback.second));
2105 }
2106
2107 const map<RouteID,DataModel::Route*>& routes = manager.RouteList();
2108 for (auto& route : routes)
2109 {
2110 if (route.second->IsVisibleOnLayer(layer) == false)
2111 {
2112 continue;
2113 }
2114 content.AddChildTag(HtmlTagRoute(route.second));
2115 }
2116
2117 const map<CounterID,DataModel::Counter*>& counters = manager.CounterList();
2118 for (auto& counter : counters)
2119 {
2120 if (counter.second->IsVisibleOnLayer(layer) == false)
2121 {
2122 continue;
2123 }
2124 content.AddChildTag(HtmlTagCounter(counter.second));
2125 }
2126
2127 ReplyHtmlWithHeader(content);
2128 }
2129
2130 HtmlTag WebClient::HtmlTagControlLoco(ControlID& controlId, const string& objectType, const ObjectID objectID) const
2131 {
2132 std::map<ControlID,string> controls = manager.ControlListNames(Hardware::CapabilityLoco);
2133 return WebClientStatic::HtmlTagControl(controls, controlId, objectType, objectID);
2134 }
2135
2136 HtmlTag WebClient::HtmlTagControlMultipleUnit(ControlID& controlId, const string& objectType, const ObjectID objectID) const
2137 {
2138 std::map<ControlID,string> controls = manager.ControlListNames(Hardware::CapabilityMultipleUnit);
2139 controls[ControlNone] = Languages::GetText(Languages::TextIndependentOfControl);
2140 return WebClientStatic::HtmlTagControl(controls, controlId, objectType, objectID);
2141 }
2142
2143 HtmlTag WebClient::HtmlTagControlAccessory(ControlID& controlID, const string& objectType, const ObjectID objectID) const
2144 {
2145 std::map<ControlID,string> controls = manager.ControlListNames(Hardware::CapabilityAccessory);
2146 return WebClientStatic::HtmlTagControl(controls, controlID, objectType, objectID);
2147 }
2148
2149 HtmlTag WebClient::HtmlTagControlFeedback(ControlID& controlId, const string& objectType, const ObjectID objectID) const
2150 {
2151 std::map<ControlID,string> controls = manager.ControlListNames(Hardware::CapabilityFeedback);
2152 return WebClientStatic::HtmlTagControl(controls, controlId, objectType, objectID);
2153 }
2154
2155 void WebClient::HandleAccessoryEdit(const map<string, string>& arguments)
2156 {
2157 HtmlTag content;
2158 AccessoryID accessoryID = Utils::Utils::GetIntegerMapEntry(arguments, "accessory", AccessoryNone);
2159 string name = Languages::GetText(Languages::TextNew);
2160 ControlID controlId = Utils::Utils::GetIntegerMapEntry(arguments, "control", ControlNone);
2161 if (controlId == ControlNone)
2162 {
2163 controlId = manager.GetPossibleControlForAccessory();
2164 }
2165 string matchKey = Utils::Utils::GetStringMapEntry(arguments, "matchkey");
2166 Protocol protocol = ProtocolNone;
2167 Address address = AddressDefault;
2168 AddressPort port = AddressPortRed;
2169 Address serverAddress = AddressNone;
2170 DataModel::AccessoryType accessoryType = static_cast<DataModel::AccessoryType>(Utils::Utils::GetIntegerMapEntry(arguments, "accessorytype", AccessoryTypeDefault));
2171 DataModel::AccessoryType connectionType;
2172 LayoutPosition posx = Utils::Utils::GetIntegerMapEntry(arguments, "posx", 0);
2173 LayoutPosition posy = Utils::Utils::GetIntegerMapEntry(arguments, "posy", 0);
2174 LayoutPosition posz = Utils::Utils::GetIntegerMapEntry(arguments, "posz", LayerUndeletable);
2175 LayoutRotation rotation = Utils::Utils::GetIntegerMapEntry(arguments, "rotation", DataModel::LayoutItem::Rotation0);
2176 DataModel::AccessoryPulseDuration duration = manager.GetDefaultAccessoryDuration();
2177 bool inverted = false;
2178 if (accessoryID > AccessoryNone)
2179 {
2180 const DataModel::Accessory* accessory = manager.GetAccessory(accessoryID);
2181 if (accessory != nullptr)
2182 {
2183 name = accessory->GetName();
2184 controlId = accessory->GetControlID();
2185 matchKey = accessory->GetMatchKey();
2186 protocol = accessory->GetProtocol();
2187 address = accessory->GetAddress();
2188 port = accessory->GetPort();
2189 serverAddress = accessory->GetServerAddress();
2190 accessoryType = accessory->GetAccessoryType();
2191 posx = accessory->GetPosX();
2192 posy = accessory->GetPosY();
2193 posz = accessory->GetPosZ();
2194 rotation = accessory->GetRotation();
2195 duration = accessory->GetAccessoryPulseDuration();
2196 inverted = accessory->GetInverted();
2197 }
2198 }
2199 else if (controlId > ControlNone)
2200 {
2201 // accessory from hardware database
2202 const DataModel::AccessoryConfig accessory = manager.GetAccessoryOfConfigByMatchKey(controlId, matchKey);
2203 if (accessory.GetControlId() == controlId && accessory.GetMatchKey() == matchKey)
2204 {
2205 protocol = accessory.GetProtocol();
2206 address = accessory.GetAddress();
2207 name = accessory.GetName();
2208 }
2209 }
2210 // else new accessory
2211
2212 connectionType = static_cast<DataModel::AccessoryType>(accessoryType & DataModel::AccessoryTypeConnectionMask);
2213 accessoryType = static_cast<DataModel::AccessoryType>(accessoryType & DataModel::AccessoryTypeMask);
2214
2215 content.AddChildTag(HtmlTag("h1").AddContent(name).AddId("popup_title"));
2216 HtmlTag tabMenu("div");
2217 tabMenu.AddChildTag(WebClientStatic::HtmlTagTabMenuItem("main", Languages::TextBasic, true));
2218 tabMenu.AddChildTag(WebClientStatic::HtmlTagTabMenuItem("position", Languages::TextPosition));
2219 content.AddChildTag(tabMenu);
2220
2221 HtmlTag formContent;
2222 formContent.AddChildTag(HtmlTagInputHidden("cmd", "accessorysave"));
2223 formContent.AddChildTag(HtmlTagInputHidden("accessory", to_string(accessoryID)));
2224
2225 std::map<DataModel::AccessoryType, Languages::TextSelector> typeOptions;
2226 typeOptions[DataModel::AccessoryTypeDefault] = Languages::TextDefault;
2227 typeOptions[DataModel::AccessoryTypeStraight] = Languages::TextStraight;
2228 typeOptions[DataModel::AccessoryTypeTurn] = Languages::TextTurn;
2229 typeOptions[DataModel::AccessoryTypeDecoupler] = Languages::TextAccessoryTypeDecoupler;
2230 typeOptions[DataModel::AccessoryTypeLight] = Languages::TextAccessoryTypeLight;
2231 typeOptions[DataModel::AccessoryTypeLightInhouse] = Languages::TextAccessoryTypeLightInhouse;
2232 typeOptions[DataModel::AccessoryTypeLightStreet] = Languages::TextAccessoryTypeLightStreet;
2233
2234 std::map<DataModel::AccessoryType, Languages::TextSelector> connectionOptions;
2235 connectionOptions[DataModel::AccessoryTypeOnOn] = Languages::TextAccessoryTypeOnOn;
2236 connectionOptions[DataModel::AccessoryTypeOnPush] = Languages::TextAccessoryTypeOnPush;
2237 connectionOptions[DataModel::AccessoryTypeOnOff] = Languages::TextAccessoryTypeOnOff;
2238
2239 HtmlTag mainContent("div");
2240 mainContent.AddId("tab_main");
2241 mainContent.AddClass("tab_content");
2242 mainContent.AddChildTag(HtmlTagInputTextWithLabel("name", Languages::TextName, name).AddAttribute("onkeyup", "updateName();"));
2243 mainContent.AddChildTag(HtmlTagSelectWithLabel("accessorytype", Languages::TextType, typeOptions, static_cast<DataModel::AccessoryType>(accessoryType & DataModel::AccessoryTypeMask)));
2244 mainContent.AddChildTag(HtmlTagSelectWithLabel("connectiontype", Languages::TextConnection, Languages::TextConnectionHint, connectionOptions, connectionType).AddAttribute("onchange", "loadAccessoryAddress('" + to_string(accessoryID) + "')"));
2245 mainContent.AddChildTag(HtmlTagControlAccessory(controlId, "accessory", accessoryID));
2246 mainContent.AddChildTag(HtmlTag("div").AddId("select_protocol").AddChildTag(HtmlTagMatchKeyProtocolAccessory(controlId, matchKey, protocol)));
2247 mainContent.AddChildTag(HtmlTag("div").AddId("select_address").AddChildTag(WebClientStatic::HtmlTagAccessoryAddress(connectionType, address, port)));
2248 mainContent.AddChildTag(WebClientStatic::HtmlTagDuration(duration));
2249 mainContent.AddChildTag(HtmlTagInputCheckboxWithLabel("inverted", Languages::TextInverted, "true", inverted));
2250 if (manager.IsServerEnabled())
2251 {
2252 mainContent.AddChildTag(HtmlTagInputIntegerWithLabel("serveraddress", Languages::TextServerAddress, serverAddress, 0, 2044));
2253 }
2254 formContent.AddChildTag(mainContent);
2255
2256 formContent.AddChildTag(HtmlTagTabPosition(posx, posy, posz, rotation));
2257
2258 content.AddChildTag(HtmlTag("div").AddClass("popup_content").AddChildTag(HtmlTag("form").AddId("editform").AddChildTag(formContent)));
2259 content.AddChildTag(HtmlTagButtonCancel());
2260 content.AddChildTag(HtmlTagButtonOK());
2261 ReplyHtmlWithHeader(content);
2262 }
2263
2264 void WebClient::HandleAccessoryGet(const map<string, string>& arguments)
2265 {
2266 AccessoryID accessoryID = Utils::Utils::GetIntegerMapEntry(arguments, "accessory");
2267 const DataModel::Accessory* accessory = manager.GetAccessory(accessoryID);
2268 if (accessory == nullptr)
2269 {
2270 ReplyHtmlWithHeader(HtmlTag());
2271 return;
2272 }
2273 ReplyHtmlWithHeader(HtmlTagAccessory(accessory));
2274 }
2275
2276 void WebClient::HandleAccessorySave(const map<string, string>& arguments)
2277 {
2278 const AccessoryID accessoryID = Utils::Utils::GetIntegerMapEntry(arguments, "accessory", AccessoryNone);
2279 const string name = Utils::Utils::GetStringMapEntry(arguments, "name");
2280 const ControlID controlId = Utils::Utils::GetIntegerMapEntry(arguments, "control", ControlIdNone);
2281 const string matchKey = Utils::Utils::GetStringMapEntry(arguments, "matchkey");
2282 const Protocol protocol = static_cast<Protocol>(Utils::Utils::GetIntegerMapEntry(arguments, "protocol", ProtocolNone));
2283 const Address address = Utils::Utils::GetIntegerMapEntry(arguments, "address", AddressDefault);
2284 const AddressPort port = static_cast<AddressPort>(Utils::Utils::GetIntegerMapEntry(arguments, "port", AddressPortRed));
2285 const Address serverAddress = Utils::Utils::GetIntegerMapEntry(arguments, "serveraddress", AddressNone);
2286 const DataModel::AccessoryType connectionType = static_cast<DataModel::AccessoryType>(Utils::Utils::GetIntegerMapEntry(arguments, "connectiontype", AccessoryTypeOnOn));
2287 const DataModel::AccessoryType accessoryType = static_cast<DataModel::AccessoryType>(Utils::Utils::GetIntegerMapEntry(arguments, "accessorytype", AccessoryTypeDefault) + connectionType);
2288 const LayoutPosition posX = Utils::Utils::GetIntegerMapEntry(arguments, "posx", 0);
2289 const LayoutPosition posY = Utils::Utils::GetIntegerMapEntry(arguments, "posy", 0);
2290 const LayoutPosition posZ = Utils::Utils::GetIntegerMapEntry(arguments, "posz", 0);
2291 const LayoutRotation rotation = Utils::Utils::GetIntegerMapEntry(arguments, "rotation", DataModel::LayoutItem::Rotation0);
2292 const DataModel::AccessoryPulseDuration duration = Utils::Utils::GetIntegerMapEntry(arguments, "duration", manager.GetDefaultAccessoryDuration());
2293 const bool inverted = Utils::Utils::GetBoolMapEntry(arguments, "inverted");
2294 string result;
2295 if (!manager.AccessorySave(accessoryID,
2296 name,
2297 posX,
2298 posY,
2299 posZ,
2300 rotation,
2301 controlId,
2302 matchKey,
2303 protocol,
2304 address,
2305 port,
2306 serverAddress,
2307 accessoryType,
2308 duration,
2309 inverted,
2310 result))
2311 {
2312 ReplyResponse(ResponseError, result);
2313 return;
2314 }
2315
2316 ReplyResponse(ResponseInfo, Languages::TextAccessorySaved, name);
2317 }
2318
2319 void WebClient::HandleAccessoryState(const map<string, string>& arguments)
2320 {
2321 const AccessoryID accessoryID = Utils::Utils::GetIntegerMapEntry(arguments, "accessory", AccessoryNone);
2322 const DataModel::AccessoryState accessoryState = (Utils::Utils::GetStringMapEntry(arguments, "state", "off").compare("off") == 0 ? DataModel::AccessoryStateOff : DataModel::AccessoryStateOn);
2323
2324 manager.AccessoryState(ControlTypeWebServer, accessoryID, accessoryState, false);
2325
2326 ReplyHtmlWithHeaderAndParagraph(accessoryState ? Languages::TextAccessoryStateIsGreen : Languages::TextAccessoryStateIsRed, manager.GetAccessoryName(accessoryID));
2327 }
2328
2329 void WebClient::HandleAccessoryList()
2330 {
2331 HtmlTag content;
2332 content.AddChildTag(HtmlTag("h1").AddContent(Languages::TextAccessories));
2333 HtmlTag table("table");
2334 const map<string,DataModel::AccessoryConfig> accessoryList = manager.AccessoryConfigByName();
2335 map<string,string> accessoryArgument;
2336 for (auto& accessory : accessoryList)
2337 {
2338 const AccessoryConfig& accessoryConfig = accessory.second;
2339 HtmlTag row("tr");
2340 row.AddChildTag(HtmlTag("td").AddContent(accessory.first));
2341 row.AddChildTag(HtmlTag("td").AddContent(ProtocolName(accessoryConfig.GetProtocol())));
2342 row.AddChildTag(HtmlTag("td").AddContent(to_string(accessoryConfig.GetAddress())));
2343 AccessoryID accessoryId = accessoryConfig.GetObjectIdentifier().GetObjectID();
2344 const string& accessoryIdString = to_string(accessoryId);
2345 accessoryArgument["accessory"] = accessoryIdString;
2346 if (accessoryId == AccessoryNone)
2347 {
2348 accessoryArgument["control"] = to_string(accessoryConfig.GetControlId());
2349 accessoryArgument["matchkey"] = accessoryConfig.GetMatchKey();
2350 row.AddChildTag(HtmlTag("td").AddChildTag(HtmlTagButtonPopupWide(Languages::TextImport, "accessoryedit_list_" + accessoryIdString, accessoryArgument)));
2351 }
2352 else
2353 {
2354 row.AddChildTag(HtmlTag("td").AddChildTag(HtmlTagButtonPopupWide(Languages::TextEdit, "accessoryedit_list_" + accessoryIdString, accessoryArgument)));
2355 row.AddChildTag(HtmlTag("td").AddChildTag(HtmlTagButtonPopupWide(Languages::TextDelete, "accessoryaskdelete_" + accessoryIdString, accessoryArgument)));
2356 if (accessoryConfig.IsInUse())
2357 {
2358 row.AddChildTag(HtmlTag("td").AddChildTag(HtmlTagButtonCommandWide(Languages::TextRelease, "accessoryrelease_" + accessoryIdString, accessoryArgument, "hideElement('b_accessoryrelease_" + accessoryIdString + "');")));
2359 }
2360 }
2361 table.AddChildTag(row);
2362 }
2363 content.AddChildTag(HtmlTag("div").AddClass("popup_content").AddChildTag(table));
2364 content.AddChildTag(HtmlTagButtonCancel());
2365 content.AddChildTag(HtmlTagButtonPopupWide(Languages::TextNew, "accessoryedit_0"));
2366 ReplyHtmlWithHeader(content);
2367 }
2368
2369 void WebClient::HandleAccessoryAskDelete(const map<string, string>& arguments)
2370 {
2371 AccessoryID accessoryID = Utils::Utils::GetIntegerMapEntry(arguments, "accessory", AccessoryNone);
2372
2373 if (accessoryID == AccessoryNone)
2374 {
2375 ReplyHtmlWithHeaderAndParagraph(Languages::TextAccessoryDoesNotExist);
2376 return;
2377 }
2378
2379 const DataModel::Accessory* accessory = manager.GetAccessory(accessoryID);
2380 if (accessory == nullptr)
2381 {
2382 ReplyHtmlWithHeaderAndParagraph(Languages::TextAccessoryDoesNotExist);
2383 return;
2384 }
2385
2386 HtmlTag content;
2387 const string& accessoryName = accessory->GetName();
2388 content.AddContent(HtmlTag("h1").AddContent(Languages::TextDeleteAccessory));
2389 content.AddContent(HtmlTag("p").AddContent(Languages::TextAreYouSureToDelete, accessoryName));
2390 content.AddContent(HtmlTag("form").AddId("editform")
2391 .AddContent(HtmlTagInputHidden("cmd", "accessorydelete"))
2392 .AddContent(HtmlTagInputHidden("accessory", to_string(accessoryID))
2393 ));
2394 content.AddContent(HtmlTagButtonCancel());
2395 content.AddContent(HtmlTagButtonOK());
2396 ReplyHtmlWithHeader(content);
2397 }
2398
2399 void WebClient::HandleAccessoryDelete(const map<string, string>& arguments)
2400 {
2401 AccessoryID accessoryID = Utils::Utils::GetIntegerMapEntry(arguments, "accessory", AccessoryNone);
2402 const DataModel::Accessory* accessory = manager.GetAccessory(accessoryID);
2403 if (accessory == nullptr)
2404 {
2405 ReplyResponse(ResponseError, Languages::TextAccessoryDoesNotExist);
2406 return;
2407 }
2408
2409 string name = accessory->GetName();
2410 string result;
2411 if (!manager.AccessoryDelete(accessoryID, result))
2412 {
2413 ReplyResponse(ResponseError, result);
2414 return;
2415 }
2416
2417 ReplyResponse(ResponseInfo, Languages::TextAccessoryDeleted, name);
2418 }
2419
2420 void WebClient::HandleAccessoryRelease(const map<string, string>& arguments)
2421 {
2422 AccessoryID accessoryID = Utils::Utils::GetIntegerMapEntry(arguments, "accessory");
2423 bool ret = manager.AccessoryRelease(accessoryID);
2424 ReplyHtmlWithHeaderAndParagraph(ret ? "Accessory released" : "Accessory not released");
2425 }
2426
2427 void WebClient::HandleSwitchEdit(const map<string, string>& arguments)
2428 {
2429 HtmlTag content;
2430 SwitchID switchID = Utils::Utils::GetIntegerMapEntry(arguments, "switch", SwitchNone);
2431 ControlID controlId = manager.GetPossibleControlForAccessory();
2432 if (controlId == ControlNone)
2433 {
2434 controlId = manager.GetPossibleControlForAccessory();
2435 }
2436 string matchKey = Utils::Utils::GetStringMapEntry(arguments, "matchkey");
2437 Protocol protocol = ProtocolNone;
2438 Address address = AddressDefault;
2439 Address serverAddress = AddressNone;
2440 string name = Languages::GetText(Languages::TextNew);
2441 LayoutPosition posx = Utils::Utils::GetIntegerMapEntry(arguments, "posx", 0);
2442 LayoutPosition posy = Utils::Utils::GetIntegerMapEntry(arguments, "posy", 0);
2443 LayoutPosition posz = Utils::Utils::GetIntegerMapEntry(arguments, "posz", LayerUndeletable);
2444 LayoutRotation rotation = Utils::Utils::GetIntegerMapEntry(arguments, "rotation", DataModel::LayoutItem::Rotation0);
2445 DataModel::AccessoryType type = DataModel::SwitchTypeLeft;
2446 DataModel::AccessoryPulseDuration duration = manager.GetDefaultAccessoryDuration();
2447 bool inverted = false;
2448 if (switchID > SwitchNone)
2449 {
2450 const DataModel::Switch* mySwitch = manager.GetSwitch(switchID);
2451 if (mySwitch != nullptr)
2452 {
2453 controlId = mySwitch->GetControlID();
2454 matchKey = mySwitch->GetMatchKey();
2455 protocol = mySwitch->GetProtocol();
2456 address = mySwitch->GetAddress();
2457 serverAddress = mySwitch->GetServerAddress();
2458 name = mySwitch->GetName();
2459 posx = mySwitch->GetPosX();
2460 posy = mySwitch->GetPosY();
2461 posz = mySwitch->GetPosZ();
2462 rotation = mySwitch->GetRotation();
2463 type = mySwitch->GetAccessoryType();
2464 duration = mySwitch->GetAccessoryPulseDuration();
2465 inverted = mySwitch->GetInverted();
2466 }
2467 }
2468 else if (controlId > ControlNone)
2469 {
2470 // switch from hardware database
2471 const DataModel::AccessoryConfig switchConfig = manager.GetAccessoryOfConfigByMatchKey(controlId, matchKey);
2472 if (switchConfig.GetControlId() == controlId && switchConfig.GetMatchKey() == matchKey)
2473 {
2474 protocol = switchConfig.GetProtocol();
2475 address = switchConfig.GetAddress();
2476 name = switchConfig.GetName();
2477 }
2478 }
2479 // else new switch
2480
2481 std::map<DataModel::AccessoryType,Languages::TextSelector> typeOptions;
2482 typeOptions[DataModel::SwitchTypeLeft] = Languages::TextLeft;
2483 typeOptions[DataModel::SwitchTypeRight] = Languages::TextRight;
2484 typeOptions[DataModel::SwitchTypeThreeWay] = Languages::TextThreeWay;
2485 typeOptions[DataModel::SwitchTypeMaerklinLeft] = Languages::TextMaerklinLeft;
2486 typeOptions[DataModel::SwitchTypeMaerklinRight] = Languages::TextMaerklinRight;
2487
2488 content.AddChildTag(HtmlTag("h1").AddContent(name).AddId("popup_title"));
2489 HtmlTag tabMenu("div");
2490 tabMenu.AddChildTag(WebClientStatic::HtmlTagTabMenuItem("main", Languages::TextBasic, true));
2491 tabMenu.AddChildTag(WebClientStatic::HtmlTagTabMenuItem("position", Languages::TextPosition));
2492 content.AddChildTag(tabMenu);
2493
2494 HtmlTag formContent;
2495 formContent.AddChildTag(HtmlTagInputHidden("cmd", "switchsave"));
2496 formContent.AddChildTag(HtmlTagInputHidden("switch", to_string(switchID)));
2497
2498 HtmlTag mainContent("div");
2499 mainContent.AddId("tab_main");
2500 mainContent.AddClass("tab_content");
2501 mainContent.AddChildTag(HtmlTagInputTextWithLabel("name", Languages::TextName, name).AddAttribute("onkeyup", "updateName();"));
2502 mainContent.AddChildTag(HtmlTagSelectWithLabel("type", Languages::TextType, typeOptions, type));
2503 mainContent.AddChildTag(HtmlTagControlAccessory(controlId, "switch", switchID));
2504 mainContent.AddChildTag(HtmlTag("div").AddId("select_protocol").AddChildTag(HtmlTagMatchKeyProtocolAccessory(controlId, matchKey, protocol)));
2505 mainContent.AddChildTag(HtmlTagInputIntegerWithLabel("address", Languages::TextAddress, address, 1, 2044));
2506 mainContent.AddChildTag(WebClientStatic::HtmlTagDuration(duration));
2507 mainContent.AddChildTag(HtmlTagInputCheckboxWithLabel("inverted", Languages::TextInverted, "true", inverted));
2508 if (manager.IsServerEnabled())
2509 {
2510 mainContent.AddChildTag(HtmlTagInputIntegerWithLabel("serveraddress", Languages::TextServerAddress, serverAddress, 0, 2044));
2511 }
2512 formContent.AddChildTag(mainContent);
2513
2514 formContent.AddChildTag(HtmlTagTabPosition(posx, posy, posz, rotation));
2515
2516 content.AddChildTag(HtmlTag("div").AddClass("popup_content").AddChildTag(HtmlTag("form").AddId("editform").AddChildTag(formContent)));
2517 content.AddChildTag(HtmlTagButtonCancel());
2518 content.AddChildTag(HtmlTagButtonOK());
2519 ReplyHtmlWithHeader(content);
2520 }
2521
2522 void WebClient::HandleSwitchSave(const map<string, string>& arguments)
2523 {
2524 const SwitchID switchID = Utils::Utils::GetIntegerMapEntry(arguments, "switch", SwitchNone);
2525 const string name = Utils::Utils::GetStringMapEntry(arguments, "name");
2526 const ControlID controlId = Utils::Utils::GetIntegerMapEntry(arguments, "control", ControlIdNone);
2527 const string matchKey = Utils::Utils::GetStringMapEntry(arguments, "matchkey");
2528 const Protocol protocol = static_cast<Protocol>(Utils::Utils::GetIntegerMapEntry(arguments, "protocol", ProtocolNone));
2529 const Address address = Utils::Utils::GetIntegerMapEntry(arguments, "address", AddressDefault);
2530 const Address serverAddress = Utils::Utils::GetIntegerMapEntry(arguments, "serveraddress", AddressNone);
2531 const LayoutPosition posX = Utils::Utils::GetIntegerMapEntry(arguments, "posx", 0);
2532 const LayoutPosition posY = Utils::Utils::GetIntegerMapEntry(arguments, "posy", 0);
2533 const LayoutPosition posZ = Utils::Utils::GetIntegerMapEntry(arguments, "posz", 0);
2534 const LayoutRotation rotation = Utils::Utils::GetIntegerMapEntry(arguments, "rotation", DataModel::LayoutItem::Rotation0);
2535 const DataModel::AccessoryType type = static_cast<DataModel::AccessoryType>(Utils::Utils::GetIntegerMapEntry(arguments, "type", DataModel::SwitchTypeLeft));
2536 const DataModel::AccessoryPulseDuration duration = Utils::Utils::GetIntegerMapEntry(arguments, "duration", manager.GetDefaultAccessoryDuration());
2537 const bool inverted = Utils::Utils::GetBoolMapEntry(arguments, "inverted");
2538 string result;
2539 if (!manager.SwitchSave(switchID,
2540 name,
2541 posX,
2542 posY,
2543 posZ,
2544 rotation,
2545 controlId,
2546 matchKey,
2547 protocol,
2548 address,
2549 serverAddress,
2550 type,
2551 duration,
2552 inverted,
2553 result))
2554 {
2555 ReplyResponse(ResponseError, result);
2556 return;
2557 }
2558
2559 ReplyResponse(ResponseInfo, Languages::TextSwitchSaved, name);
2560 }
2561
2562 void WebClient::HandleSwitchState(const map<string, string>& arguments)
2563 {
2564 SwitchID switchID = Utils::Utils::GetIntegerMapEntry(arguments, "switch", SwitchNone);
2565 string switchStateText = Utils::Utils::GetStringMapEntry(arguments, "state", "turnout");
2566 DataModel::AccessoryState switchState;
2567 if (switchStateText.compare("turnout") == 0)
2568 {
2569 switchState = DataModel::SwitchStateTurnout;
2570 }
2571 else if (switchStateText.compare("third") == 0)
2572 {
2573 switchState = DataModel::SwitchStateThird;
2574 }
2575 else
2576 {
2577 switchState = DataModel::SwitchStateStraight;
2578 }
2579 manager.SwitchState(ControlTypeWebServer, switchID, switchState, false);
2580
2581 ReplyHtmlWithHeaderAndParagraph(switchState ? Languages::TextSwitchStateIsStraight : Languages::TextSwitchStateIsTurnout, manager.GetSwitchName(switchID));
2582 }
2583
2584 void WebClient::HandleSwitchList()
2585 {
2586 HtmlTag content;
2587 content.AddChildTag(HtmlTag("h1").AddContent(Languages::TextSwitches));
2588 HtmlTag table("table");
2589 const map<string,AccessoryConfig> switchList = manager.SwitchConfigByName();
2590 map<string,string> switchArgument;
2591 for (auto& mySwitch : switchList)
2592 {
2593 const AccessoryConfig& switchConfig = mySwitch.second;
2594 HtmlTag row("tr");
2595 row.AddChildTag(HtmlTag("td").AddContent(mySwitch.first));
2596 row.AddChildTag(HtmlTag("td").AddContent(ProtocolName(switchConfig.GetProtocol())));
2597 row.AddChildTag(HtmlTag("td").AddContent(to_string(switchConfig.GetAddress())));
2598 SwitchID switchId = switchConfig.GetObjectIdentifier().GetObjectID();
2599 const string& switchIdString = to_string(switchId);
2600 switchArgument["switch"] = switchIdString;
2601 if (switchId == SwitchNone)
2602 {
2603 switchArgument["control"] = to_string(switchConfig.GetControlId());
2604 switchArgument["matchkey"] = switchConfig.GetMatchKey();
2605 row.AddChildTag(HtmlTag("td").AddChildTag(HtmlTagButtonPopupWide(Languages::TextImport, "switchedit_list_" + switchIdString, switchArgument)));
2606 }
2607 else
2608 {
2609 row.AddChildTag(HtmlTag("td").AddChildTag(HtmlTagButtonPopupWide(Languages::TextEdit, "switchedit_list_" + switchIdString, switchArgument)));
2610 row.AddChildTag(HtmlTag("td").AddChildTag(HtmlTagButtonPopupWide(Languages::TextDelete, "switchaskdelete_" + switchIdString, switchArgument)));
2611 if (switchConfig.IsInUse())
2612 {
2613 row.AddChildTag(HtmlTag("td").AddChildTag(HtmlTagButtonCommandWide(Languages::TextRelease, "switchrelease_" + switchIdString, switchArgument, "hideElement('b_switchrelease_" + switchIdString + "');")));
2614 }
2615 }
2616 table.AddChildTag(row);
2617 }
2618 content.AddChildTag(HtmlTag("div").AddClass("popup_content").AddChildTag(table));
2619 content.AddChildTag(HtmlTagButtonCancel());
2620 content.AddChildTag(HtmlTagButtonPopupWide(Languages::TextNew, "switchedit_0"));
2621 ReplyHtmlWithHeader(content);
2622 }
2623
2624 void WebClient::HandleSwitchAskDelete(const map<string, string>& arguments)
2625 {
2626 SwitchID switchID = Utils::Utils::GetIntegerMapEntry(arguments, "switch", SwitchNone);
2627
2628 if (switchID == SwitchNone)
2629 {
2630 ReplyHtmlWithHeaderAndParagraph(Languages::TextSwitchDoesNotExist);
2631 return;
2632 }
2633
2634 const DataModel::Switch* mySwitch = manager.GetSwitch(switchID);
2635 if (mySwitch == nullptr)
2636 {
2637 ReplyHtmlWithHeaderAndParagraph(Languages::TextSwitchDoesNotExist);
2638 return;
2639 }
2640
2641 HtmlTag content;
2642 const string& switchName = mySwitch->GetName();
2643 content.AddContent(HtmlTag("h1").AddContent(Languages::TextDeleteSwitch));
2644 content.AddContent(HtmlTag("p").AddContent(Languages::TextAreYouSureToDelete, switchName));
2645 content.AddContent(HtmlTag("form").AddId("editform")
2646 .AddContent(HtmlTagInputHidden("cmd", "switchdelete"))
2647 .AddContent(HtmlTagInputHidden("switch", to_string(switchID))
2648 ));
2649 content.AddContent(HtmlTagButtonCancel());
2650 content.AddContent(HtmlTagButtonOK());
2651 ReplyHtmlWithHeader(content);
2652 }
2653
2654 void WebClient::HandleSwitchDelete(const map<string, string>& arguments)
2655 {
2656 SwitchID switchID = Utils::Utils::GetIntegerMapEntry(arguments, "switch", SwitchNone);
2657 const DataModel::Switch* mySwitch = manager.GetSwitch(switchID);
2658 if (mySwitch == nullptr)
2659 {
2660 ReplyResponse(ResponseError, Languages::TextSwitchDoesNotExist);
2661 return;
2662 }
2663
2664 string name = mySwitch->GetName();
2665 string result;
2666 if (!manager.SwitchDelete(switchID, result))
2667 {
2668 ReplyResponse(ResponseError, result);
2669 return;
2670 }
2671
2672 ReplyResponse(ResponseInfo, Languages::TextSwitchDeleted, name);
2673 }
2674
2675 void WebClient::HandleSwitchGet(const map<string, string>& arguments)
2676 {
2677 SwitchID switchID = Utils::Utils::GetIntegerMapEntry(arguments, "switch");
2678 const DataModel::Switch* mySwitch = manager.GetSwitch(switchID);
2679 if (mySwitch == nullptr)
2680 {
2681 ReplyHtmlWithHeader(HtmlTag());
2682 return;
2683 }
2684 ReplyHtmlWithHeader(HtmlTagSwitch(mySwitch));
2685 }
2686
2687 void WebClient::HandleSwitchRelease(const map<string, string>& arguments)
2688 {
2689 SwitchID switchID = Utils::Utils::GetIntegerMapEntry(arguments, "switch");
2690 bool ret = manager.SwitchRelease(switchID);
2691 ReplyHtmlWithHeaderAndParagraph(ret ? "Switch released" : "Switch not released");
2692 }
2693
2694 HtmlTag WebClient::HtmlTagTabPosition(const LayoutPosition posx,
2695 const LayoutPosition posy,
2696 const LayoutPosition posz,
2697 const LayoutRotation rotation,
2698 const Visible visible) const
2699 {
2700 HtmlTag positionContent("div");
2701 positionContent.AddId("tab_position");
2702 positionContent.AddClass("tab_content");
2703 positionContent.AddClass("hidden");
2704 if (visible == DataModel::LayoutItem::VisibleNotRelevant)
2705 {
2706 positionContent.AddChildTag(HtmlTagPosition(posx, posy, posz));
2707 }
2708 else
2709 {
2710 positionContent.AddChildTag(HtmlTagPosition(posx, posy, posz, visible));
2711 }
2712 if (rotation != DataModel::LayoutItem::RotationNotRelevant)
2713 {
2714 positionContent.AddChildTag(WebClientStatic::HtmlTagRotation(rotation));
2715 }
2716 return positionContent;
2717 }
2718
2719 HtmlTag WebClient::HtmlTagRelationSignalState(const string& name,
2720 const SignalID signalId,
2721 const DataModel::Relation::Data data)
2722 {
2723 map<DataModel::AccessoryState,DataModel::Signal::StateOption> stateOptions;
2724 Signal* signal = manager.GetSignal(signalId);
2725 if (signal != nullptr)
2726 {
2727 stateOptions = signal->GetStateOptions();
2728 }
2729
2730 return HtmlTagSelect(name + "_state", stateOptions, static_cast<DataModel::AccessoryState>(data)).AddClass("select_relation_state");
2731 }
2732
2733 void WebClient::HandleFeedbackEdit(const map<string, string>& arguments)
2734 {
2735 HtmlTag content;
2736 FeedbackID feedbackID = Utils::Utils::GetIntegerMapEntry(arguments, "feedback", FeedbackNone);
2737 string name = Languages::GetText(Languages::TextNew);
2738 ControlID controlId = Utils::Utils::GetIntegerMapEntry(arguments, "controlid", manager.GetPossibleControlForFeedback());
2739 string matchKey = Utils::Utils::GetStringMapEntry(arguments, "matchkey");
2740 FeedbackPin pin = Utils::Utils::GetIntegerMapEntry(arguments, "pin", FeedbackPinNone);
2741 DataModel::FeedbackType feedbackType = static_cast<DataModel::FeedbackType>(Utils::Utils::GetIntegerMapEntry(arguments, "feedbacktype", FeedbackTypeDefault));
2742 RouteID routeId = Utils::Utils::GetIntegerMapEntry(arguments, "route", RouteNone);
2743 LayoutPosition posx = Utils::Utils::GetIntegerMapEntry(arguments, "posx", 0);
2744 LayoutPosition posy = Utils::Utils::GetIntegerMapEntry(arguments, "posy", 0);
2745 LayoutPosition posz = Utils::Utils::GetIntegerMapEntry(arguments, "posz", LayerUndeletable);
2746 LayoutRotation rotation = Utils::Utils::GetIntegerMapEntry(arguments, "rotation", DataModel::LayoutItem::Rotation0);
2747 DataModel::LayoutItem::Visible visible = static_cast<Visible>(Utils::Utils::GetBoolMapEntry(arguments, "visible", feedbackID == FeedbackNone && ((posx || posy) && posz >= LayerUndeletable) ? DataModel::LayoutItem::VisibleYes : DataModel::LayoutItem::VisibleNo));
2748 if (posz < LayerUndeletable)
2749 {
2750 if (controlId == ControlNone)
2751 {
2752 controlId = -posz;
2753 }
2754 if (pin == 0)
2755 {
2756 pin = posy * 16 + posx + (posx > 8 ? 0 : 1);
2757 }
2758 }
2759 bool inverted = false;
2760 if (feedbackID > FeedbackNone)
2761 {
2762 // existing feedback
2763 const DataModel::Feedback* feedback = manager.GetFeedback(feedbackID);
2764 if (feedback != nullptr)
2765 {
2766 name = feedback->GetName();
2767 matchKey = feedback->GetMatchKey();
2768 controlId = feedback->GetControlID();
2769 pin = feedback->GetPin();
2770 inverted = feedback->GetInverted();
2771 feedbackType = feedback->GetFeedbackType();
2772 routeId = feedback->GetRouteId();
2773 visible = feedback->GetVisible();
2774 posx = feedback->GetPosX();
2775 posy = feedback->GetPosY();
2776 posz = feedback->GetPosZ();
2777 rotation = feedback->GetRotation();
2778 }
2779 }
2780 else if (controlId > ControlNone)
2781 {
2782 // feedback from hardware database
2783 const DataModel::FeedbackConfig feedback = manager.GetFeedbackOfConfigByMatchKey(controlId, matchKey);
2784 if (feedback.GetControlId() == controlId && feedback.GetMatchKey() == matchKey)
2785 {
2786 name = feedback.GetName();
2787 pin = feedback.GetPin();
2788 }
2789 }
2790 // else new feedback
2791
2792
2793 content.AddChildTag(HtmlTag("h1").AddContent(name).AddId("popup_title"));
2794
2795 HtmlTag tabMenu("div");
2796 tabMenu.AddChildTag(WebClientStatic::HtmlTagTabMenuItem("main", Languages::TextBasic, true));
2797 tabMenu.AddChildTag(WebClientStatic::HtmlTagTabMenuItem("position", Languages::TextPosition));
2798 content.AddChildTag(tabMenu);
2799
2800 HtmlTag formContent("form");
2801 formContent.AddId("editform");
2802 formContent.AddChildTag(HtmlTagInputHidden("cmd", "feedbacksave"));
2803 formContent.AddChildTag(HtmlTagInputHidden("feedback", to_string(feedbackID)));
2804
2805 std::map<DataModel::FeedbackType, Languages::TextSelector> typeOptions;
2806 typeOptions[DataModel::FeedbackTypeDefault] = Languages::TextDefault;
2807 typeOptions[DataModel::FeedbackTypeStraight] = Languages::TextStraight;
2808 typeOptions[DataModel::FeedbackTypeTurn] = Languages::TextTurn;
2809
2810 const std::map<string, Route*> routes = manager.RouteListByName();
2811 map<string, RouteID> routeOptions;
2812 routeOptions["-"] = RouteNone;
2813 for (auto& track : routes)
2814 {
2815 routeOptions[track.first] = track.second->GetID();
2816 }
2817
2818 HtmlTag mainContent("div");
2819 mainContent.AddId("tab_main");
2820 mainContent.AddClass("tab_content");
2821 mainContent.AddChildTag(HtmlTagInputTextWithLabel("name", Languages::TextName, name).AddAttribute("onkeyup", "updateName();"));
2822 mainContent.AddChildTag(HtmlTagControlFeedback(controlId, "feedback", feedbackID));
2823 mainContent.AddChildTag(HtmlTagMatchKeyFeedback(controlId, matchKey));
2824 mainContent.AddChildTag(HtmlTagInputIntegerWithLabel("pin", Languages::TextPin, pin, 1, 4096));
2825 mainContent.AddChildTag(HtmlTagInputCheckboxWithLabel("inverted", Languages::TextInverted, "true", inverted));
2826 mainContent.AddChildTag(HtmlTagSelectWithLabel("feedbacktype", Languages::TextType, typeOptions, feedbackType));
2827 mainContent.AddChildTag(HtmlTagSelectWithLabel("route", Languages::TextExecuteRoute, routeOptions, routeId));
2828 formContent.AddChildTag(mainContent);
2829
2830 formContent.AddChildTag(HtmlTagTabPosition(posx, posy, posz, rotation, visible));
2831
2832 content.AddChildTag(HtmlTag("div").AddClass("popup_content").AddChildTag(formContent));
2833 content.AddChildTag(HtmlTagButtonCancel());
2834 content.AddChildTag(HtmlTagButtonOK());
2835 ReplyHtmlWithHeader(content);
2836 }
2837
2838 void WebClient::HandleFeedbackSave(const map<string, string>& arguments)
2839 {
2840 const FeedbackID feedbackID = Utils::Utils::GetIntegerMapEntry(arguments, "feedback", FeedbackNone);
2841 const string name = Utils::Utils::GetStringMapEntry(arguments, "name");
2842 const ControlID controlId = Utils::Utils::GetIntegerMapEntry(arguments, "control", ControlIdNone);
2843 const string matchKey = Utils::Utils::GetStringMapEntry(arguments, "matchkey");
2844 const FeedbackPin pin = static_cast<FeedbackPin>(Utils::Utils::GetIntegerMapEntry(arguments, "pin", FeedbackPinNone));
2845 const bool inverted = Utils::Utils::GetBoolMapEntry(arguments, "inverted");
2846 const DataModel::FeedbackType feedbackType = static_cast<DataModel::FeedbackType>(Utils::Utils::GetIntegerMapEntry(arguments, "feedbacktype", FeedbackTypeDefault));
2847 const RouteID routeId = Utils::Utils::GetIntegerMapEntry(arguments, "route", RouteNone);
2848 const DataModel::LayoutItem::Visible visible = static_cast<Visible>(Utils::Utils::GetBoolMapEntry(arguments, "visible", DataModel::LayoutItem::VisibleNo));
2849 const LayoutPosition posX = Utils::Utils::GetIntegerMapEntry(arguments, "posx", 0);
2850 const LayoutPosition posY = Utils::Utils::GetIntegerMapEntry(arguments, "posy", 0);
2851 const LayoutPosition posZ = Utils::Utils::GetIntegerMapEntry(arguments, "posz", 0);
2852 const LayoutRotation rotation = Utils::Utils::GetIntegerMapEntry(arguments, "rotation", DataModel::LayoutItem::Rotation0);
2853 string result;
2854 if (!manager.FeedbackSave(feedbackID,
2855 name,
2856 visible,
2857 posX,
2858 posY,
2859 posZ,
2860 rotation,
2861 controlId,
2862 matchKey,
2863 pin,
2864 inverted,
2865 feedbackType,
2866 routeId,
2867 result))
2868 {
2869 ReplyResponse(ResponseError, result);
2870 return;
2871 }
2872
2873 ReplyResponse(ResponseInfo, Languages::TextFeedbackSaved, name);
2874 }
2875
2876 void WebClient::HandleFeedbackState(const map<string, string>& arguments)
2877 {
2878 FeedbackID feedbackID = Utils::Utils::GetIntegerMapEntry(arguments, "feedback", FeedbackNone);
2879 DataModel::Feedback::FeedbackState state = (Utils::Utils::GetStringMapEntry(arguments, "state", "occupied").compare("occupied") == 0 ? DataModel::Feedback::FeedbackStateOccupied : DataModel::Feedback::FeedbackStateFree);
2880
2881 manager.FeedbackState(feedbackID, state);
2882
2883 ReplyHtmlWithHeaderAndParagraph(state ? Languages::TextFeedbackStateIsOn : Languages::TextFeedbackStateIsOff, manager.GetFeedbackName(feedbackID));
2884 }
2885
2886 void WebClient::HandleFeedbackList()
2887 {
2888 HtmlTag content;
2889 content.AddChildTag(HtmlTag("h1").AddContent(Languages::TextFeedbacks));
2890 HtmlTag table("table");
2891 const map<string,DataModel::FeedbackConfig> feedbackList = manager.FeedbackConfigByName();
2892 map<string,string> feedbackArgument;
2893 for (auto& feedback : feedbackList)
2894 {
2895 const DataModel::FeedbackConfig& feedbackConfig = feedback.second;
2896 HtmlTag row("tr");
2897 row.AddChildTag(HtmlTag("td").AddContent(feedback.first));
2898 const FeedbackID feedbackId = feedbackConfig.GetFeedbackId();
2899 const string& feedbackIdString = to_string(feedbackId);
2900 feedbackArgument["feedback"] = feedbackIdString;
2901 if (feedbackId == FeedbackNone)
2902 {
2903 feedbackArgument["control"] = to_string(feedbackConfig.GetControlId());
2904 feedbackArgument["matchkey"] = feedbackConfig.GetMatchKey();
2905 row.AddChildTag(HtmlTag("td").AddChildTag(HtmlTagButtonPopupWide(Languages::TextImport, "feedbackedit_list_" + feedbackIdString, feedbackArgument)));
2906 }
2907 else
2908 {
2909 row.AddChildTag(HtmlTag("td").AddChildTag(HtmlTagButtonPopupWide(Languages::TextEdit, "feedbackedit_list_" + feedbackIdString, feedbackArgument)));
2910 row.AddChildTag(HtmlTag("td").AddChildTag(HtmlTagButtonPopupWide(Languages::TextDelete, "feedbackaskdelete_" + feedbackIdString, feedbackArgument)));
2911 }
2912 table.AddChildTag(row);
2913 }
2914 content.AddChildTag(HtmlTag("div").AddClass("popup_content").AddChildTag(table));
2915 content.AddChildTag(HtmlTagButtonCancel());
2916 content.AddChildTag(HtmlTagButtonPopupWide(Languages::TextNew, "feedbackedit_0"));
2917 ReplyHtmlWithHeader(content);
2918 }
2919
2920 void WebClient::HandleFeedbackAskDelete(const map<string, string>& arguments)
2921 {
2922 FeedbackID feedbackID = Utils::Utils::GetIntegerMapEntry(arguments, "feedback", FeedbackNone);
2923
2924 if (feedbackID == FeedbackNone)
2925 {
2926 ReplyHtmlWithHeaderAndParagraph(Languages::TextFeedbackDoesNotExist);
2927 return;
2928 }
2929
2930 const DataModel::Feedback* feedback = manager.GetFeedback(feedbackID);
2931 if (feedback == nullptr)
2932 {
2933 ReplyHtmlWithHeaderAndParagraph(Languages::TextFeedbackDoesNotExist);
2934 return;
2935 }
2936
2937 HtmlTag content;
2938 const string& feedbackName = feedback->GetName();
2939 content.AddContent(HtmlTag("h1").AddContent(Languages::TextDeleteFeedback));
2940 content.AddContent(HtmlTag("p").AddContent(Languages::TextAreYouSureToDelete, feedbackName));
2941 content.AddContent(HtmlTag("form").AddId("editform")
2942 .AddContent(HtmlTagInputHidden("cmd", "feedbackdelete"))
2943 .AddContent(HtmlTagInputHidden("feedback", to_string(feedbackID))
2944 ));
2945 content.AddContent(HtmlTagButtonCancel());
2946 content.AddContent(HtmlTagButtonOK());
2947 ReplyHtmlWithHeader(content);
2948 }
2949
2950 void WebClient::HandleFeedbackDelete(const map<string, string>& arguments)
2951 {
2952 FeedbackID feedbackID = Utils::Utils::GetIntegerMapEntry(arguments, "feedback", FeedbackNone);
2953 const DataModel::Feedback* feedback = manager.GetFeedback(feedbackID);
2954 if (feedback == nullptr)
2955 {
2956 ReplyResponse(ResponseError, Languages::TextFeedbackDoesNotExist);
2957 return;
2958 }
2959
2960 string name = feedback->GetName();
2961 string result;
2962 if (!manager.FeedbackDelete(feedbackID, result))
2963 {
2964 ReplyResponse(ResponseError, result);
2965 return;
2966 }
2967
2968 ReplyResponse(ResponseInfo, Languages::TextFeedbackDeleted, name);
2969 }
2970
2971 void WebClient::HandleFeedbackGet(const map<string, string>& arguments)
2972 {
2973 FeedbackID feedbackID = Utils::Utils::GetIntegerMapEntry(arguments, "feedback", FeedbackNone);
2974 const DataModel::Feedback* feedback = manager.GetFeedback(feedbackID);
2975 if (feedback == nullptr)
2976 {
2977 ReplyHtmlWithHeader(HtmlTag());
2978 return;
2979 }
2980
2981 LayerID layer = Utils::Utils::GetIntegerMapEntry(arguments, "layer", LayerNone);
2982 if (feedback->GetControlID() == -layer)
2983 {
2984 ReplyHtmlWithHeader(HtmlTagFeedback(feedback, true));
2985 return;
2986 }
2987
2988 if (layer < LayerNone || feedback->GetVisible() == DataModel::LayoutItem::VisibleNo)
2989 {
2990 ReplyHtmlWithHeader(HtmlTag());
2991 return;
2992 }
2993
2994 ReplyHtmlWithHeader(HtmlTagFeedback(feedback));
2995 }
2996
2997 void WebClient::HandleLocoSelector(const map<string,string>& arguments)
2998 {
2999 const unsigned int selector = Utils::Utils::GetIntegerMapEntry(arguments, "selector", 1);
3000 const LocoID locoID = Utils::Utils::GetIntegerMapEntry(arguments, "loco");
3001 ReplyHtmlWithHeader(HtmlTagLocoSelector(to_string(selector), locoID));
3002 }
3003
3004 void WebClient::HandleLayerSelector(const map<string,string>& arguments)
3005 {
3006 const LayerID layerID = Utils::Utils::GetIntegerMapEntry(arguments, "layer");
3007 ReplyHtmlWithHeader(HtmlTagLayerSelector(layerID));
3008 }
3009
3010 void WebClient::HandleSettingsEdit()
3011 {
3012 const StartupInitLocos startupInitLocos = manager.GetStartupInitLocos();
3013 const DataModel::AccessoryPulseDuration defaultAccessoryDuration = manager.GetDefaultAccessoryDuration();
3014 const bool executeAccessory = manager.GetExecuteAccessory();
3015 const bool autoAddFeedback = manager.GetAutoAddFeedback();
3016 const bool stopOnFeedbackInFreeTrack = manager.GetStopOnFeedbackInFreeTrack();
3017 const DataModel::SelectRouteApproach selectRouteApproach = manager.GetSelectRouteApproach();
3018 const DataModel::LocoBase::NrOfTracksToReserve nrOfTracksToReserve = manager.GetNrOfTracksToReserve();
3019
3020 HtmlTag content;
3021 content.AddChildTag(HtmlTag("h1").AddContent(Languages::TextSettings).AddId("popup_title"));
3022 HtmlTag tabMenu("div");
3023 tabMenu.AddChildTag(WebClientStatic::HtmlTagTabMenuItem("basic", Languages::TextBasic, true));
3024 tabMenu.AddChildTag(WebClientStatic::HtmlTagTabMenuItem("startup", Languages::TextStartup));
3025 tabMenu.AddChildTag(WebClientStatic::HtmlTagTabMenuItem("feedback", Languages::TextFeedback));
3026 tabMenu.AddChildTag(WebClientStatic::HtmlTagTabMenuItem("accessory", Languages::TextAccessory));
3027 tabMenu.AddChildTag(WebClientStatic::HtmlTagTabMenuItem("automode", Languages::TextAutomode));
3028 content.AddChildTag(tabMenu);
3029
3030 HtmlTag formContent("form");
3031 formContent.AddId("editform");
3032 formContent.AddChildTag(HtmlTagInputHidden("cmd", "settingssave"));
3033
3034 HtmlTag basicContent("div");
3035 basicContent.AddId("tab_basic");
3036 basicContent.AddClass("tab_content");
3037 basicContent.AddChildTag(WebClientStatic::HtmlTagLanguage());
3038 basicContent.AddChildTag(WebClientStatic::HtmlTagLogLevel());
3039 formContent.AddChildTag(basicContent);
3040
3041 HtmlTag startupContent("div");
3042 startupContent.AddId("tab_startup");
3043 startupContent.AddClass("tab_content");
3044 startupContent.AddClass("hidden");
3045 startupContent.AddChildTag(WebClientStatic::HtmlTagStartupLocos(startupInitLocos));
3046 formContent.AddChildTag(startupContent);
3047
3048 HtmlTag accessoryContent("div");
3049 accessoryContent.AddId("tab_accessory");
3050 accessoryContent.AddClass("tab_content");
3051 accessoryContent.AddClass("hidden");
3052 accessoryContent.AddChildTag(WebClientStatic::HtmlTagDuration(defaultAccessoryDuration, Languages::TextDefaultSwitchingDuration));
3053 accessoryContent.AddChildTag(WebClientStatic::HtmlTagSelectExecuteAccessory(executeAccessory));
3054 formContent.AddChildTag(accessoryContent);
3055
3056 HtmlTag feedbackContent("div");
3057 feedbackContent.AddId("tab_feedback");
3058 feedbackContent.AddClass("tab_content");
3059 feedbackContent.AddClass("hidden");
3060 feedbackContent.AddChildTag(HtmlTagInputCheckboxWithLabel("autoaddfeedback", Languages::TextAutomaticallyAddUnknownFeedbacks, "autoaddfeedback", autoAddFeedback));
3061 feedbackContent.AddChildTag(HtmlTagInputCheckboxWithLabel("stoponfeedbackinfreetrack", Languages::TextStopOnFeedbackInFreeTrack, "stoponfeedbackinfreetrack", stopOnFeedbackInFreeTrack));
3062 formContent.AddChildTag(feedbackContent);
3063
3064 HtmlTag automodeContent("div");
3065 automodeContent.AddId("tab_automode");
3066 automodeContent.AddClass("tab_content");
3067 automodeContent.AddClass("hidden");
3068 automodeContent.AddChildTag(WebClientStatic::HtmlTagSelectSelectRouteApproach(selectRouteApproach, false));
3069 automodeContent.AddChildTag(WebClientStatic::HtmlTagNrOfTracksToReserve(nrOfTracksToReserve));
3070 formContent.AddChildTag(automodeContent);
3071
3072 content.AddChildTag(HtmlTag("div").AddClass("popup_content").AddChildTag(formContent));
3073 content.AddChildTag(HtmlTagButtonCancel());
3074 content.AddChildTag(HtmlTagButtonOK());
3075 ReplyHtmlWithHeader(content);
3076 }
3077
3078 void WebClient::HandleSettingsSave(const map<string, string>& arguments)
3079 {
3080 const Languages::Language language = static_cast<Languages::Language>(Utils::Utils::GetIntegerMapEntry(arguments, "language", Languages::EN));
3081 const Logger::Logger::Level logLevel = static_cast<Logger::Logger::Level>(Utils::Utils::GetIntegerMapEntry(arguments, "loglevel", Logger::Logger::LevelInfo));
3082 const StartupInitLocos startupInitLocos = static_cast<StartupInitLocos>(Utils::Utils::GetIntegerMapEntry(arguments, "startupinitlocos", StartupInitLocosAll));
3083 const DataModel::AccessoryPulseDuration defaultAccessoryDuration = Utils::Utils::GetIntegerMapEntry(arguments, "duration", manager.GetDefaultAccessoryDuration());
3084 const bool executeAccessory = Utils::Utils::GetBoolMapEntry(arguments, "executeaccessory", manager.GetExecuteAccessory());
3085 const bool autoAddFeedback = Utils::Utils::GetBoolMapEntry(arguments, "autoaddfeedback", manager.GetAutoAddFeedback());
3086 const bool stopOnFeedbackInFreeTrack = Utils::Utils::GetBoolMapEntry(arguments, "stoponfeedbackinfreetrack", manager.GetStopOnFeedbackInFreeTrack());
3087 const DataModel::SelectRouteApproach selectRouteApproach = static_cast<DataModel::SelectRouteApproach>(Utils::Utils::GetIntegerMapEntry(arguments, "selectrouteapproach", DataModel::SelectRouteRandom));
3088 const DataModel::Loco::NrOfTracksToReserve nrOfTracksToReserve = static_cast<DataModel::Loco::NrOfTracksToReserve>(Utils::Utils::GetIntegerMapEntry(arguments, "nroftrackstoreserve", DataModel::Loco::ReserveOne));
3089 manager.SettingsSave(language,
3090 startupInitLocos,
3091 defaultAccessoryDuration,
3092 autoAddFeedback,
3093 stopOnFeedbackInFreeTrack,
3094 executeAccessory,
3095 selectRouteApproach,
3096 nrOfTracksToReserve,
3097 logLevel);
3098 ReplyResponse(ResponseInfo, Languages::TextSettingsSaved);
3099 }
3100
3101 void WebClient::HandleTimestamp(__attribute__((unused)) const map<string, string>& arguments)
3102 {
3103 #ifdef __CYGWIN__
3104 ReplyHtmlWithHeaderAndParagraph(Languages::TextTimestampNotSet);
3105 #else
3106 const time_t timestamp = Utils::Utils::GetIntegerMapEntry(arguments, "timestamp", 0);
3107 if (timestamp == 0)
3108 {
3109 ReplyHtmlWithHeaderAndParagraph(Languages::TextTimestampNotSet);
3110 return;
3111 }
3112 struct timeval tv;
3113 int ret = gettimeofday(&tv, nullptr);
3114 if (ret != 0)
3115 {
3116 ReplyHtmlWithHeaderAndParagraph(Languages::TextTimestampAlreadySet);
3117 return;
3118 }
3119
3120 tv.tv_sec = timestamp;
3121 ret = settimeofday(&tv, nullptr);
3122 if (ret != 0)
3123 {
3124 ReplyHtmlWithHeaderAndParagraph(Languages::TextTimestampNotSet);
3125 return;
3126 }
3127 ReplyHtmlWithHeaderAndParagraph(Languages::TextTimestampSet);
3128 #endif
3129 }
3130
3131 void WebClient::HandleControlArguments(const map<string, string>& arguments)
3132 {
3133 HardwareType hardwareType = static_cast<HardwareType>(Utils::Utils::GetIntegerMapEntry(arguments, "hardwaretype"));
3134 ReplyHtmlWithHeader(WebClientStatic::HtmlTagControlArguments(hardwareType));
3135 }
3136
3137 HtmlTag WebClient::HtmlTagProgramModeSelector(const ControlID controlID, ProgramMode& mode) const
3138 {
3139 Hardware::Capabilities capabilities = manager.GetCapabilities(controlID);
3140 map<ProgramMode, Languages::TextSelector> programModeOptions;
3141 if (capabilities & (Hardware::CapabilityProgramDccDirectRead | Hardware::CapabilityProgramDccDirectWrite))
3142 {
3143 programModeOptions[ProgramModeDccDirect] = Languages::TextProgramModeDccDirect;
3144 if (mode == ProgramModeNone)
3145 {
3146 mode = ProgramModeDccDirect;
3147 }
3148 }
3149 if (capabilities & (Hardware::CapabilityProgramDccPomLocoRead | Hardware::CapabilityProgramDccPomLocoWrite))
3150 {
3151 programModeOptions[ProgramModeDccPomLoco] = Languages::TextProgramModeDccPomLoco;
3152 if (mode == ProgramModeNone)
3153 {
3154 mode = ProgramModeDccPomLoco;
3155 }
3156 }
3157 if (capabilities & (Hardware::CapabilityProgramDccPomAccessoryRead | Hardware::CapabilityProgramDccPomAccessoryWrite))
3158 {
3159 programModeOptions[ProgramModeDccPomAccessory] = Languages::TextProgramModeDccPomAccessory;
3160 if (mode == ProgramModeNone)
3161 {
3162 mode = ProgramModeDccPomAccessory;
3163 }
3164 }
3165 if (capabilities & Hardware::CapabilityProgramMmWrite)
3166 {
3167 programModeOptions[ProgramModeMm] = Languages::TextProgramModeMm;
3168 if (mode == ProgramModeNone)
3169 {
3170 mode = ProgramModeMm;
3171 }
3172 }
3173 if (capabilities & Hardware::CapabilityProgramMmPomWrite)
3174 {
3175 programModeOptions[ProgramModeMmPom] = Languages::TextProgramModeMmPom;
3176 if (mode == ProgramModeNone)
3177 {
3178 mode = ProgramModeMmPom;
3179 }
3180 }
3181 if (capabilities & (Hardware::CapabilityProgramMfxRead | Hardware::CapabilityProgramMfxWrite))
3182 {
3183 programModeOptions[ProgramModeMfx] = Languages::TextProgramModeMfx;
3184 if (mode == ProgramModeNone)
3185 {
3186 mode = ProgramModeMfx;
3187 }
3188 }
3189 if (capabilities & (Hardware::CapabilityProgramDccPageRead | Hardware::CapabilityProgramDccPageWrite))
3190 {
3191 programModeOptions[ProgramModeDccPage] = Languages::TextProgramModeDccPage;
3192 if (mode == ProgramModeNone)
3193 {
3194 mode = ProgramModeDccPage;
3195 }
3196 }
3197 if (capabilities & (Hardware::CapabilityProgramDccRegisterRead | Hardware::CapabilityProgramDccRegisterWrite))
3198 {
3199 programModeOptions[ProgramModeDccRegister] = Languages::TextProgramModeDccRegister;
3200 if (mode == ProgramModeNone)
3201 {
3202 mode = ProgramModeDccRegister;
3203 }
3204 }
3205 return HtmlTagSelectWithLabel("moderaw", Languages::TextProgramMode, programModeOptions, mode).AddAttribute("onchange", "onChangeProgramModeSelector();");
3206 }
3207
3208 HtmlTag WebClient::HtmlTagCvFields(const ControlID controlID, const ProgramMode programMode) const
3209 {
3210 HtmlTag content("div");
3211 content.AddId("cv_fields");
3212 switch (programMode)
3213 {
3214 case ProgramModeMmPom:
3215 content.AddChildTag(HtmlTagInputIntegerWithLabel("addressraw", Languages::TextAddress, 1, 1, 0xFF));
3216 break;
3217
3218 case ProgramModeMfx:
3219 case ProgramModeDccPomLoco:
3220 case ProgramModeDccPomAccessory:
3221 content.AddChildTag(HtmlTagInputIntegerWithLabel("addressraw", Languages::TextAddress, 1, 1, 0x4000));
3222 break;
3223
3224 default:
3225 content.AddChildTag(HtmlTagInputHidden("addressraw", "0"));
3226 break;
3227 }
3228
3229 switch (programMode)
3230 {
3231 case ProgramModeMfx:
3232 content.AddChildTag(HtmlTagInputIntegerWithLabel("indexraw", Languages::TextIndex, 0, 0, 0x3F));
3233 break;
3234
3235 default:
3236 content.AddChildTag(HtmlTagInputHidden("indexraw", "0"));
3237 break;
3238 }
3239
3240 switch (programMode)
3241 {
3242 case ProgramModeMm:
3243 case ProgramModeMmPom:
3244 content.AddChildTag(HtmlTagInputIntegerWithLabel("cvraw", Languages::TextCV, 1, 1, 256));
3245 break;
3246
3247 default:
3248 content.AddChildTag(HtmlTagInputIntegerWithLabel("cvraw", Languages::TextCV, 1, 1, 1024));
3249 break;
3250 }
3251
3252 content.AddChildTag(HtmlTagInputIntegerWithLabel("valueraw", Languages::TextValue, 0, 0, 255));
3253
3254 content.AddChildTag(HtmlTag("br"));
3255 content.AddChildTag(HtmlTagInput8BitValueWithLabel());
3256 content.AddChildTag(HtmlTag("br"));
3257
3258 Hardware::Capabilities capabilities = manager.GetCapabilities(controlID);
3259 if (((programMode == ProgramModeMm) && (capabilities & Hardware::CapabilityProgramMmWrite))
3260 || ((programMode == ProgramModeMmPom) && (capabilities & Hardware::CapabilityProgramMmPomWrite))
3261 || ((programMode == ProgramModeMfx) && (capabilities & Hardware::CapabilityProgramMfxWrite))
3262 || ((programMode == ProgramModeDccRegister) && (capabilities & Hardware::CapabilityProgramDccRegisterWrite))
3263 || ((programMode == ProgramModeDccPage) && (capabilities & Hardware::CapabilityProgramDccPageWrite))
3264 || ((programMode == ProgramModeDccDirect) && (capabilities & Hardware::CapabilityProgramDccDirectWrite))
3265 || ((programMode == ProgramModeDccPomLoco) && (capabilities & Hardware::CapabilityProgramDccPomLocoWrite))
3266 || ((programMode == ProgramModeDccPomAccessory) && (capabilities & Hardware::CapabilityProgramDccPomAccessoryWrite)))
3267 {
3268 HtmlTagButton writeButton(Languages::TextWrite, "programwrite");
3269 writeButton.AddAttribute("onclick", "onClickProgramWrite();return false;");
3270 writeButton.AddClass("wide_button");
3271 content.AddChildTag(writeButton);
3272 }
3273
3274 if (((programMode == ProgramModeMfx) && (capabilities & Hardware::CapabilityProgramMfxRead))
3275 || ((programMode == ProgramModeDccRegister) && (capabilities & Hardware::CapabilityProgramDccRegisterRead))
3276 || ((programMode == ProgramModeDccPage) && (capabilities & Hardware::CapabilityProgramDccPageRead))
3277 || ((programMode == ProgramModeDccDirect) && (capabilities & Hardware::CapabilityProgramDccDirectRead))
3278 || ((programMode == ProgramModeDccPomLoco) && (capabilities & Hardware::CapabilityProgramDccPomLocoRead))
3279 || ((programMode == ProgramModeDccPomAccessory) && (capabilities & Hardware::CapabilityProgramDccPomAccessoryRead)))
3280 {
3281 HtmlTagButton readButton(Languages::TextRead, "programread");
3282 readButton.AddAttribute("onclick", "onClickProgramRead();return false;");
3283 readButton.AddClass("wide_button");
3284 content.AddChildTag(readButton);
3285 }
3286
3287 return content;
3288 }
3289
3290 void WebClient::HandleCvFields(const map<string, string>& arguments)
3291 {
3292 ControlID controlID = static_cast<ControlID>(Utils::Utils::GetIntegerMapEntry(arguments, "control", ControlNone));
3293 ProgramMode programMode = static_cast<ProgramMode>(Utils::Utils::GetIntegerMapEntry(arguments, "mode", ProgramModeNone));
3294 ReplyHtmlWithHeader(HtmlTagCvFields(controlID, programMode));
3295 }
3296
3297 HtmlTag WebClient::HtmlTagInput8BitValueWithLabel() const
3298 {
3299 HtmlTag content;
3300 content.AddChildTag(HtmlTagLabel(Languages::TextValue, "valueraw0"));
3301 content.AddChildTag(HtmlTagInputBitValue("valueraw7"));
3302 content.AddChildTag(HtmlTagInputBitValue("valueraw6"));
3303 content.AddChildTag(HtmlTagInputBitValue("valueraw5"));
3304 content.AddChildTag(HtmlTagInputBitValue("valueraw4"));
3305 content.AddChildTag(HtmlTagInputBitValue("valueraw3"));
3306 content.AddChildTag(HtmlTagInputBitValue("valueraw2"));
3307 content.AddChildTag(HtmlTagInputBitValue("valueraw1"));
3308 content.AddChildTag(HtmlTagInputBitValue("valueraw0"));
3309 return content;
3310 }
3311
3312 HtmlTag WebClient::HtmlTagInputBitValue(string name) const
3313 {
3314 HtmlTagInputCheckbox checkbox(name, name);
3315 checkbox.AddAttribute("onclick", "updateCvValue();");
3316 return checkbox;
3317 }
3318
3319 void WebClient::HandleProgram()
3320 {
3321 HtmlTag content;
3322 content.AddChildTag(HtmlTag("h1").AddContent(Languages::TextProgrammer));
3323 HtmlTag tabMenu("div");
3324 tabMenu.AddChildTag(WebClientStatic::HtmlTagTabMenuItem("raw", Languages::TextDirect, true));
3325 std::map<ControlID,string> controls = manager.ControlListNames(Hardware::CapabilityProgram);
3326 if (controls.size() == 0)
3327 {
3328 ReplyHtmlWithHeader(HtmlTag("p").AddContent(Languages::TextNoControlSupportsProgramming));
3329 return;
3330 }
3331 /* FIXME: Tab MM and Tab DCC incomplete
3332 unsigned int controlCountMm = 0;
3333 unsigned int controlCountDcc = 0;
3334 for (auto control : controls)
3335 {
3336 Hardware::Capabilities capabilities = manager.GetCapabilities(control.first);
3337 if (capabilities & Hardware::CapabilityProgramMmWrite)
3338 {
3339 ++controlCountMm;
3340 }
3341 if (capabilities & (Hardware::CapabilityProgramDccDirectRead | Hardware::CapabilityProgramDccDirectWrite))
3342 {
3343 ++controlCountDcc;
3344 }
3345 }
3346
3347 if (controlCountMm > 0)
3348 {
3349 tabMenu.AddChildTag(WebClientStatic::HtmlTagTabMenuItem("mm", Languages::TextMaerklinMotorola));
3350 }
3351 if (controlCountDcc > 0)
3352 {
3353 tabMenu.AddChildTag(WebClientStatic::HtmlTagTabMenuItem("dcc", Languages::TextDcc));
3354 }
3355 */
3356 content.AddChildTag(tabMenu);
3357
3358 HtmlTag programContent("div");
3359 programContent.AddClass("popup_content");
3360
3361 HtmlTag rawContent("div");
3362 rawContent.AddId("tab_raw");
3363 rawContent.AddClass("tab_content");
3364 rawContent.AddClass("narrow_label");
3365 HtmlTag controlSelector = WebClientStatic::HtmlTagControl("controlraw", controls);
3366 rawContent.AddChildTag(controlSelector);
3367
3368 const ControlID controlIdFirst = controls.begin()->first;
3369 HtmlTag programModeSelector("div");
3370 programModeSelector.AddId("program_mode_selector");
3371 ProgramMode programMode = ProgramModeNone;
3372 programModeSelector.AddChildTag(HtmlTagProgramModeSelector(controlIdFirst, programMode));
3373 rawContent.AddChildTag(programModeSelector);
3374 rawContent.AddChildTag(HtmlTagCvFields(controlIdFirst, programMode));
3375 programContent.AddChildTag(rawContent);
3376
3377 /* FIXME: Tab MM incomplete
3378 HtmlTag mmContent("div");
3379 mmContent.AddId("tab_mm");
3380 mmContent.AddClass("tab_content");
3381 mmContent.AddClass("hidden");
3382 mmContent.AddContent("MM");
3383 programContent.AddChildTag(mmContent);
3384 */
3385
3386 /* FIXME: Tab DCC incomplete
3387 HtmlTag dccContent("div");
3388 dccContent.AddId("tab_dcc");
3389 dccContent.AddClass("tab_content");
3390 dccContent.AddClass("hidden");
3391 dccContent.AddContent("DCC");
3392 programContent.AddChildTag(dccContent);
3393 */
3394
3395 content.AddChildTag(programContent);
3396 content.AddChildTag(HtmlTagButtonCancel());
3397 ReplyHtmlWithHeader(content);
3398 }
3399
3400 void WebClient::HandleProgramModeSelector(const map<string, string>& arguments)
3401 {
3402 ControlID controlID = static_cast<ControlID>(Utils::Utils::GetIntegerMapEntry(arguments, "control"));
3403 ProgramMode mode = static_cast<ProgramMode>(Utils::Utils::GetIntegerMapEntry(arguments, "mode"));
3404 return ReplyHtmlWithHeader(HtmlTagProgramModeSelector(controlID, mode));
3405 }
3406
3407 void WebClient::HandleProgramRead(const map<string, string>& arguments)
3408 {
3409 ControlID controlID = static_cast<ControlID>(Utils::Utils::GetIntegerMapEntry(arguments, "control"));
3410 CvNumber cv = static_cast<CvNumber>(Utils::Utils::GetIntegerMapEntry(arguments, "cv"));
3411 ProgramMode mode = static_cast<ProgramMode>(Utils::Utils::GetIntegerMapEntry(arguments, "mode"));
3412 switch (mode)
3413 {
3414 case ProgramModeDccRegister:
3415 case ProgramModeDccPage:
3416 case ProgramModeDccDirect:
3417 manager.ProgramRead(controlID, mode, 0, cv);
3418 break;
3419
3420 case ProgramModeDccPomLoco:
3421 case ProgramModeDccPomAccessory:
3422 case ProgramModeMfx:
3423 {
3424 Address address = static_cast<Address>(Utils::Utils::GetIntegerMapEntry(arguments, "address"));
3425 manager.ProgramRead(controlID, mode, address, cv);
3426 break;
3427 }
3428
3429 default:
3430 break;
3431 }
3432 ReplyHtmlWithHeaderAndParagraph(Languages::TextProgramDccDirectRead, cv);
3433 }
3434
3435 void WebClient::HandleProgramWrite(const map<string, string>& arguments)
3436 {
3437 ControlID controlID = static_cast<ControlID>(Utils::Utils::GetIntegerMapEntry(arguments, "control"));
3438 ProgramMode mode = static_cast<ProgramMode>(Utils::Utils::GetIntegerMapEntry(arguments, "mode"));
3439 CvNumber cv = static_cast<CvNumber>(Utils::Utils::GetIntegerMapEntry(arguments, "cv"));
3440 CvValue value = static_cast<CvValue>(Utils::Utils::GetIntegerMapEntry(arguments, "value"));
3441 switch (mode)
3442 {
3443 case ProgramModeMm:
3444 case ProgramModeDccRegister:
3445 case ProgramModeDccPage:
3446 case ProgramModeDccDirect:
3447 manager.ProgramWrite(controlID, mode, 0, cv, value);
3448 break;
3449
3450 case ProgramModeMmPom:
3451 case ProgramModeDccPomLoco:
3452 case ProgramModeDccPomAccessory:
3453 case ProgramModeMfx:
3454 {
3455 Address address = static_cast<Address>(Utils::Utils::GetIntegerMapEntry(arguments, "address"));
3456 manager.ProgramWrite(controlID, mode, address, cv, value);
3457 break;
3458 }
3459
3460 default:
3461 break;
3462 }
3463 ReplyHtmlWithHeaderAndParagraph(Languages::TextProgramDccDirectWrite, cv, value);
3464 }
3465
3466 void WebClient::HandleUpdater(const map<string, string>& headers)
3467 {
3468 Response response;
3469 response.AddHeader("Cache-Control", "no-cache, must-revalidate");
3470 response.AddHeader("Pragma", "no-cache");
3471 response.AddHeader("Expires", "Sun, 12 Feb 2016 00:00:00 GMT");
3472 response.AddHeader("Content-Type", "text/event-stream; charset=utf-8");
3473 int ret = connection->Send(response);
3474 if (ret <= 0)
3475 {
3476 return;
3477 }
3478
3479 unsigned int updateID = Utils::Utils::GetIntegerMapEntry(headers, "Last-Event-ID", 1);
3480 while(run)
3481 {
3482 string s;
3483 bool ok = server.NextUpdate(updateID, s);
3484 if (!ok)
3485 {
3486 // FIXME: use signaling instead of sleep
3487 Utils::Utils::SleepForMilliseconds(100);
3488 continue;
3489 }
3490
3491 string reply("id: ");
3492 reply += to_string(updateID);
3493 reply += "\r\n";
3494 reply += s;
3495 reply += "\r\n\r\n";
3496
3497 ++updateID;
3498
3499 ret = connection->Send(reply);
3500 if (ret < 0)
3501 {
3502 return;
3503 }
3504 }
3505 }
3506
3507 HtmlTag WebClient::HtmlTagLocoSelector(const string& selector, const LocoID locoID) const
3508 {
3509 map<string,LocoID> options = manager.LocoBaseIdsByName();
3510 if (options.size() != 1)
3511 {
3512 options["-"] = LocoNone;
3513 }
3514 return HtmlTagSelect("loco_" + selector, options, locoID).AddAttribute("onchange", "loadLoco(" + selector + ");");
3515 }
3516
3517 void WebClient::HandleLoco(const map<string, string>& arguments)
3518 {
3519 string content;
3520 const LocoID locoID = Utils::Utils::GetIntegerMapEntry(arguments, "loco", LocoNone);
3521 const ObjectIdentifier locoBaseIdentifier(WebClientStatic::LocoIdToObjectIdentifier(locoID));
3522 if (!locoBaseIdentifier.IsSet())
3523 {
3524 ReplyHtmlWithHeaderAndParagraph(Languages::TextPleaseSelectLoco);
3525 return;
3526 }
3527 LocoBase* locoBase = manager.GetLocoBase(locoBaseIdentifier);
3528 if (locoBase == nullptr)
3529 {
3530 ReplyHtmlWithHeaderAndParagraph(Languages::TextLocoDoesNotExist);
3531 return;
3532 }
3533 HtmlTag container("div");
3534 container.AddAttribute("class", "inner_loco");
3535 container.AddChildTag(HtmlTag("p").AddId("loconame").AddContent(locoBase->GetName()));
3536 unsigned int speed = locoBase->GetSpeed();
3537 map<string, string> buttonArguments;
3538 buttonArguments["loco"] = to_string(locoID);
3539
3540 string id = "locospeed_" + to_string(locoID);
3541 container.AddChildTag(HtmlTagInputSliderLocoSpeed(id, MinSpeed, locoBase->GetMaxSpeed(), speed, locoID));
3542 buttonArguments["speed"] = to_string(MinSpeed);
3543 container.AddChildTag(HtmlTagButtonCommand("0", id + "_0", buttonArguments));
3544 buttonArguments["speed"] = to_string(locoBase->GetCreepingSpeed());
3545 container.AddChildTag(HtmlTagButtonCommand("I", id + "_1", buttonArguments));
3546 buttonArguments["speed"] = to_string(locoBase->GetReducedSpeed());
3547 container.AddChildTag(HtmlTagButtonCommand("II", id + "_2", buttonArguments));
3548 buttonArguments["speed"] = to_string(locoBase->GetTravelSpeed());
3549 container.AddChildTag(HtmlTagButtonCommand("III", id + "_3", buttonArguments));
3550 buttonArguments["speed"] = to_string(locoBase->GetMaxSpeed());
3551 container.AddChildTag(HtmlTagButtonCommand("IV", id + "_4", buttonArguments));
3552 buttonArguments.erase("speed");
3553
3554 if (locoBaseIdentifier.GetObjectType() == ObjectTypeMultipleUnit)
3555 {
3556 id = "multipleunitedit_" + to_string(locoBaseIdentifier.GetObjectID());
3557 buttonArguments["multipleunit"] = to_string(locoBaseIdentifier.GetObjectID());
3558 }
3559 else
3560 {
3561 id = "locoedit_" + to_string(locoID);
3562 }
3563 container.AddChildTag(HtmlTagButtonPopup("<svg width=\"36\" height=\"36\"><circle r=\"7\" cx=\"14\" cy=\"14\" fill=\"black\" /><line x1=\"14\" y1=\"5\" x2=\"14\" y2=\"23\" stroke-width=\"2\" stroke=\"black\" /><line x1=\"9.5\" y1=\"6.2\" x2=\"18.5\" y2=\"21.8\" stroke-width=\"2\" stroke=\"black\" /><line x1=\"6.2\" y1=\"9.5\" x2=\"21.8\" y2=\"18.5\" stroke-width=\"2\" stroke=\"black\" /><line y1=\"14\" x1=\"5\" y2=\"14\" x2=\"23\" stroke-width=\"2\" stroke=\"black\" /><line x1=\"9.5\" y1=\"21.8\" x2=\"18.5\" y2=\"6.2\" stroke-width=\"2\" stroke=\"black\" /><line x1=\"6.2\" y1=\"18.5\" x2=\"21.8\" y2=\"9.5\" stroke-width=\"2\" stroke=\"black\" /><circle r=\"5\" cx=\"14\" cy=\"14\" fill=\"lightgray\" /><circle r=\"4\" cx=\"24\" cy=\"24\" fill=\"black\" /><line x1=\"18\" y1=\"24\" x2=\"30\" y2=\"24\" stroke-width=\"2\" stroke=\"black\" /><line x1=\"28.2\" y1=\"28.2\" x2=\"19.8\" y2=\"19.8\" stroke-width=\"2\" stroke=\"black\" /><line x1=\"24\" y1=\"18\" x2=\"24\" y2=\"30\" stroke-width=\"2\" stroke=\"black\" /><line x1=\"19.8\" y1=\"28.2\" x2=\"28.2\" y2=\"19.8\" stroke-width=\"2\" stroke=\"black\" /><circle r=\"2\" cx=\"24\" cy=\"24\" fill=\"lightgray\" /></svg>", id, buttonArguments));
3564 if (locoBaseIdentifier.GetObjectType() == ObjectTypeMultipleUnit)
3565 {
3566 buttonArguments.erase("multipleunit");
3567 }
3568
3569 id = "locoorientation_" + to_string(locoID);
3570 container.AddChildTag(HtmlTagButtonCommandToggle("<svg width=\"36\" height=\"36\">"
3571 "<polyline points=\"5,15 31,15 31,23 5,23\" stroke=\"black\" stroke-width=\"0\" fill=\"black\" />"
3572 "<polyline points=\"16,8 0,19 16,30\" stroke=\"black\" stroke-width=\"0\" fill=\"black\" class=\"orientation_left\" />"
3573 "<polyline points=\"20,8 36,19 20,30\" stroke=\"black\" stroke-width=\"0\" fill=\"black\" class=\"orientation_right\" />"
3574 "</svg>", id, locoBase->GetOrientation(), buttonArguments).AddClass("button_orientation"));
3575
3576 id = "locofunction_" + to_string(locoID);
3577 std::vector<DataModel::LocoFunctionEntry> functions = locoBase->GetFunctionStates();
3578 for (DataModel::LocoFunctionEntry& function : functions)
3579 {
3580 string nrText(to_string(function.nr));
3581 buttonArguments["function"] = nrText;
3582 switch(function.type)
3583 {
3584 case DataModel::LocoFunctionTypeMoment:
3585 container.AddChildTag(HtmlTagButtonCommandPressRelease(DataModel::LocoFunctions::GetLocoFunctionIcon(function.nr, function.icon), id + "_" + nrText, buttonArguments));
3586 break;
3587
3588 default:
3589 container.AddChildTag(HtmlTagButtonCommandToggle(DataModel::LocoFunctions::GetLocoFunctionIcon(function.nr, function.icon), id + "_" + nrText, function.state, buttonArguments));
3590 break;
3591 }
3592 }
3593 buttonArguments.erase("function");
3594 container.AddChildTag(HtmlTagInputHidden("loco", to_string(locoID)).AddId("loco"));
3595 ReplyHtmlWithHeader(container);
3596 }
3597
3598 void WebClient::HandleNewPosition(const map<string, string>& arguments)
3599 {
3600 string result;
3601 HandleNewPositionInternal(arguments, result);
3602 ReplyHtmlWithHeaderAndParagraph(result);
3603 }
3604
3605 void WebClient::HandleNewPositionInternal(const map<string, string>& arguments, string& result)
3606 {
3607 const LayoutPosition posX = static_cast<LayoutPosition>(Utils::Utils::GetIntegerMapEntry(arguments, "x", -1));
3608 if (posX == -1)
3609 {
3610 return;
3611 }
3612
3613 const LayoutPosition posY = static_cast<LayoutPosition>(Utils::Utils::GetIntegerMapEntry(arguments, "y", -1));
3614 if (posY == -1)
3615 {
3616 return;
3617 }
3618
3619 manager.LayoutItemNewPosition(ObjectIdentifier(arguments), posX, posY, result);
3620 }
3621
3622 void WebClient::HandleRotate(const map<string, string>& arguments)
3623 {
3624 string result;
3625 manager.LayoutItemRotate(ObjectIdentifier(arguments), result);
3626 ReplyHtmlWithHeaderAndParagraph(result);
3627 }
3628
3629 void WebClient::PrintMainHTML() {
3630 // handle base request
3631 HtmlTag body("body");
3632 body.AddAttribute("onload", "startUp();");
3633 body.AddId("body");
3634
3635 map<string,string> buttonArguments;
3636
3637 HtmlTag menu("div");
3638 menu.AddClass("menu");
3639 HtmlTag menuMain("div");
3640 menuMain.AddClass("menu_main");
3641 menuMain.AddChildTag(HtmlTagButtonPopup("<svg width=\"36\" height=\"36\"><polygon points=\"16,1.5 31,1.5 31,25.5 16,25.5\" fill=\"white\" style=\"stroke:black;stroke-width:1;\"/><polygon points=\"21,11.5 31,1.5 31,25.5 21,35.5\" fill=\"black\" style=\"stroke:black;stroke-width:1;\"/><polygon points=\"1,11 8.5,11 8.5,6 16,13.5 8.5,21 8.5,16 1,16\"/></svg>", "askshutdown", Languages::TextExitRailControl));
3642 menuMain.AddChildTag(HtmlTagButtonCommandToggle("<svg width=\"36\" height=\"36\"><polyline points=\"13.5,9.8 12.1,10.8 10.8,12.1 9.8,13.5 9.1,15.1 8.7,16.8 8.5,18.5 8.7,20.2 9.1,21.9 9.8,23.5 10.8,24.9 12.1,26.2 13.5,27.2 15.1,27.9 16.8,28.3 18.5,28.5 20.2,28.3 21.9,27.9 23.5,27.2 24.9,26.2 26.2,24.9 27.2,23.5 27.9,21.9 28.3,20.2 28.5,18.5 28.3,16.8 27.9,15.1 27.2,13.5 26.2,12.1 24.9,10.8 23.5,9.8\" stroke=\"black\" stroke-width=\"3\" fill=\"none\"/><polyline points=\"18.5,3.5 18.5,16\" stroke=\"black\" stroke-width=\"3\" fill=\"none\"/></svg>", "booster", manager.Booster(), Languages::TextTurningBoosterOnOrOff).AddClass("button_booster"));
3643 menuMain.AddChildTag(HtmlTagButtonCommand("<svg width=\"36\" height=\"36\"><polyline points=\"2,12 2,11 11,2 26,2 35,11 35,26 26,35 11,35 2,26 2,12\" stroke=\"black\" stroke-width=\"1\" fill=\"red\"/><text x=\"4\" y=\"22\" fill=\"white\" font-size=\"11\">STOP</text></svg>", "stopallimmediately", Languages::TextStopAllLocos));
3644 menuMain.AddChildTag(HtmlTagButtonCommand("<svg width=\"36\" height=\"36\"><polygon points=\"17,36 17,28 15,28 10,23 10,5 15,0 21,0 26,5 26,23 21,28 19,28 19,36\" fill=\"black\" /><circle cx=\"18\" cy=\"8\" r=\"4\" fill=\"red\" /><circle cx=\"18\" cy=\"20\" r=\"4\" fill=\"darkgray\" /></svg>", "stopall", Languages::TextSetAllLocosToManualMode));
3645 menuMain.AddChildTag(HtmlTagButtonCommand("<svg width=\"36\" height=\"36\"><polygon points=\"17,36 17,28 15,28 10,23 10,5 15,0 21,0 26,5 26,23 21,28 19,28 19,36\" fill=\"black\" /><circle cx=\"18\" cy=\"8\" r=\"4\" fill=\"darkgray\" /><circle cx=\"18\" cy=\"20\" r=\"4\" fill=\"green\" /></svg>", "startall", Languages::TextSetAllLocosToAutomode));
3646 menuMain.AddChildTag(HtmlTag().AddContent("&nbsp;&nbsp;"));
3647 menu.AddChildTag(menuMain);
3648
3649 HtmlTag menuAdd("div");
3650 menuAdd.AddClass("menu_add");
3651 menuAdd.AddChildTag(HtmlTagButtonCommandFullScreen());
3652 menuAdd.AddChildTag(HtmlTag().AddContent("&nbsp;&nbsp;"));
3653 menuAdd.AddChildTag(HtmlTagButtonPopup("<svg width=\"36\" height=\"36\"><circle r=\"7\" cx=\"14\" cy=\"14\" fill=\"black\" /><line x1=\"14\" y1=\"5\" x2=\"14\" y2=\"23\" stroke-width=\"2\" stroke=\"black\" /><line x1=\"9.5\" y1=\"6.2\" x2=\"18.5\" y2=\"21.8\" stroke-width=\"2\" stroke=\"black\" /><line x1=\"6.2\" y1=\"9.5\" x2=\"21.8\" y2=\"18.5\" stroke-width=\"2\" stroke=\"black\" /><line y1=\"14\" x1=\"5\" y2=\"14\" x2=\"23\" stroke-width=\"2\" stroke=\"black\" /><line x1=\"9.5\" y1=\"21.8\" x2=\"18.5\" y2=\"6.2\" stroke-width=\"2\" stroke=\"black\" /><line x1=\"6.2\" y1=\"18.5\" x2=\"21.8\" y2=\"9.5\" stroke-width=\"2\" stroke=\"black\" /><circle r=\"5\" cx=\"14\" cy=\"14\" fill=\"white\" /><circle r=\"4\" cx=\"24\" cy=\"24\" fill=\"black\" /><line x1=\"18\" y1=\"24\" x2=\"30\" y2=\"24\" stroke-width=\"2\" stroke=\"black\" /><line x1=\"28.2\" y1=\"28.2\" x2=\"19.8\" y2=\"19.8\" stroke-width=\"2\" stroke=\"black\" /><line x1=\"24\" y1=\"18\" x2=\"24\" y2=\"30\" stroke-width=\"2\" stroke=\"black\" /><line x1=\"19.8\" y1=\"28.2\" x2=\"28.2\" y2=\"19.8\" stroke-width=\"2\" stroke=\"black\" /><circle r=\"2\" cx=\"24\" cy=\"24\" fill=\"white\" /></svg>", "settingsedit", Languages::TextEditSettings));
3654 menuAdd.AddChildTag(HtmlTag().AddContent("&nbsp;&nbsp;"));
3655 if (manager.CanHandle(Hardware::CapabilityProgram))
3656 {
3657 menuAdd.AddChildTag(HtmlTagButtonPopup("<svg width=\"36\" height=\"36\"><polyline points=\"1,5 35,5\" stroke=\"black\" stroke-width=\"1\" /><polyline points=\"1,16 35,16\" stroke=\"black\" stroke-width=\"1\" /><polyline points=\"3,3 3,18\" stroke=\"black\" stroke-width=\"1\" /><polyline points=\"6,3 6,18\" stroke=\"black\" stroke-width=\"1\" /><polyline points=\"9,3 9,18\" stroke=\"black\" stroke-width=\"1\" /><polyline points=\"12,3 12,18\" stroke=\"black\" stroke-width=\"1\" /><polyline points=\"15,3 15,18\" stroke=\"black\" stroke-width=\"1\" /><polyline points=\"18,3 18,18\" stroke=\"black\" stroke-width=\"1\" /><polyline points=\"21,3 21,18\" stroke=\"black\" stroke-width=\"1\" /><polyline points=\"24,3 24,18\" stroke=\"black\" stroke-width=\"1\" /><polyline points=\"27,3 27,18\" stroke=\"black\" stroke-width=\"1\" /><polyline points=\"30,3 30,18\" stroke=\"black\" stroke-width=\"1\" /><polyline points=\"33,3 33,18\" stroke=\"black\" stroke-width=\"1\" /><text x=\"3\" y=\"31\" fill=\"black\" >Prog</text></svg>", "program", Languages::TextProgrammer));
3658 menuAdd.AddChildTag(HtmlTag().AddContent("&nbsp;&nbsp;"));
3659 }
3660 menu.AddChildTag(menuAdd);
3661
3662 HtmlTag menuConfigButton("div");
3663 menuConfigButton.AddClass("menu_configbutton");
3664 menuConfigButton.AddId("menu_configbutton");
3665 menuConfigButton.AddChildTag(HtmlTagButton("<svg width=\"36\" height=\"36\"><polyline points=\"5,11 31,11\" stroke=\"black\" stroke-width=\"3\"/><polyline points=\"5,18 31,18\" stroke=\"black\" stroke-width=\"3\"/><polyline points=\"5,25 31,25\" stroke=\"black\" stroke-width=\"3\"/></svg>", "showmenuconfig", Languages::TextConfigMenu).AddAttribute("onclick", "showMenuConfig(); return false;").AddClass("button_menuconfig"));
3666 menuConfigButton.AddChildTag(HtmlTag().AddContent("&nbsp;&nbsp;"));
3667 menu.AddChildTag(menuConfigButton);
3668
3669 HtmlTag menuConfig("div");
3670 menuConfig.AddClass("menu_config");
3671 menuConfig.AddId("menu_config");
3672 menuConfig.AddChildTag(HtmlTagButtonPopup("<svg width=\"36\" height=\"36\"><polygon points=\"11,1.5 26,1.5 26,35.5 11,35.5\" fill=\"white\" style=\"stroke:black;stroke-width:1;\"/><polygon points=\"14,4.5 23,4.5 23,8.5 14,8.5\" fill=\"white\" style=\"stroke:black;stroke-width:1;\"/><circle cx=\"15.5\" cy=\"12\" r=\"1\" fill=\"black\"/><circle cx=\"18.5\" cy=\"12\" r=\"1\" fill=\"black\"/><circle cx=\"21.5\" cy=\"12\" r=\"1\" fill=\"black\"/><circle cx=\"15.5\" cy=\"15\" r=\"1\" fill=\"black\"/><circle cx=\"18.5\" cy=\"15\" r=\"1\" fill=\"black\"/><circle cx=\"21.5\" cy=\"15\" r=\"1\" fill=\"black\"/><circle cx=\"15.5\" cy=\"18\" r=\"1\" fill=\"black\"/><circle cx=\"18.5\" cy=\"18\" r=\"1\" fill=\"black\"/><circle cx=\"21.5\" cy=\"18\" r=\"1\" fill=\"black\"/><circle cx=\"15.5\" cy=\"21\" r=\"1\" fill=\"black\"/><circle cx=\"18.5\" cy=\"21\" r=\"1\" fill=\"black\"/><circle cx=\"21.5\" cy=\"21\" r=\"1\" fill=\"black\"/><circle cx=\"18.5\" cy=\"28.5\" r=\"5\" fill=\"black\"/></svg>", "controllist", Languages::TextEditControls));
3673 menuConfig.AddChildTag(HtmlTagButtonPopup("<svg width=\"36\" height=\"36\"><polyline points=\"0,25 35,25\" fill=\"none\" stroke=\"black\"/><polygon points=\"35,22 6,22 5,19 8,10 35,10\" stroke=\"black\" fill=\"black\"/><polygon points=\"10,12 15,12 15,15 9,15\" fill=\"white\"/><polyline points=\"16,9 20,7 16,5\" stroke=\"black\" fill=\"none\"/><circle cx=\"12\" cy=\"22\" r=\"3\"/><circle cx=\"20\" cy=\"22\" r=\"3\"/></svg>", "locolist", Languages::TextEditLocos));
3674 menuConfig.AddChildTag(HtmlTagButtonPopup("<svg width=\"36\" height=\"36\"><polyline points=\"0,25 35,25\" fill=\"none\" stroke=\"black\"/><polygon points=\"0,22 0,10 12,10 15,19 14,22\" stroke=\"black\" fill=\"black\"/><polygon points=\"10,12 11,15 5,15 5,12\" fill=\"white\"/><polyline points=\"8,9 4,7 8,5\" stroke=\"black\" fill=\"none\"/><circle cx=\"8\" cy=\"22\" r=\"3\"/><circle cx=\"0\" cy=\"22\" r=\"3\"/><polygon points=\"35,22 21,22 20,19 23,10 35,10\" stroke=\"black\" fill=\"black\"/><polygon points=\"25,12 30,12 30,15 24,15\" fill=\"white\"/><polyline points=\"27,9 31,7 27,5\" stroke=\"black\" fill=\"none\"/><circle cx=\"27\" cy=\"22\" r=\"3\"/><circle cx=\"35\" cy=\"22\" r=\"3\"/><polyline points=\"0,20 35,20\" fill=\"none\" stroke=\"black\"/></svg>", "multipleunitlist", Languages::TextEditMultipleUnits));
3675 menuConfig.AddChildTag(HtmlTagButtonPopup("<svg width=\"36\" height=\"36\"><polygon points=\"2,31 26,31 35,21 11,21\" fill=\"white\" stroke=\"black\"/><polygon points=\"2,26 26,26 35,16 11,16\" fill=\"white\" stroke=\"black\"/><polygon points=\"2,21 26,21 35,11 11,11\" fill=\"white\" stroke=\"black\"/><polygon points=\"2,16 26,16 35,6 11,6\" fill=\"white\" stroke=\"black\"/></svg>", "layerlist", Languages::TextEditLayers));
3676 menuConfig.AddChildTag(HtmlTagButtonPopup("<svg width=\"36\" height=\"36\"><polyline points=\"1,12 35,12\" stroke=\"black\" stroke-width=\"1\"/><polyline points=\"1,23 35,23\" stroke=\"black\" stroke-width=\"1\"/><polyline points=\"3,10 3,25\" stroke=\"black\" stroke-width=\"1\"/><polyline points=\"6,10 6,25\" stroke=\"black\" stroke-width=\"1\"/><polyline points=\"9,10 9,25\" stroke=\"black\" stroke-width=\"1\"/><polyline points=\"12,10 12,25\" stroke=\"black\" stroke-width=\"1\"/><polyline points=\"15,10 15,25\" stroke=\"black\" stroke-width=\"1\"/><polyline points=\"18,10 18,25\" stroke=\"black\" stroke-width=\"1\"/><polyline points=\"21,10 21,25\" stroke=\"black\" stroke-width=\"1\"/><polyline points=\"24,10 24,25\" stroke=\"black\" stroke-width=\"1\"/><polyline points=\"27,10 27,25\" stroke=\"black\" stroke-width=\"1\"/><polyline points=\"30,10 30,25\" stroke=\"black\" stroke-width=\"1\"/><polyline points=\"33,10 33,25\" stroke=\"black\" stroke-width=\"1\"/></svg>", "tracklist", Languages::TextEditTracks));
3677 menuConfig.AddChildTag(HtmlTagButtonPopup("<svg width=\"36\" height=\"36\"><polyline points=\"1,12 17,12\" stroke=\"black\" stroke-width=\"1\"/><polyline points=\"1,23 17,23\" stroke=\"black\" stroke-width=\"1\"/><polyline points=\"19,12 35,12\" stroke=\"black\" stroke-width=\"1\"/><polyline points=\"19,23 35,23\" stroke=\"black\" stroke-width=\"1\"/><polyline points=\"3,10 3,25\" stroke=\"black\" stroke-width=\"1\"/><polyline points=\"6,10 6,25\" stroke=\"black\" stroke-width=\"1\"/><polyline points=\"9,10 9,25\" stroke=\"black\" stroke-width=\"1\"/><polyline points=\"12,10 12,25\" stroke=\"black\" stroke-width=\"1\"/><polyline points=\"15,10 15,25\" stroke=\"black\" stroke-width=\"1\"/><polyline points=\"21,10 21,25\" stroke=\"black\" stroke-width=\"1\"/><polyline points=\"24,10 24,25\" stroke=\"black\" stroke-width=\"1\"/><polyline points=\"27,10 27,25\" stroke=\"black\" stroke-width=\"1\"/><polyline points=\"30,10 30,25\" stroke=\"black\" stroke-width=\"1\"/><polyline points=\"33,10 33,25\" stroke=\"black\" stroke-width=\"1\"/></svg>", "clusterlist", Languages::TextEditClusters));
3678 menuConfig.AddChildTag(HtmlTagButtonPopup("<svg width=\"36\" height=\"36\"><polyline points=\"1,20 7.1,19.5 13,17.9 18.5,15.3 23.5,11.8 27.8,7.5\" stroke=\"black\" stroke-width=\"1\" fill=\"none\"/><polyline points=\"1,28 8.5,27.3 15.7,25.4 22.5,22.2 28.6,17.9 33.9,12.6\" stroke=\"black\" stroke-width=\"1\" fill=\"none\"/><polyline points=\"1,20 35,20\" stroke=\"black\" stroke-width=\"1\"/><polyline points=\"1,28 35,28\" stroke=\"black\" stroke-width=\"1\"/><polyline points=\"3,18 3,30\" stroke=\"black\" stroke-width=\"1\"/><polyline points=\"6,18 6,30\" stroke=\"black\" stroke-width=\"1\"/><polyline points=\"9,17 9,30\" stroke=\"black\" stroke-width=\"1\"/><polyline points=\"12,16 12,30\" stroke=\"black\" stroke-width=\"1\"/><polyline points=\"15,15 15,30\" stroke=\"black\" stroke-width=\"1\"/><polyline points=\"18,13 18,30\" stroke=\"black\" stroke-width=\"1\"/><polyline points=\"21,12 21,30\" stroke=\"black\" stroke-width=\"1\"/><polyline points=\"24,9 24,30\" stroke=\"black\" stroke-width=\"1\"/><polyline points=\"27,17 27,30\" stroke=\"black\" stroke-width=\"1\"/><polyline points=\"30,18 30,30\" stroke=\"black\" stroke-width=\"1\"/><polyline points=\"33,18 33,30\" stroke=\"black\" stroke-width=\"1\"/><polyline points=\"24,9 32,17\" stroke=\"black\" stroke-width=\"1\"/><polyline points=\"26,7 34,15\" stroke=\"black\" stroke-width=\"1\"/></svg>", "switchlist", Languages::TextEditSwitches));
3679 menuConfig.AddChildTag(HtmlTagButtonPopup("<svg width=\"36\" height=\"36\"><polygon points=\"17,36 17,28 15,28 10,23 10,5 15,0 21,0 26,5 26,23 21,28 19,28 19,36\" fill=\"black\" /><circle cx=\"18\" cy=\"8\" r=\"4\" fill=\"red\" /><circle cx=\"18\" cy=\"20\" r=\"4\" fill=\"green\" /></svg>", "signallist", Languages::TextEditSignals));
3680 menuConfig.AddChildTag(HtmlTagButtonPopup("<svg width=\"36\" height=\"36\"><polyline points=\"1,20 10,20 30,15\" stroke=\"black\" stroke-width=\"1\" fill=\"none\"/><polyline points=\"28,17 28,20 34,20\" stroke=\"black\" stroke-width=\"1\" fill=\"none\"/></svg>", "accessorylist", Languages::TextEditAccessories));
3681 menuConfig.AddChildTag(HtmlTagButtonPopup("<svg width=\"36\" height=\"36\"><polyline points=\"1,25 35,25\" fill=\"none\" stroke=\"black\"/><polygon points=\"4,25 4,23 8,23 8,25\" fill=\"black\" stroke=\"black\"/><polygon points=\"35,22 16,22 15,19 18,10 35,10\" stroke=\"black\" fill=\"black\"/><polygon points=\"20,12 25,12 25,15 19,15\" fill=\"white\"/><polyline points=\"26,10 30,8 26,6\" stroke=\"black\" fill=\"none\"/><circle cx=\"22\" cy=\"22\" r=\"3\"/><circle cx=\"30\" cy=\"22\" r=\"3\"/></svg>", "feedbacklist", Languages::TextEditFeedbacks));
3682 menuConfig.AddChildTag(HtmlTagButtonPopup("<svg width=\"36\" height=\"36\"><polyline points=\"5,34 15,1\" stroke=\"black\" stroke-width=\"1\" fill=\"none\"/><polyline points=\"31,34 21,1\" stroke=\"black\" stroke-width=\"1\" fill=\"none\"/><polyline points=\"18,34 18,30\" stroke=\"black\" stroke-width=\"1\" fill=\"none\"/><polyline points=\"18,24 18,20\" stroke=\"black\" stroke-width=\"1\" fill=\"none\"/><polyline points=\"18,14 18,10\" stroke=\"black\" stroke-width=\"1\" fill=\"none\"/><polyline points=\"18,4 18,1\" stroke=\"black\" stroke-width=\"1\" fill=\"none\"/></svg>", "routelist", Languages::TextEditRoutes));
3683 menuConfig.AddChildTag(HtmlTagButtonPopup("<svg width=\"36\" height=\"36\"><text x=\"4\" y=\"22\" fill=\"black\" font-size=\"15\">1 2</text></svg>", "counterlist", Languages::TextEditCounters));
3684 menuConfig.AddChildTag(HtmlTagButtonPopup("<svg width=\"36\" height=\"36\"><text x=\"4\" y=\"22\" fill=\"black\" font-size=\"15\">Text</text></svg>", "textlist", Languages::TextEditTexts));
3685 menu.AddChildTag(menuConfig);
3686
3687 body.AddChildTag(menu);
3688
3689 const unsigned int MaxNumberOfLocoControls = 5;
3690 for (unsigned int numberOfLocoControl = 1; numberOfLocoControl <= MaxNumberOfLocoControls; ++numberOfLocoControl)
3691 {
3692 const string numberOfLocoControlText = to_string(numberOfLocoControl);
3693 HtmlTag locoContainer("div");
3694 locoContainer.AddClass("loco_container");
3695 locoContainer.AddId("loco_container_" + numberOfLocoControlText);
3696
3697 HtmlTag locoSelector("div");
3698 locoSelector.AddClass("loco_selector");
3699 locoSelector.AddClass("loco_selector_" + numberOfLocoControlText);
3700 locoSelector.AddId("loco_selector_" + numberOfLocoControlText);
3701 locoSelector.AddChildTag(HtmlTagLocoSelector(numberOfLocoControlText));
3702 locoContainer.AddChildTag(locoSelector);
3703
3704 HtmlTag loco("div");
3705 loco.AddClass("loco");
3706 loco.AddClass("loco_" + numberOfLocoControlText);
3707 loco.AddId("loco_" + numberOfLocoControlText);
3708 locoContainer.AddChildTag(loco);
3709 if (numberOfLocoControl > 1)
3710 {
3711 locoContainer.AddClass("hidden");
3712 }
3713 body.AddChildTag(locoContainer);
3714 }
3715 body.AddChildTag(HtmlTag("div").AddClass("layer_selector").AddId("layer_selector").AddChildTag(HtmlTagLayerSelector()));
3716 body.AddChildTag(HtmlTag("div").AddClass("layout").AddId("layout")
3717 .AddAttribute("oncontextmenu", "loadLayoutContext(event);")
3718 .AddAttribute("ondragover", "allowDrop(event);")
3719 .AddAttribute("ondrop", "drop(event);")
3720 );
3721 body.AddChildTag(HtmlTag("div").AddClass("reduce_locos").AddId("reduce_locos").AddContent("&lt;").AddAttribute("onclick", "reduceLocos(); return false;"));
3722 body.AddChildTag(HtmlTag("div").AddClass("extend_locos").AddId("extend_locos").AddContent("&gt;").AddAttribute("onclick", "extendLocos(); return false;"));
3723 body.AddChildTag(HtmlTag("div").AddClass("clock").AddId("clock").AddContent("<object data=\"/clock.svg\" class=\"clock2\" type=\"image/svg+xml\"></object>"));
3724 body.AddChildTag(HtmlTag("div").AddClass("status").AddId("status"));
3725 body.AddChildTag(HtmlTag("div").AddClass("popup").AddId("popup"));
3726 body.AddChildTag(HtmlTag("div").AddClass("infobox").AddId("infobox"));
3727
3728 body.AddChildTag(HtmlTag("div").AddClass("contextmenu").AddId("layout_context")
3729 .AddChildTag(HtmlTag("ul").AddClass("contextentries")
3730 .AddChildTag(HtmlTag("li").AddClass("contextentry").AddClass("real_layer_only").AddContent(Languages::GetText(Languages::TextAddTrack)).AddAttribute("onClick", "loadPopup('/?cmd=trackedit&track=0');"))
3731 .AddChildTag(HtmlTag("li").AddClass("contextentry").AddClass("real_layer_only").AddContent(Languages::GetText(Languages::TextAddSwitch)).AddAttribute("onClick", "loadPopup('/?cmd=switchedit&switch=0');"))
3732 .AddChildTag(HtmlTag("li").AddClass("contextentry").AddClass("real_layer_only").AddContent(Languages::GetText(Languages::TextAddSignal)).AddAttribute("onClick", "loadPopup('/?cmd=signaledit&signal=0');"))
3733 .AddChildTag(HtmlTag("li").AddClass("contextentry").AddClass("real_layer_only").AddContent(Languages::GetText(Languages::TextAddAccessory)).AddAttribute("onClick", "loadPopup('/?cmd=accessoryedit&accessory=0');"))
3734 .AddChildTag(HtmlTag("li").AddClass("contextentry").AddContent(Languages::GetText(Languages::TextAddFeedback)).AddAttribute("onClick", "loadPopup('/?cmd=feedbackedit&feedback=0');"))
3735 .AddChildTag(HtmlTag("li").AddClass("contextentry").AddClass("real_layer_only").AddContent(Languages::GetText(Languages::TextAddRoute)).AddAttribute("onClick", "loadPopup('/?cmd=routeedit&route=0');"))
3736 .AddChildTag(HtmlTag("li").AddClass("contextentry").AddClass("real_layer_only").AddContent(Languages::GetText(Languages::TextAddText)).AddAttribute("onClick", "loadPopup('/?cmd=textedit&text=0');"))
3737 .AddChildTag(HtmlTag("li").AddClass("contextentry").AddClass("real_layer_only").AddContent(Languages::GetText(Languages::TextAddCounter)).AddAttribute("onClick", "loadPopup('/?cmd=counteredit&counter=0');"))
3738 ));
3739
3740 connection->Send(ResponseHtmlFull("RailControl", body));
3741 }
3742 }} // namespace Server::Web