diff --git a/src/AutoConnectAux.cpp b/src/AutoConnectAux.cpp index ceccd71..6639fd3 100644 --- a/src/AutoConnectAux.cpp +++ b/src/AutoConnectAux.cpp @@ -142,6 +142,21 @@ AutoConnectElement* AutoConnectAux::getElement(const String& name) { return nullptr; } +/** + * Validate all AutoConnectInputs value. + * @return true Validation successfull + * @return false Some elements failed validation. + */ +bool AutoConnectAux::isValid(void) const { + bool rc = true; + for (AutoConnectElement& elm : _addonElm) + if (elm.typeOf() == AC_Input) { + AutoConnectInput& elmInput = reinterpret_cast(elm); + rc &= elmInput.isValid(); + } + return rc; +} + /** * Releases the AutoConnectElements with the specified name from * the AutoConnectAux page. Releases all AutoConnectElements with @@ -530,6 +545,16 @@ void AutoConnectAux::_storeElements(WebServerClass* webServer) { if (elm.typeOf() == AC_Checkbox) elmValue = "checked"; setElementValue(elm.name, elmValue); + + // Copy a value to other elements declared as global. + if (elm.global) { + AutoConnectAux* aux = _ac->_aux.get(); + while (aux) { + if (aux != this) + aux->setElementValue(elm.name, elmValue); + aux = aux->_next.get(); + } + } } } } diff --git a/src/AutoConnectAux.h b/src/AutoConnectAux.h index abd959e..27ec479 100644 --- a/src/AutoConnectAux.h +++ b/src/AutoConnectAux.h @@ -60,6 +60,7 @@ class AutoConnectAux : public PageBuilder { AutoConnectElementVT& getElements(void) { return _addonElm; } /**< Get vector of all elements */ void menu(const bool post) { _menu = post; } /**< Set or reset the display as menu item for this aux */ bool isMenu(void) { return _menu; } /**< Return whether embedded in the menu or not */ + bool isValid(void) const; /**< Validate all AutoConnectInput value */ bool release(const String& name); /**< Release an AutoConnectElement */ bool setElementValue(const String& name, const String value); /**< Set value to specified element */ bool setElementValue(const String& name, std::vector const& values); /**< Set values collection to specified element */ diff --git a/src/AutoConnectElementBasis.h b/src/AutoConnectElementBasis.h index 21d91c9..cba00f6 100644 --- a/src/AutoConnectElementBasis.h +++ b/src/AutoConnectElementBasis.h @@ -2,8 +2,8 @@ * Declaration of AutoConnectElement basic class. * @file AutoConnectElementBasis.h * @author hieromon@gmail.com - * @version 0.9.11 - * @date 2019-06-25 + * @version 1.0.0 + * @date 2019-09-03 * @copyright MIT license. */ @@ -71,7 +71,7 @@ typedef enum { */ class AutoConnectElementBasis { public: - explicit AutoConnectElementBasis(const char* name = "", const char* value = "", const ACPosterior_t post = AC_Tag_None) : name(String(name)), value(String(value)), post(post), enable(true) { + explicit AutoConnectElementBasis(const char* name = "", const char* value = "", const ACPosterior_t post = AC_Tag_None) : name(String(name)), value(String(value)), post(post), enable(true), global(false) { _type = AC_Element; } virtual ~AutoConnectElementBasis() {} @@ -87,6 +87,7 @@ class AutoConnectElementBasis { String value; /**< Element value */ ACPosterior_t post; /**< Tag to be generated with posterior */ bool enable; /**< Enabling the element */ + bool global; /**< The value available in global scope */ protected: ACElement_t _type; /**< Element type identifier */ diff --git a/src/AutoConnectElementJson.h b/src/AutoConnectElementJson.h index 91de8b9..2cb9486 100644 --- a/src/AutoConnectElementJson.h +++ b/src/AutoConnectElementJson.h @@ -2,8 +2,8 @@ * Declaration of AutoConnectElement extended classes using JSON. * @file AutoConnectElementJson.h * @author hieromon@gmail.com - * @version 0.9.11 - * @date 2019-06-25 + * @version 1.0.0 + * @date 2019-09-03 * @copyright MIT license. */ @@ -18,6 +18,7 @@ #define AUTOCONNECT_JSON_KEY_CHECKED "checked" #define AUTOCONNECT_JSON_KEY_ELEMENT "element" #define AUTOCONNECT_JSON_KEY_FORMAT "format" +#define AUTOCONNECT_JSON_KEY_GLOBAL "global" #define AUTOCONNECT_JSON_KEY_LABEL "label" #define AUTOCONNECT_JSON_KEY_LABELPOSITION "labelposition" #define AUTOCONNECT_JSON_KEY_MENU "menu" diff --git a/src/AutoConnectElementJsonImpl.h b/src/AutoConnectElementJsonImpl.h index 16d2f36..9219ff5 100644 --- a/src/AutoConnectElementJsonImpl.h +++ b/src/AutoConnectElementJsonImpl.h @@ -2,8 +2,8 @@ * Implementation of AutoConnectElementJson classes. * @file AutoConnectElementImpl.h * @author hieromon@gmail.com - * @version 0.9.11 - * @date 2019-06-25 + * @version 1.0.0 + * @date 2019-09-03 * @copyright MIT license. */ @@ -72,6 +72,8 @@ void AutoConnectElementJson::_serialize(JsonObject& json) { } json[F(AUTOCONNECT_JSON_KEY_POSTERIOR)] = posterior; } + if (global) + json[F(AUTOCONNECT_JSON_KEY_GLOBAL)] = true; } /** @@ -93,6 +95,9 @@ void AutoConnectElementJson::_setMember(const JsonObject& json) { else AC_DBG("Warning '%s' loading, unknown posterior '%s'\n", name.c_str(), posterior.c_str()); } + if (json.containsKey(F(AUTOCONNECT_JSON_KEY_GLOBAL))) { + global = json[F(AUTOCONNECT_JSON_KEY_GLOBAL)].as(); + } } /**