contains. A string
- * of style-codes are given for '
'.
- */
-class AutoConnectText : public AutoConnectElement {
- public:
- explicit AutoConnectText(const char* name = "", const char* value = "", const char* style = "") : AutoConnectElement(name, value), style(String(style)) {}
- ~AutoConnectText() {}
- const String toHTML(void) const;
-
- String style; /**< CSS style modifier native code */
-};
-
-/**
- * Support declare the AutoConnectElement variable with reducing the
- * arguments. These macros declare the AutoConnectElement variable
- * with the same name as a "name" argument.
- */
-#define ACElement(n, v) AutoConnectElements n(#n, v)
-#define ACButton(n, ...) AutoConnectButton n(#n, ## __VA_ARGS__)
-#define ACCheckbox(n, ...) AutoConnectCheckbox n(#n, ## __VA_ARGS__)
-#define ACInput(n, ...) AutoConnectInput n(#n, ## __VA_ARGS__)
-#define ACSelect(n, ...) AutoConnectSelect n(#n, ## __VA_ARGS__)
-#define ACSubmit(n, ...) AutoConnectSubmit n(#n, ## __VA_ARGS__)
-#define ACText(n, ...) AutoConnectText n(#n, ## __VA_ARGS__)
+class AutoConnect;
// Manage placed AutoConnectElement with a vector
typedef std::vector
> AutoConnectElementVT;
@@ -167,6 +33,8 @@ typedef enum {
AC_EXIT_BOTH = 3
} AutoConnectExitOrder_t;
+//class AutoConnect; // Reference to avoid circular
+
/**
* A class that handles an auxiliary page with AutoConnectElement
* that placed on it by binding it to the AutoConnect menu.
@@ -188,6 +56,11 @@ class AutoConnectAux : public PageBuilder {
void menu(const bool post) { _menu = post; } /**< Set or reset the display as menu item for this aux. */
void on(const AuxHandlerFunctionT handler, const AutoConnectExitOrder_t order = AC_EXIT_AHEAD) { _handler = handler; _order = order; } /**< Set user handler */
+#ifdef AUTOCONNECT_USE_JSON
+ AutoConnectElement& loadElement(Stream& in, const String name);
+ size_t saveElement(Stream& out, const AutoConnectElement& element);
+#endif
+
protected:
void _concat(AutoConnectAux& aux);
void _join(AutoConnect& ac);
@@ -196,6 +69,13 @@ class AutoConnectAux : public PageBuilder {
const String _injectTitle(PageArgument& args) { return _title; }
const String _injectMenu(PageArgument& args);
+#ifdef AUTOCONNECT_USE_JSON
+ AutoConnectElement* _createElement(const JsonObject& json);
+ AutoConnectElement* _getElement(const String name);
+ static const ACElement_t _asElementType(const String type);
+ static AutoConnectElement& _nullElement(void);
+#endif
+
String _title; /**< A title of the page */
bool _menu; /**< Switch for menu displaying */
AutoConnectElementVT _addonElm; /**< A vector set of AutoConnectElements placed on this auxiliary page */
@@ -210,4 +90,4 @@ class AutoConnectAux : public PageBuilder {
friend class AutoConnect;
};
-#endif // _AUTOCONNECTAUX_H_
\ No newline at end of file
+#endif // _AUTOCONNECTAUX_H_
\ No newline at end of file
diff --git a/src/AutoConnectDefs.h b/src/AutoConnectDefs.h
new file mode 100644
index 0000000..2fb2690
--- /dev/null
+++ b/src/AutoConnectDefs.h
@@ -0,0 +1,103 @@
+/**
+ * Predefined AutoConnect configuration parameters.
+ * @file AutoConnectDefs.h
+ * @author hieromon@gmail.com
+ * @version 0.9.7
+ * @date 2018-11-17
+ * @copyright MIT license.
+ */
+
+#ifndef _AUTOCONNECTDEFS_H_
+#define _AUTOCONNECTDEFS_H_
+
+// Uncomment the following AC_DEBUG to enable debug output.
+#define AC_DEBUG
+
+// Debug output destination can be defined externally with AC_DEBUG_PORT
+#ifndef AC_DEBUG_PORT
+#define AC_DEBUG_PORT Serial
+#endif // !AC_DEBUG_PORT
+#ifdef AC_DEBUG
+#define AC_DBG(...) do {AC_DEBUG_PORT.print("[AC] "); AC_DEBUG_PORT.printf( __VA_ARGS__ );} while (0)
+#else
+#define AC_DBG(...)
+#endif // !AC_DEBUG
+
+// Indicator to specify that AutoConnectAux handles elements with JSON.
+#define AUTOCONNECT_USE_JSON
+
+// Predefined parameters
+// SSID that Captive portal started.
+#ifndef AUTOCONNECT_APID
+#if defined(ARDUINO_ARCH_ESP8266)
+#define AUTOCONNECT_APID "esp8266ap"
+#elif defined(ARDUINO_ARCH_ESP32)
+#define AUTOCONNECT_APID "esp32ap"
+#endif // !ARDUINO_ARCH_ESP8266
+#endif // !AUTOCONNECT_APID
+
+// Password that Captive portal started.
+#ifndef AUTOCONNECT_PSK
+#define AUTOCONNECT_PSK "12345678"
+#endif // !AUTOCONNECT_PSK
+
+#ifndef AUTOCONNECT_AP_IP
+#define AUTOCONNECT_AP_IP 0x01F4A8C0 //*< 192.168.244.1 */
+#endif // !AUTOCONNECT_AP_IP
+#ifndef AUTOCONNECT_AP_GW
+#define AUTOCONNECT_AP_GW 0x01F4A8C0 //*< 192.168.244.1 */
+#endif // !AUTOCONNECT_AP_GW
+#ifndef AUTOCONNECT_AP_NM
+#define AUTOCONNECT_AP_NM 0x00FFFFFF //*< 255.255.255.0 */
+#endif // !AUTOCONNECT_AP_NM
+
+// AutoConnect menu root path
+#ifndef AUTOCONNECT_URI
+#define AUTOCONNECT_URI "/_ac"
+#endif // !AUTOCONNECT_URI
+
+// Root URI of home path prepared by user sketch
+#ifndef AUTOCONNECT_HOMEURI
+#define AUTOCONNECT_HOMEURI "/"
+#endif // !AUTOCONNECT_HOMEURI
+
+// AutoConnect menu title
+#ifndef AUTOCONNECT_MENU_TITLE
+#define AUTOCONNECT_MENU_TITLE "AutoConnect"
+#endif // !AUTOCONNECT_MENU_TITLE
+#define AUTOCONNECT_MENU_TITLE_CONNETED "Connected"
+
+// URIs of AutoConnect menu collection
+#define AUTOCONNECT_URI_CONFIG AUTOCONNECT_URI "/config"
+#define AUTOCONNECT_URI_CONNECT AUTOCONNECT_URI "/connect"
+#define AUTOCONNECT_URI_RESULT AUTOCONNECT_URI "/result"
+#define AUTOCONNECT_URI_OPEN AUTOCONNECT_URI "/open"
+#define AUTOCONNECT_URI_DISCON AUTOCONNECT_URI "/disc"
+#define AUTOCONNECT_URI_RESET AUTOCONNECT_URI "/reset"
+#define AUTOCONNECT_URI_SUCCESS AUTOCONNECT_URI "/success"
+#define AUTOCONNECT_URI_FAIL AUTOCONNECT_URI "/fail"
+
+// Time-out limitation when AutoConnect::begin
+#ifndef AUTOCONNECT_TIMEOUT
+#define AUTOCONNECT_TIMEOUT 30000
+#endif // !AUTOCONNECT_TIMEOUT
+
+// Advance wait time
+#ifndef AUTOCONNECT_STARTUPTIME
+#define AUTOCONNECT_STARTUPTIME 10
+#endif // !AUTOCONNECT_STARTUPTIME
+
+// Default HTTP port
+#ifndef AUTOCONNECT_HTTPPORT
+#define AUTOCONNECT_HTTPPORT 80
+#endif // !AUTOCONNECT_HTTPPORT
+
+// DNS port
+#ifndef AUTOCONNECT_DNSPORT
+#define AUTOCONNECT_DNSPORT 53
+#endif // !AUTOCONNECT_DNSPORT
+
+// Explicitly avoiding unused warning with token handler of PageBuilder
+#define AC_UNUSED(expr) do { (void)(expr); } while (0)
+
+#endif // _AUTOCONNECTDEFS_H_
\ No newline at end of file
diff --git a/src/AutoConnectElement.h b/src/AutoConnectElement.h
new file mode 100644
index 0000000..ef88467
--- /dev/null
+++ b/src/AutoConnectElement.h
@@ -0,0 +1,49 @@
+/**
+ * Alias declarations for an accessible the AutoConnectElement class.
+ * @file AutoConnectAux.h
+ * @author hieromon@gmail.com
+ * @version 0.9.7
+ * @date 2018-11-17
+ * @copyright MIT license.
+ */
+
+#ifndef _AUTOCONNECTELEMENT_H_
+#define _AUTOCONENCTELEMENT_H_
+
+#include "AutoConnectElementBasis.h"
+//#include "AutoConnectElementBasisImpl.h"
+#ifdef AUTOCONNECT_USE_JSON
+#include
+#include "AutoConnectElementJson.h"
+//#include "AutoConnectElementJsonImpl.h"
+using AutoConnectElement = AutoConnectElementJson;
+using AutoConnectButton = AutoConnectButtonJson;
+using AutoConnectCheckbox = AutoConnectCheckboxJson;
+using AutoConnectInput = AutoConnectInputJson;
+using AutoConnectSelect = AutoConnectSelectJson;
+using AutoConnectSubmit = AutoConnectSubmitJson;
+using AutoConnectText = AutoConnectTextJson;
+#else
+using AutoConnectElement = AutoConnectElementBasis;
+using AutoConnectButton = AutoConnectButtonBasis;
+using AutoConnectCheckbox = AutoConnectCheckboxBasis;
+using AutoConnectInput = AutoConnectInputBasis;
+using AutoConnectSelect = AutoConnectSelectBasis;
+using AutoConnectSubmit = AutoConnectSubmitBasis;
+using AutoConnectText = AutoConnectTextBasis;
+#endif
+
+/**
+ * Support declare the AutoConnectElement variable with reducing the
+ * arguments. These macros declare the AutoConnectElement variable
+ * with the same name as a "name" argument.
+ */
+#define ACElement(n, v) AutoConnectElement n(#n, v)
+#define ACButton(n, ...) AutoConnectButton n(#n, ##__VA_ARGS__)
+#define ACCheckbox(n, ...) AutoConnectCheckbox n(#n, ##__VA_ARGS__)
+#define ACInput(n, ...) AutoConnectInput n(#n, ##__VA_ARGS__)
+#define ACSelect(n, ...) AutoConnectSelect n(#n, ##__VA_ARGS__)
+#define ACSubmit(n, ...) AutoConnectSubmit n(#n, ##__VA_ARGS__)
+#define ACText(n, ...) AutoConnectText n(#n, ##__VA_ARGS__)
+
+#endif // _AUTOCONNECTELEMENT_H_
\ No newline at end of file
diff --git a/src/AutoConnectElementBasis.h b/src/AutoConnectElementBasis.h
new file mode 100644
index 0000000..bac2bf6
--- /dev/null
+++ b/src/AutoConnectElementBasis.h
@@ -0,0 +1,170 @@
+/**
+ * Declaration of AutoConnectElement basic class.
+ * @file AutoConnectElementBasis.h
+ * @author hieromon@gmail.com
+ * @version 0.9.7
+ * @date 2018-11-17
+ * @copyright MIT license.
+ */
+
+#ifndef _AUTOCONNECTELEMENTBASIS_H_
+#define _AUTOCONNECTELEMENTBASIS_H_
+
+#include
+#include
+
+typedef enum {
+ AC_Button,
+ AC_Checkbox,
+ AC_Element,
+ AC_Input,
+ AC_Select,
+ AC_Submit,
+ AC_Text,
+ AC_Unknown
+} ACElement_t; /**< AutoConnectElement class type */
+
+/**
+ * AutoConnectAux element base.
+ * Placed a raw text that can be added by user sketch.
+ * @param name A name string for the element.
+ * @param value A raw text to be placed in HTML.
+ */
+class AutoConnectElementBasis {
+ public:
+ explicit AutoConnectElementBasis(const char* name = "", const char* value = "") : name(String(name)), value(String(value)) {
+ _type = AC_Element;
+ }
+ virtual ~AutoConnectElementBasis() {}
+ virtual const String toHTML(void) const { return value; }
+ const ACElement_t typeOf(void) const { return _type; }
+
+ String name; /**< Element name */
+ String value; /**< Element value */
+
+protected:
+ ACElement_t _type; /**< Element type identifier */
+};
+
+/**
+ * Button arrangement class, a part of AutoConnectAux element.
+ * Place a labeled button that can be added by user sketch.
+ * @param name Button element name string.
+ * @param value Value string with the placed button.
+ * @param action Script code to execute with the button pushed.
+ */
+class AutoConnectButtonBasis : virtual public AutoConnectElementBasis {
+ public:
+ explicit AutoConnectButtonBasis(const char* name = "", const char* value = "", const String action = String()) : AutoConnectElementBasis(name, value), action(action) {
+ _type = AC_Button;
+ }
+ ~AutoConnectButtonBasis() {}
+ const String toHTML(void) const;
+
+ String action;
+};
+
+/**
+ * Checkbox arrangement class, a part of AutoConnectAux element.
+ * Place a optionally labeled input-box that can be added by user sketch.
+ * @param name Checkbox name string.
+ * @param value A string value associated with the input.
+ * @param label A label string that follows checkbox, optionally.
+ * The label is placed on the right side of the checkbox.
+ */
+class AutoConnectCheckboxBasis : virtual public AutoConnectElementBasis {
+ public:
+ explicit AutoConnectCheckboxBasis(const char* name = "", const char* value = "", const char* label = "", const bool checked = false) : AutoConnectElementBasis(name, value), label(String(label)), checked(checked) {
+ _type = AC_Checkbox;
+ }
+ virtual ~AutoConnectCheckboxBasis() {}
+ const String toHTML(void) const;
+
+ String label; /**< A label for a subsequent input box */
+ bool checked; /**< The element should be pre-selected */
+};
+
+/**
+ * Input-box arrangement class, a part of AutoConnectAux element.
+ * Place a optionally labeled input-box that can be added by user sketch.
+ * @param name Input-box name string.
+ * @param value Default value string. This string display as a placeholder by the default.
+ * @param label A label string that follows Input-box, optionally.
+ * The label is placed in front of Input-box.
+ */
+class AutoConnectInputBasis : virtual public AutoConnectElementBasis {
+ public:
+ explicit AutoConnectInputBasis(const char* name = "", const char* value = "", const char* label = "") : AutoConnectElementBasis(name, value), label(String(label)) {
+ _type = AC_Input;
+ }
+ virtual ~AutoConnectInputBasis() {}
+ const String toHTML(void) const;
+
+ String label; /**< A label for a subsequent input box */
+};
+
+/**
+ * Selection-box arrangement class, A part of AutoConnectAux element.
+ * Place a optionally labeled Selection-box that can be added by user sketch.
+ * @param name Input-box name string.
+ * @param options String array display in a selection list.
+ * @param label A label string that follows Input-box, optionally.
+ * The label is placed in front of Input-box.
+ */
+class AutoConnectSelectBasis : virtual public AutoConnectElementBasis {
+ public:
+ explicit AutoConnectSelectBasis(const char* name = "", std::vector options = {}, const char* label = "") : AutoConnectElementBasis(name, ""), label(String(label)), _options(options) {
+ _type = AC_Select;
+ }
+ virtual ~AutoConnectSelectBasis() {}
+ const String toHTML(void) const;
+ void option(const String value) { _options.push_back(value); }
+ void empty(void) { _options.clear(); }
+
+ String label; /**< A label for a subsequent input box */
+
+ protected:
+ std::vector _options; /**< List options array */
+};
+
+/**
+ * Submit button arrangement class, a part of AutoConnectAux element.
+ * Place a submit button with a label that can be added by user sketch.
+ * With the button behavior, the values of the elements contained in
+ * the form would be sent using the post method.
+ * @param name Button name string.
+ * @param value Sending value string.
+ * @param uri Sending uri string.
+ */
+class AutoConnectSubmitBasis : virtual public AutoConnectElementBasis {
+ public:
+ explicit AutoConnectSubmitBasis(const char* name = "", const char* value = "", const char* uri = "") : AutoConnectElementBasis(name, value), uri(String(uri)) {
+ _type = AC_Submit;
+ }
+ virtual ~AutoConnectSubmitBasis() {}
+ const String toHTML(void) const;
+
+ String uri; /**< An url of submitting to */
+};
+
+/**
+ * Text arrangement class, a part of AutoConnectAux element.
+ * @param
+ * @param name Text name string.
+ * @param value Text value string.
+ * @param style A string of style-code for decoration, optionally.
+ * An arrangement text would be placed with contains. A string
+ * of style-codes are given for '
'.
+ */
+class AutoConnectTextBasis : virtual public AutoConnectElementBasis {
+ public:
+ explicit AutoConnectTextBasis(const char* name = "", const char* value = "", const char* style = "") : AutoConnectElementBasis(name, value), style(String(style)) {
+ _type = AC_Text;
+ }
+ virtual ~AutoConnectTextBasis() {}
+ const String toHTML(void) const;
+
+ String style; /**< CSS style modifier native code */
+};
+
+#endif // _AUTOCONNECTELEMENTBASIS_H_
diff --git a/src/AutoConnectElementBasisImpl.h b/src/AutoConnectElementBasisImpl.h
new file mode 100644
index 0000000..6292fb5
--- /dev/null
+++ b/src/AutoConnectElementBasisImpl.h
@@ -0,0 +1,107 @@
+/**
+ * Implementation of AutoConnectElementBasis classes.
+ * @file AutoConnectElementImpl.h
+ * @author hieromon@gmail.com
+ * @version 0.9.7
+ * @date 2018-11-17
+ * @copyright MIT license.
+ */
+
+#ifndef _AUTOCONNECTELEMENTBASISIMPL_H_
+#define _AUTOCONNECTELEMENTBASISIMPL_H_
+
+#include "AutoConnectElementBasis.h"
+
+/**
+ * Generate an HTML
element. The onclick behavior depends on
+ * the code held in ÂfactionÂf member.
+ * @return An HTML string.
+ */
+const String AutoConnectButtonBasis::toHTML(void) const {
+ return String(FPSTR("") + value + String(FPSTR(" "));
+}
+
+/**
+ * Generate an HTML element.
+ * A "value" is associated with the input tag and sent by the form
+ * action as the value of "name". If the label member is contained, it
+ * is placed to the right side of the checkbox to be labeled.
+ * f the label member is empty, only the checkbox is placed.
+ * @return An HTML string.
+ */
+const String AutoConnectCheckboxBasis::toHTML(void) const {
+ String html;
+
+ html = String(FPSTR("") + label + String(FPSTR(" "));
+ return html;
+}
+
+/**
+ * Generate an HTML element.
+ * If the value member is contained, it is reflected in the placeholder
+ * attribute. The entered value can be obtained using the user callback
+ * function registered by AutoConnectAux::on after the form is sent in
+ * combination with AutoConnectSubmit.
+ * @return String an HTML string.
+ */
+const String AutoConnectInputBasis::toHTML(void) const {
+ String html = String();
+
+ if (label.length())
+ html = String(FPSTR("") + label + String(FPSTR(" "));
+ html += String(FPSTR(" "));
+
+ return html;
+}
+
+/**
+ * Generate an HTML element with an element.
+ * The attribute value of the element is given to the
+ * AutoConnectSelect class as a string array, which would be stored
+ * in the 'options' member. If a label member is contained, the
+ * element would be generated the preface of .
+ * @return String an HTML string.
+ */
+const String AutoConnectSelectBasis::toHTML(void) const {
+ String html = String();
+
+ if (label.length())
+ html = String(FPSTR("")) + label + String(FPSTR(" "));
+ html += String(FPSTR("");
+ std::size_t n = _options.size();
+ if (n) {
+ for (std::size_t n = 0; n < _options.size(); n++)
+ html += String(FPSTR("" + _options[n] + String(FPSTR(" "));
+ }
+ html += String(FPSTR(" "));
+ return html;
+}
+
+/**
+ * Generate an HTML element. This element is used
+ * for form submission. An 'onclick' attribute calls fixed JavaScript
+ * code as 'sa' named and it's included in the template.
+ * @return String an HTML string.
+ */
+const String AutoConnectSubmitBasis::toHTML(void) const {
+ return String(FPSTR(" ");
+}
+
+/**
+ * Generate an HTML text element from a string of the value member. If a style
+ * exists, it gives a style attribute.
+ * @return String an HTML string.
+ */
+const String AutoConnectTextBasis::toHTML(void) const {
+ return String(FPSTR("") + value + String(FPSTR("
"));
+}
+
+#endif // _AUTOCONNECTELEMENTBASISIMPL_H_
diff --git a/src/AutoConnectElementJson.h b/src/AutoConnectElementJson.h
new file mode 100644
index 0000000..87a09a3
--- /dev/null
+++ b/src/AutoConnectElementJson.h
@@ -0,0 +1,173 @@
+/**
+ * Declaration of AutoConnectElement extended classes using JSON.
+ * @file AutoConnectElementJson.h
+ * @author hieromon@gmail.com
+ * @version 0.9.7
+ * @date 2018-11-17
+ * @copyright MIT license.
+ */
+
+#ifndef _AUTOCONNECTELEMENTJSON_H_
+#define _AUTOCONNECTELEMENTJSON_H_
+
+#include "AutoConnectElementBasis.h"
+#include
+
+#define AUTOCONNECT_JSON_KEY_AUX "aux"
+#define AUTOCONNECT_JSON_KEY_ELEMENT "element"
+#define AUTOCONNECT_JSON_KEY_ACTION "action"
+#define AUTOCONNECT_JSON_KEY_CHECKED "checked"
+#define AUTOCONNECT_JSON_KEY_LABEL "label"
+#define AUTOCONNECT_JSON_KEY_NAME "name"
+#define AUTOCONNECT_JSON_KEY_OPTIONS "options"
+#define AUTOCONNECT_JSON_KEY_STYLE "style"
+#define AUTOCONNECT_JSON_KEY_TYPE "type"
+#define AUTOCONNECT_JSON_KEY_URI "uri"
+#define AUTOCONNECT_JSON_KEY_VALUE "value"
+#define AUTOCONNECT_JSON_TYPE_ACBUTTON "ACButton"
+#define AUTOCONNECT_JSON_TYPE_ACCHECKBOX "ACCheckBox"
+#define AUTOCONNECT_JSON_TYPE_ACELEMENT "ACElement"
+#define AUTOCONNECT_JSON_TYPE_ACINPUT "ACInput"
+#define AUTOCONNECT_JSON_TYPE_ACSELECT "ACSelect"
+#define AUTOCONNECT_JSON_TYPE_ACSUBMIT "ACSubmit"
+#define AUTOCONNECT_JSON_TYPE_ACTEXT "ACText"
+
+/**
+ * AutoConnectAux element base with handling with JSON object.
+ * Placed a raw text that can be added by user sketch.
+ * @param name A name string for the element.
+ * @param value A raw text to be placed in HTML.
+ */
+class AutoConnectElementJson : virtual public AutoConnectElementBasis {
+ public:
+ explicit AutoConnectElementJson(const char* name = "", const char* value = "") {
+ AutoConnectElementBasis::name = name;
+ AutoConnectElementBasis::value = value;
+ }
+ ~AutoConnectElementJson() {}
+ virtual bool loadElement(const JsonObject& json);
+
+ protected:
+ void _setElement(const JsonObject& json);
+};
+
+/**
+ * Button arrangement class, a part of AutoConnectAux element with
+ * handling JSON object.
+ * Place a labeled button that can be added by user sketch.
+ * @param name Button element name string.
+ * @param value Value string with the placed button.
+ * @param action Script code to execute with the button pushed.
+ */
+class AutoConnectButtonJson : public AutoConnectElementJson, public AutoConnectButtonBasis {
+ public:
+ explicit AutoConnectButtonJson(const char* name = "", const char* value = "", const String action = String()) {
+ AutoConnectButtonBasis::name = name;
+ AutoConnectButtonBasis::value = value;
+ AutoConnectButtonBasis::action = action;
+ }
+ ~AutoConnectButtonJson() {}
+ bool loadElement(const JsonObject& json);
+};
+
+/**
+ * Checkbox arrangement class, a part of AutoConnectAux element with
+ * handling JSON object.
+ * Place a optionally labeled input-box that can be added by user sketch.
+ * @param name Checkbox name string.
+ * @param value A string value associated with the input.
+ * @param label A label string that follows checkbox, optionally.
+ * The label is placed on the right side of the checkbox.
+ */
+class AutoConnectCheckboxJson : public AutoConnectElementJson, public AutoConnectCheckboxBasis {
+ public:
+ explicit AutoConnectCheckboxJson(const char* name = "", const char* value = "", const char* label = "", const bool checked = false) {
+ AutoConnectCheckboxBasis::name = name;
+ AutoConnectCheckboxBasis::value = value;
+ AutoConnectCheckboxBasis::label = label;
+ AutoConnectCheckboxBasis::checked = checked;
+ }
+ ~AutoConnectCheckboxJson() {}
+ bool loadElement(const JsonObject& json);
+};
+
+/**
+ * Input-box arrangement class, a part of AutoConnectAux element with
+ * handling JSON object.
+ * Place a optionally labeled input-box that can be added by user sketch.
+ * @param name Input-box name string.
+ * @param value Default value string. This string display as a placeholder by the default.
+ * @param label A label string that follows Input-box, optionally.
+ * The label is placed in front of Input-box.
+ */
+class AutoConnectInputJson : public AutoConnectElementJson, public AutoConnectInputBasis {
+ public:
+ explicit AutoConnectInputJson(const char* name = "", const char* value = "", const char* label = "") {
+ AutoConnectInputBasis::name = name;
+ AutoConnectInputBasis::value = value;
+ AutoConnectInputBasis::label = label;
+ }
+ ~AutoConnectInputJson() {}
+ bool loadElement(const JsonObject& json);
+};
+
+/**
+ * Selection-box arrangement class, A part of AutoConnectAux element.
+ * Place a optionally labeled Selection-box that can be added by user sketch.
+ * @param name Input-box name string.
+ * @param options String array display in a selection list.
+ * @param label A label string that follows Input-box, optionally.
+ * The label is placed in front of Input-box.
+ */
+class AutoConnectSelectJson : public AutoConnectElementJson, public AutoConnectSelectBasis {
+ public:
+ explicit AutoConnectSelectJson(const char* name = "", std::vector options = {}, const char* label = "") {
+ AutoConnectSelectBasis::name = name;
+ AutoConnectSelectBasis::_options = options;
+ AutoConnectSelectBasis::label = label;
+ }
+ ~AutoConnectSelectJson() {}
+ bool loadElement(const JsonObject& json);
+};
+
+/**
+ * Submit button arrangement class, a part of AutoConnectAux element.
+ * Place a submit button with a label that can be added by user sketch.
+ * With the button behavior, the values of the elements contained in
+ * the form would be sent using the post method.
+ * @param name Button name string.
+ * @param value Sending value string.
+ * @param uri Sending uri string.
+ */
+class AutoConnectSubmitJson : public AutoConnectElementJson, public AutoConnectSubmitBasis {
+ public:
+ explicit AutoConnectSubmitJson(const char* name = "", const char* value = "", const char* uri = "") {
+ AutoConnectSubmitBasis::name = name;
+ AutoConnectSubmitBasis::value = value;
+ AutoConnectSubmitBasis::uri = uri;
+ }
+ ~AutoConnectSubmitJson() {}
+ bool loadElement(const JsonObject& json);
+};
+
+/**
+ * Text arrangement class, a part of AutoConnectAux element.
+ * @param
+ * @param name Text name string.
+ * @param value Text value string.
+ * @param style A string of style-code for decoration, optionally.
+ * An arrangement text would be placed with contains. A string
+ * of style-codes are given for '
'.
+ */
+class AutoConnectTextJson : public AutoConnectElementJson, public AutoConnectTextBasis {
+ public:
+ explicit AutoConnectTextJson(const char* name = "", const char* value = "", const char* style = "") {
+ AutoConnectTextBasis::name = name;
+ AutoConnectTextBasis::value = value;
+ AutoConnectTextBasis::style = style;
+ }
+ ~AutoConnectTextJson() {}
+ bool loadElement(const JsonObject& json);
+};
+
+#endif // _AUTOCONNECTELEMENTJSON_H_
diff --git a/src/AutoConnectElementJsonImpl.h b/src/AutoConnectElementJsonImpl.h
new file mode 100644
index 0000000..fbb8281
--- /dev/null
+++ b/src/AutoConnectElementJsonImpl.h
@@ -0,0 +1,140 @@
+/**
+ * Implementation of AutoConnectElementJson classes.
+ * @file AutoConnectElementImpl.h
+ * @author hieromon@gmail.com
+ * @version 0.9.7
+ * @date 2018-11-17
+ * @copyright MIT license.
+ */
+
+#ifndef _AUTOCONNECTELEMENTJSONIMPL_H_
+#define _AUTOCONNECTELEMENTJSONIMPL_H_
+
+#include "AutoConnectElementJson.h"
+
+/**
+ * Set items common to any type of AutoConnectElement from JSON objects.
+ * @param json A JSON object with the definition of AutoConnectElement.
+ */
+void AutoConnectElementJson::_setElement(const JsonObject& json) {
+ name = json.get(F(AUTOCONNECT_JSON_KEY_NAME));
+ value = json.get(F(AUTOCONNECT_JSON_KEY_VALUE));
+}
+
+/**
+ * Load an element member value from the JSON object.
+ * @param json A JSON object with the definition of AutoConnectElement.
+ * @return true AutoConnectElement loaded
+ * @return false Type of AutoConnectElement is mismatched.
+ */
+bool AutoConnectElementJson::loadElement(const JsonObject& json) {
+ String type = json.get(F(AUTOCONNECT_JSON_KEY_TYPE));
+ if (type.equalsIgnoreCase(F(AUTOCONNECT_JSON_TYPE_ACELEMENT))) {
+ _setElement(json);
+ return true;
+ }
+ return false;
+}
+
+/**
+ * Load a button element attribute member from the JSON object.
+ * @param json A JSON object with the definition of AutoConnectElement.
+ * @return true AutoConnectElement loaded
+ * @return false Type of AutoConnectElement is mismatched.
+ */
+bool AutoConnectButtonJson::loadElement(const JsonObject& json) {
+ String type = json.get(F(AUTOCONNECT_JSON_KEY_TYPE));
+ if (type.equalsIgnoreCase(F(AUTOCONNECT_JSON_TYPE_ACBUTTON))) {
+ _setElement(json);
+ action = json.get(F(AUTOCONNECT_JSON_KEY_ACTION));
+ return true;
+ }
+ return false;
+}
+
+/**
+ * Load a checkbox element attribute member from the JSON object.
+ * @param json A JSON object with the definition of AutoConnectElement.
+ * @return true AutoConnectElement loaded
+ * @return false Type of AutoConnectElement is mismatched.
+ */
+bool AutoConnectCheckboxJson::loadElement(const JsonObject& json) {
+ String type = json.get(F(AUTOCONNECT_JSON_KEY_TYPE));
+ if (type.equalsIgnoreCase(F(AUTOCONNECT_JSON_TYPE_ACCHECKBOX))) {
+ _setElement(json);
+ label = json.get(F(AUTOCONNECT_JSON_KEY_LABEL));
+ checked = json.get(F(AUTOCONNECT_JSON_KEY_CHECKED));
+ return true;
+ }
+ return false;
+}
+
+/**
+ * Load a input-box element attribute member from the JSON object.
+ * @param json A JSON object with the definition of AutoConnectElement.
+ * @return true AutoConnectElement loaded
+ * @return false Type of AutoConnectElement is mismatched.
+ */
+bool AutoConnectInputJson::loadElement(const JsonObject& json) {
+ String type = json.get(F(AUTOCONNECT_JSON_KEY_TYPE));
+ if (type.equalsIgnoreCase(F(AUTOCONNECT_JSON_TYPE_ACINPUT))) {
+ _setElement(json);
+ label = json.get(F(AUTOCONNECT_JSON_KEY_LABEL));
+ return true;
+ }
+ return false;
+}
+
+/**
+ * Load a select element attribute member from the JSON object.
+ * @param json A JSON object with the definition of AutoConnectElement.
+ * @return true AutoConnectElement loaded
+ * @return false Type of AutoConnectElement is mismatched.
+ */
+bool AutoConnectSelectJson::loadElement(const JsonObject& json) {
+ String type = json.get(F(AUTOCONNECT_JSON_KEY_TYPE));
+ if (type.equalsIgnoreCase(F(AUTOCONNECT_JSON_TYPE_ACSELECT))) {
+ _setElement(json);
+ empty();
+ label = json.get(F(AUTOCONNECT_JSON_KEY_LABEL));
+ JsonArray& optionArray = json[AUTOCONNECT_JSON_KEY_OPTIONS];
+ for (auto value : optionArray)
+ option(value.as());
+ return true;
+ }
+ return false;
+}
+
+/**
+ * Load a submit element attribute member from the JSON object.
+ * @param json A JSON object with the definition of AutoConnectElement.
+ * @return true AutoConnectElement loaded
+ * @return false Type of AutoConnectElement is mismatched.
+ */
+bool AutoConnectSubmitJson::loadElement(const JsonObject& json) {
+ String type = json.get(F(AUTOCONNECT_JSON_KEY_TYPE));
+ if (type.equalsIgnoreCase(F(AUTOCONNECT_JSON_TYPE_ACSUBMIT))) {
+ _setElement(json);
+ uri = json.get(F(AUTOCONNECT_JSON_KEY_URI));
+ return true;
+ }
+ return false;
+}
+
+/**
+ * Load a text element attribute member from the JSON object.
+ * @param json A JSON object with the definition of AutoConnectElement.
+ * @return true AutoConnectElement loaded
+ * @return false Type of AutoConnectElement is mismatched.
+ */
+bool AutoConnectTextJson::loadElement(const JsonObject& json) {
+ String type = json.get(F(AUTOCONNECT_JSON_KEY_TYPE));
+ if (type.equalsIgnoreCase(F(AUTOCONNECT_JSON_TYPE_ACTEXT))) {
+ _setElement(json);
+ style = json.get(F(AUTOCONNECT_JSON_KEY_STYLE));
+ return true;
+ }
+ return false;
+}
+
+#endif // _AUTOCONNECTELEMENTJSONIMPL_H_