Debian Codegraph @

Server/Web/WebClient.cpp

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