| 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 <sstream> |
| 22 | |
| 23 | #include "DataModel/Feedback.h" |
| 24 | #include "DataModel/LayoutItem.h" |
| 25 | #include "Server/Web/HtmlTagFeedback.h" |
| 26 | |
| 27 | using std::string; |
| 28 | using std::to_string; |
| 29 | |
| 30 | namespace Server { namespace Web |
| 31 | { |
| 32 | HtmlTagFeedback::HtmlTagFeedback(const DataModel::Feedback* feedback, |
| 33 | const DataModel::LayoutItem::LayoutPosition posX, |
| 34 | const DataModel::LayoutItem::LayoutPosition posY, |
| 35 | const DataModel::FeedbackType feedbackType) |
| 36 | : HtmlTagLayoutItem(dynamic_cast<const DataModel::LayoutItem*>(feedback), posX, posY) |
| 37 | { |
| 38 | switch (feedbackType) |
| 39 | { |
| 40 | case DataModel::FeedbackTypeStraight: |
| 41 | image = "<polygon class=\"track\" points=\"15,0 21,0 21,36 15,36\"/>"; |
| 42 | break; |
| 43 | |
| 44 | case DataModel::FeedbackTypeTurn: |
| 45 | image = "<polygon class=\"track\" points=\"0,21 0,15 21,36 15,36\"/>"; |
| 46 | break; |
| 47 | |
| 48 | case DataModel::FeedbackTypeDefault: |
| 49 | default: |
| 50 | break; |
| 51 | } |
| 52 | image += "<circle r=\"12\" cx=\"18\" cy=\"18\" stroke=\"white\" stroke-width=\"2\" class=\"feedback\"/>"; |
| 53 | |
| 54 | const DataModel::Feedback::FeedbackState state = feedback->GetState(); |
| 55 | |
| 56 | const string& feedbackName = feedback->GetName(); |
| 57 | |
| 58 | string feedbackIdString = to_string(feedback->GetID()); |
| 59 | imageDiv.AddClass("feedback_item"); |
| 60 | imageDiv.AddClass(state == DataModel::Feedback::FeedbackStateOccupied ? "feedback_occupied" : "feedback_free"); |
| 61 | imageDiv.AddAttribute("onclick", "return onClickFeedback(" + feedbackIdString + ");"); |
| 62 | |
| 63 | AddToolTip(feedbackName + " (pin=" + to_string(feedback->GetPin()) + ")"); |
| 64 | AddContextMenuEntry(feedbackName); |
| 65 | AddContextMenuEntry(Languages::TextEditFeedback, "loadPopup('/?cmd=feedbackedit&feedback=" + feedbackIdString + "');"); |
| 66 | AddContextMenuEntry(Languages::TextDeleteFeedback, "loadPopup('/?cmd=feedbackaskdelete&feedback=" + feedbackIdString + "');"); |
| 67 | FinishInit(); |
| 68 | } |
| 69 | }} // namespace Server::Web |