Add enable attribute

pull/66/head^2
Hieromon Ikasamo 6 years ago
parent 4abfb5251f
commit 0a3e9e4b63
  1. 5
      src/AutoConnectElementBasis.h
  2. 23
      src/AutoConnectElementBasisImpl.h

@ -46,11 +46,11 @@ typedef enum {
*/ */
class AutoConnectElementBasis { class AutoConnectElementBasis {
public: public:
explicit AutoConnectElementBasis(const char* name = "", const char* value = "") : name(String(name)), value(String(value)) { explicit AutoConnectElementBasis(const char* name = "", const char* value = "") : name(String(name)), value(String(value)), enable(true) {
_type = AC_Element; _type = AC_Element;
} }
virtual ~AutoConnectElementBasis() {} virtual ~AutoConnectElementBasis() {}
virtual const String toHTML(void) const { return value; } virtual const String toHTML(void) const { return enable ? value : String(""); }
ACElement_t typeOf(void) const { return _type; } ACElement_t typeOf(void) const { return _type; }
#ifndef AUTOCONNECT_USE_JSON #ifndef AUTOCONNECT_USE_JSON
template<typename T> template<typename T>
@ -59,6 +59,7 @@ class AutoConnectElementBasis {
String name; /**< Element name */ String name; /**< Element name */
String value; /**< Element value */ String value; /**< Element value */
bool enable; /**< Enabling the element */
protected: protected:
ACElement_t _type; /**< Element type identifier */ ACElement_t _type; /**< Element type identifier */

@ -25,7 +25,7 @@
* @return An HTML string. * @return An HTML string.
*/ */
const String AutoConnectButtonBasis::toHTML(void) const { const String AutoConnectButtonBasis::toHTML(void) const {
return String(F("<button type=\"button\" name=\"")) + name + String(F("\" value=\"")) + value + String(F("\" onclick=\"")) + action + String("\">") + value + String(F("</button>")); return enable ? String(F("<button type=\"button\" name=\"")) + name + String(F("\" value=\"")) + value + String(F("\" onclick=\"")) + action + String("\">") + value + String(F("</button>")) : String("");
} }
/** /**
@ -37,14 +37,16 @@ const String AutoConnectButtonBasis::toHTML(void) const {
* @return An HTML string. * @return An HTML string.
*/ */
const String AutoConnectCheckboxBasis::toHTML(void) const { const String AutoConnectCheckboxBasis::toHTML(void) const {
String html; String html = String("");
if (enable) {
html = String(F("<input type=\"checkbox\" name=\"")) + name + String(F("\" value=\"")) + value + String("\""); html = String(F("<input type=\"checkbox\" name=\"")) + name + String(F("\" value=\"")) + value + String("\"");
if (checked) if (checked)
html += String(F(" checked")); html += String(F(" checked"));
if (label.length()) if (label.length())
html += String(F(" id=\"")) + name + String(F("\"><label for=\"")) + name + String("\">") + label + String(F("</label")); html += String(F(" id=\"")) + name + String(F("\"><label for=\"")) + name + String("\">") + label + String(F("</label"));
html += String(F("><br>")); html += String(F("><br>"));
}
return html; return html;
} }
@ -58,9 +60,11 @@ const String AutoConnectCheckboxBasis::toHTML(void) const {
const String AutoConnectFileBasis::toHTML(void) const { const String AutoConnectFileBasis::toHTML(void) const {
String html = String(""); String html = String("");
if (enable) {
if (label.length()) if (label.length())
html = String(F("<label for=\"")) + name + String(F("\">")) + label + String(F("</label>")); html = String(F("<label for=\"")) + name + String(F("\">")) + label + String(F("</label>"));
html += String(F("<input type=\"file\" id=\"")) + name + String(F("\" name=\"")) + name + String(F("\"><br>")); html += String(F("<input type=\"file\" id=\"")) + name + String(F("\" name=\"")) + name + String(F("\"><br>"));
}
return html; return html;
} }
@ -101,6 +105,7 @@ bool AutoConnectFileBasis::attach(const ACFile_t store) {
const String AutoConnectInputBasis::toHTML(void) const { const String AutoConnectInputBasis::toHTML(void) const {
String html = String(""); String html = String("");
if (enable) {
if (label.length()) if (label.length())
html = String(F("<label for=\"")) + name + String("\">") + label + String(F("</label>")); html = String(F("<label for=\"")) + name + String("\">") + label + String(F("</label>"));
html += String(F("<input type=\"text\" id=\"")) + name + String(F("\" name=\"")) + name + String("\""); html += String(F("<input type=\"text\" id=\"")) + name + String(F("\" name=\"")) + name + String("\"");
@ -111,7 +116,7 @@ const String AutoConnectInputBasis::toHTML(void) const {
if (value.length()) if (value.length())
html += String(F(" value=\"")) + value + String("\""); html += String(F(" value=\"")) + value + String("\"");
html += String(F("><br>")); html += String(F("><br>"));
}
return html; return html;
} }
@ -176,6 +181,7 @@ void AutoConnectRadioBasis::empty(const size_t reserve) {
const String AutoConnectRadioBasis::toHTML(void) const { const String AutoConnectRadioBasis::toHTML(void) const {
String html = String(""); String html = String("");
if (enable) {
if (label.length()) { if (label.length()) {
html = label; html = label;
if (order == AC_Vertical) if (order == AC_Vertical)
@ -192,6 +198,7 @@ const String AutoConnectRadioBasis::toHTML(void) const {
if (order == AC_Vertical) if (order == AC_Vertical)
html += String(F("<br>")); html += String(F("<br>"));
} }
}
return html; return html;
} }
@ -227,12 +234,14 @@ void AutoConnectSelectBasis::empty(const size_t reserve) {
const String AutoConnectSelectBasis::toHTML(void) const { const String AutoConnectSelectBasis::toHTML(void) const {
String html = String(""); String html = String("");
if (enable) {
if (label.length()) if (label.length())
html = String(F("<label for=\"")) + name + String("\">") + label + String(F("</label>")); html = String(F("<label for=\"")) + name + String("\">") + label + String(F("</label>"));
html += String(F("<select name=\"")) + name + String(F("\" id=\"")) + name + String("\">"); html += String(F("<select name=\"")) + name + String(F("\" id=\"")) + name + String("\">");
for (const String option : _options) for (const String option : _options)
html += String(F("<option value=\"")) + option + "\">" + option + String(F("</option>")); html += String(F("<option value=\"")) + option + "\">" + option + String(F("</option>"));
html += String(F("</select>")); html += String(F("</select>"));
}
return html; return html;
} }
@ -243,7 +252,7 @@ const String AutoConnectSelectBasis::toHTML(void) const {
* @return String an HTML string. * @return String an HTML string.
*/ */
const String AutoConnectSubmitBasis::toHTML(void) const { const String AutoConnectSubmitBasis::toHTML(void) const {
return String(F("<input type=\"button\" name=\"")) + name + String(F("\" value=\"")) + value + String(F("\" onclick=\"_sa('")) + uri + String("')\">"); return enable ? String(F("<input type=\"button\" name=\"")) + name + String(F("\" value=\"")) + value + String(F("\" onclick=\"_sa('")) + uri + String("')\">") : String("");
} }
/** /**
@ -252,7 +261,10 @@ const String AutoConnectSubmitBasis::toHTML(void) const {
* @return String an HTML string. * @return String an HTML string.
*/ */
const String AutoConnectTextBasis::toHTML(void) const { const String AutoConnectTextBasis::toHTML(void) const {
String html = String("<div"); String html = String("");
if (enable) {
html = String("<div");
String value_f = value; String value_f = value;
if (style.length()) if (style.length())
@ -268,6 +280,7 @@ const String AutoConnectTextBasis::toHTML(void) const {
} }
} }
html += value_f + String(F("</div>")); html += value_f + String(F("</div>"));
}
return html; return html;
} }

Loading…
Cancel
Save