Adds AutoConnectAux::fetchElement function

pull/110/head
Hieromon Ikasamo 5 years ago
parent 7667db0038
commit 47c6fff690
  1. 40
      src/AutoConnectAux.cpp
  2. 1
      src/AutoConnectAux.h

@ -106,6 +106,29 @@ void AutoConnectAux::add(AutoConnectElementVT addons) {
add(element);
}
/**
* Parses the query parameters contained in the http request and fetches
* the value of AutoConnectElements carried by AutoConnectAux.
*/
void AutoConnectAux::fetchElement(void) {
WebServerClass* _webServer = _ac->_webServer.get();
if (_webServer->hasArg(String(F(AUTOCONNECT_AUXURI_PARAM)))) {
_ac->_auxUri = _webServer->arg(String(F(AUTOCONNECT_AUXURI_PARAM)));
_ac->_auxUri.replace("/", "/");
AC_DBG("fetch %s", _ac->_auxUri.c_str());
AutoConnectAux* aux = _ac->_aux.get();
while (aux) {
if (aux->_uriStr == _ac->_auxUri) {
// Save the value owned by each element contained in the POST body
// of a current HTTP request to AutoConnectElements.
aux->_storeElements(_webServer);
break;
}
aux = aux->_next.get();
}
}
}
/**
* Get already registered AutoConnectElement.
* @param name Element name
@ -385,21 +408,7 @@ const String AutoConnectAux::_insertElement(PageArgument& args) {
// If the current request argument contains AutoConnectElement, it is
// the form data of the AutoConnectAux page and with this timing save
// the value of each element.
WebServerClass* _webServer = _ac->_webServer.get();
if (_webServer->hasArg(String(F(AUTOCONNECT_AUXURI_PARAM)))) {
_ac->_auxUri = _webServer->arg(String(F(AUTOCONNECT_AUXURI_PARAM)));
_ac->_auxUri.replace("/", "/");
AutoConnectAux* aux = _ac->_aux.get();
while (aux) {
if (aux->_uriStr == _ac->_auxUri) {
// Save the value owned by each element contained in the POST body
// of a current HTTP request to AutoConnectElements.
aux->_storeElements(_webServer);
break;
}
aux = aux->_next.get();
}
}
fetchElement();
// Call user handler before HTML generation.
if (_handler) {
@ -522,6 +531,7 @@ void AutoConnectAux::_storeElements(WebServerClass* webServer) {
}
}
}
AC_DBG_DUMB(",elements stored\n");
}
#ifdef AUTOCONNECT_USE_JSON

@ -53,6 +53,7 @@ class AutoConnectAux : public PageBuilder {
AutoConnectElement& operator[](const String& name) { return *getElement(name); }
void add(AutoConnectElement& addon); /**< Add an element to the auxiliary page */
void add(AutoConnectElementVT addons); /**< Add the element set to the auxiliary page */
void fetchElement(void); /**< Fetch AutoConnectElements values from http query parameters */
template<typename T>
T& getElement(const String& name);
AutoConnectElement* getElement(const String& name); /**< Get registered AutoConnectElement as specified name */

Loading…
Cancel
Save