|
|
|
@ -51,6 +51,11 @@ const char AutoConnectAux::_PAGE_AUX[] PROGMEM = { |
|
|
|
|
"</div>" |
|
|
|
|
"<script>" |
|
|
|
|
"function _sa(url) {" |
|
|
|
|
"var uri=document.createElement('input');" |
|
|
|
|
"uri.setAttribute('type','hidden');" |
|
|
|
|
"uri.setAttribute('name','uri');" |
|
|
|
|
"uri.setAttribute('value','{{AUX_URI}}');" |
|
|
|
|
"document.getElementById('_aux').appendChild(uri);" |
|
|
|
|
"document.getElementById('_aux').action=url;" |
|
|
|
|
"document.getElementById('_aux').submit();" |
|
|
|
|
"}" |
|
|
|
@ -122,6 +127,28 @@ bool AutoConnectAux::release(const String& name) { |
|
|
|
|
return rc; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Set the value to AutoConnectRadio element. |
|
|
|
|
* @param name A string of AutoConnectRadio element name to set the value. |
|
|
|
|
* @param checked A checked value. |
|
|
|
|
* @return true The value was set. |
|
|
|
|
* @return false An element specified name is not registered, |
|
|
|
|
* or its element value does not match storage type. |
|
|
|
|
*/ |
|
|
|
|
//bool AutoConnectAux::setElementValue(const String& name, const uint8_t checked) {
|
|
|
|
|
// AutoConnectElement* elm = getElement(name);
|
|
|
|
|
// if (elm) {
|
|
|
|
|
// if (elm->typeOf() == AC_Radio) {
|
|
|
|
|
// AutoConnectRadio* elmRadio = reinterpret_cast<AutoConnectRadio*>(elm);
|
|
|
|
|
// elmRadio->checked = checked;
|
|
|
|
|
// return true;
|
|
|
|
|
// }
|
|
|
|
|
// else
|
|
|
|
|
// AC_DBG("Element<%s> value type mismatch\n", name.c_str());
|
|
|
|
|
// }
|
|
|
|
|
// return false;
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Set the value to specified element. |
|
|
|
|
* @param name A string of element name to set the value. |
|
|
|
@ -133,8 +160,19 @@ bool AutoConnectAux::release(const String& name) { |
|
|
|
|
bool AutoConnectAux::setElementValue(const String& name, const String value) { |
|
|
|
|
AutoConnectElement* elm = getElement(name); |
|
|
|
|
if (elm) { |
|
|
|
|
if (elm->typeOf() != AC_Select && elm->typeOf() != AC_Radio) { |
|
|
|
|
elm->value = value; |
|
|
|
|
if (elm->typeOf() != AC_Select) { |
|
|
|
|
if (elm->typeOf() == AC_Checkbox) { |
|
|
|
|
if (value == "checked") { |
|
|
|
|
AutoConnectCheckbox* elmCheckbox = reinterpret_cast<AutoConnectCheckbox*>(elm); |
|
|
|
|
elmCheckbox->checked = true; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
else if (elm->typeOf() == AC_Radio) { |
|
|
|
|
AutoConnectRadio* elmRadio = reinterpret_cast<AutoConnectRadio*>(elm); |
|
|
|
|
elmRadio->checked = static_cast<uint8_t>(value.toInt()); |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
elm->value = value; |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
@ -213,6 +251,16 @@ void AutoConnectAux::_join(AutoConnect& ac) { |
|
|
|
|
_next->_join(ac); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Insert the uri that caused the request to the aux. |
|
|
|
|
*/ |
|
|
|
|
const String AutoConnectAux::_indicateUri(PageArgument& args) { |
|
|
|
|
AC_UNUSED(args); |
|
|
|
|
String lastUri = _ac->_auxLastUri; |
|
|
|
|
lastUri.replace(String("/"), String("/")); |
|
|
|
|
return lastUri; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Insert the token handler of PageBuilder. This handler inserts HTML |
|
|
|
|
* elements generated by the whole AutoConnectElements to the auxiliary page. |
|
|
|
@ -220,12 +268,38 @@ void AutoConnectAux::_join(AutoConnect& ac) { |
|
|
|
|
* @return HTML string that should be inserted. |
|
|
|
|
*/ |
|
|
|
|
const String AutoConnectAux::_insertElement(PageArgument& args) { |
|
|
|
|
AC_UNUSED(args); |
|
|
|
|
String body = String(); |
|
|
|
|
// Save elements owned by AutoConnectAux that caused the request.
|
|
|
|
|
String auxUri = args.arg("uri"); |
|
|
|
|
if (auxUri.length()) { |
|
|
|
|
auxUri.replace(String("/"), String("/")); |
|
|
|
|
AutoConnectAux* auxPage = _ac->_aux.get(); |
|
|
|
|
while (auxPage) { |
|
|
|
|
if (auxPage->_uriStr == auxUri) |
|
|
|
|
break; |
|
|
|
|
auxPage = auxPage->_next.get(); |
|
|
|
|
} |
|
|
|
|
// Caused page is exist, restore elements value.
|
|
|
|
|
if (auxPage) { |
|
|
|
|
for (size_t n = 0; n < args.size(); n++) { |
|
|
|
|
String elmName = args.argName(n); |
|
|
|
|
String elmValue = args.arg(n); |
|
|
|
|
AutoConnectElement* elm = auxPage->getElement(elmName); |
|
|
|
|
if (elm) { |
|
|
|
|
if (elm->typeOf() == AC_Checkbox) |
|
|
|
|
elmValue = "checked"; |
|
|
|
|
auxPage->setElementValue(elmName, elmValue); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
// Save invoked Aux.
|
|
|
|
|
_ac->_auxLastUri = _uriStr; |
|
|
|
|
|
|
|
|
|
// Build the current Aux page.
|
|
|
|
|
String body = String(); |
|
|
|
|
if (_handler) { |
|
|
|
|
if (_order & AC_EXIT_AHEAD) { |
|
|
|
|
AC_DBG("CB %s\n", uri()); |
|
|
|
|
AC_DBG("CB in AHEAD %s\n", uri()); |
|
|
|
|
body += _handler(*this, args); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -237,11 +311,10 @@ const String AutoConnectAux::_insertElement(PageArgument& args) { |
|
|
|
|
|
|
|
|
|
if (_handler) { |
|
|
|
|
if (_order & AC_EXIT_LATER) { |
|
|
|
|
AC_DBG("CB %s\n", uri()); |
|
|
|
|
AC_DBG("CB in LATER %s\n", uri()); |
|
|
|
|
body += _handler(*this, args); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return body; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -281,6 +354,7 @@ PageElement* AutoConnectAux::_setupPage(String uri) { |
|
|
|
|
elm->addToken(String(FPSTR("MENU_PRE")), std::bind(&AutoConnect::_token_MENU_PRE, mother, std::placeholders::_1)); |
|
|
|
|
elm->addToken(String(FPSTR("MENU_AUX")), std::bind(&AutoConnect::_token_MENU_AUX, mother, std::placeholders::_1)); |
|
|
|
|
elm->addToken(String(FPSTR("MENU_POST")), std::bind(&AutoConnect::_token_MENU_POST, mother, std::placeholders::_1)); |
|
|
|
|
elm->addToken(String(FPSTR("AUX_URI")), std::bind(&AutoConnectAux::_indicateUri, this, std::placeholders::_1)); |
|
|
|
|
elm->addToken(String(FPSTR("AUX_ELEMENT")), std::bind(&AutoConnectAux::_insertElement, this, std::placeholders::_1)); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -879,6 +953,9 @@ size_t AutoConnectAux::saveElement(Stream& out, std::vector<String> const& names |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
size_n = element.printTo(out); |
|
|
|
|
AC_DBG(""); |
|
|
|
|
element.printTo(Serial); |
|
|
|
|
AC_DBG_DUMB("\n"); |
|
|
|
|
} |
|
|
|
|
else if (amount == 0) { |
|
|
|
|
JsonObject& json = jb.createObject(); |
|
|
|
@ -892,6 +969,9 @@ size_t AutoConnectAux::saveElement(Stream& out, std::vector<String> const& names |
|
|
|
|
elm.serialize(element); |
|
|
|
|
} |
|
|
|
|
size_n = json.prettyPrintTo(out); |
|
|
|
|
AC_DBG(""); |
|
|
|
|
json.printTo(Serial); |
|
|
|
|
AC_DBG_DUMB("\n"); |
|
|
|
|
} |
|
|
|
|
else if (amount >= 2) { |
|
|
|
|
JsonArray& elements = jb.createArray(); |
|
|
|
@ -906,6 +986,9 @@ size_t AutoConnectAux::saveElement(Stream& out, std::vector<String> const& names |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
size_n = elements.prettyPrintTo(out); |
|
|
|
|
AC_DBG(""); |
|
|
|
|
elements.printTo(Serial); |
|
|
|
|
AC_DBG_DUMB("\n"); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return size_n; |
|
|
|
|