Debian Codegraph @

Server/Web/WebClient.cpp

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