| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
#pragma once |
| 22 |
|
| 23 |
#include <map> |
| 24 |
#include <string> |
| 25 |
|
| 26 |
#include "DataModel/ObjectIdentifier.h" |
| 27 |
#include "Languages.h" |
| 28 |
#include "Server/Web/HtmlTag.h" |
| 29 |
#include "Server/Web/HtmlTagInputHidden.h" |
| 30 |
#include "Server/Web/HtmlTagInputText.h" |
| 31 |
|
| 32 |
namespace Server { namespace Web |
| 33 |
{ |
| 34 |
class HtmlTagSelect : public HtmlTag |
| 35 |
{ |
| 36 |
public: |
| 37 |
HtmlTagSelect() = delete; |
| 38 |
|
| 39 |
HtmlTagSelect(const std::string& name, |
| 40 |
const std::map<std::string,std::string>& options, |
| 41 |
const std::string& defaultValue = ""); |
| 42 |
|
| 43 |
HtmlTagSelect(const std::string& name, |
| 44 |
const std::map<std::string,DataModel::ObjectIdentifier>& options, |
| 45 |
const DataModel::ObjectIdentifier& defaultValue = DataModel::ObjectIdentifier()); |
| 46 |
|
| 47 |
template<typename T> |
| 48 |
HtmlTagSelect(const std::string& name, |
| 49 |
const std::map<std::string,T>& options, |
| 50 |
const int defaultValue = 0) |
| 51 |
: HtmlTagSelect(name) |
| 52 |
{ |
| 53 |
for (auto& option : options) |
| 54 |
{ |
| 55 |
AddOption(std::to_string(option.second), option.first, option.second == defaultValue); |
| 56 |
} |
| 57 |
CheckDefaultKeyValue(); |
| 58 |
} |
| 59 |
|
| 60 |
|
| 61 |
template<typename T1, typename T2> |
| 62 |
HtmlTagSelect(const std::string& name, |
| 63 |
const std::map<T1,T2>& options, |
| 64 |
const T1 defaultValue = 0) |
| 65 |
: HtmlTagSelect(name) |
| 66 |
{ |
| 67 |
for (auto& option : options) |
| 68 |
{ |
| 69 |
AddOption(std::to_string(option.first), Languages::GetText(option.second), option.first == defaultValue); |
| 70 |
} |
| 71 |
CheckDefaultKeyValue(); |
| 72 |
} |
| 73 |
|
| 74 |
template<typename T> |
| 75 |
HtmlTagSelect(const std::string& name, |
| 76 |
const std::map<T,std::string>& options, |
| 77 |
const T defaultValue = 0) |
| 78 |
: HtmlTagSelect(name) |
| 79 |
{ |
| 80 |
for (auto& option : options) |
| 81 |
{ |
| 82 |
AddOption(std::to_string(option.first), option.second, option.first == defaultValue); |
| 83 |
} |
| 84 |
CheckDefaultKeyValue(); |
| 85 |
} |
| 86 |
|
| 87 |
virtual HtmlTag AddAttribute(const std::string& name, const std::string& value = "") override; |
| 88 |
|
| 89 |
private: |
| 90 |
HtmlTagSelect(const std::string& name); |
| 91 |
|
| 92 |
void AddOption(const std::string& key, |
| 93 |
const std::string& value, |
| 94 |
const bool defaultKeyValue); |
| 95 |
|
| 96 |
void CheckDefaultKeyValue(); |
| 97 |
|
| 98 |
inline void SetDefaultKeyValue(const std::string& key, |
| 99 |
const std::string& value) |
| 100 |
{ |
| 101 |
childTags[0].AddAttribute("value", key); |
| 102 |
childTags[1].AddAttribute("value", value); |
| 103 |
} |
| 104 |
|
| 105 |
const std::string commandID; |
| 106 |
bool defaultKeyValueFound; |
| 107 |
std::string defaultKey; |
| 108 |
std::string defaultValue; |
| 109 |
}; |
| 110 |
}} |
| 111 |
|