Supports AutoConnectAux

pull/41/head
Hieromon Ikasamo 6 years ago
parent bc03f917f7
commit ad07e1b448
  1. 30
      src/AutoConnectAux.cpp
  2. 16
      src/AutoConnectAux.h
  3. 5
      src/AutoConnectPage.cpp

@ -23,7 +23,6 @@
* the behavior of AutoConnectSubmit. * the behavior of AutoConnectSubmit.
*/ */
const char AutoConnectAux::_PAGE_AUX[] PROGMEM = { const char AutoConnectAux::_PAGE_AUX[] PROGMEM = {
"{{EXIT_HANDLE}}"
"{{HEAD}}" "{{HEAD}}"
"<title>{{AUX_TITLE}}</title>" "<title>{{AUX_TITLE}}</title>"
"<style type=\"text/css\">" "<style type=\"text/css\">"
@ -40,7 +39,7 @@ const char AutoConnectAux::_PAGE_AUX[] PROGMEM = {
"{{MENU_AUX}}" "{{MENU_AUX}}"
"{{MENU_POST}}" "{{MENU_POST}}"
"<div class=\"base-panel\"><div class=\"aux-page\">" "<div class=\"base-panel\"><div class=\"aux-page\">"
"<form id='_aux' method=\"post\">" "<form id='_aux' method=\"post\" onsubmit=\"return false;\">"
"<ul class=\"noorder\">" "<ul class=\"noorder\">"
"{{AUX_ELEMENT}}" "{{AUX_ELEMENT}}"
"</ul>" "</ul>"
@ -78,6 +77,8 @@ const String AutoConnectCheckbox::toHTML(void) const {
String html; String html;
html = String(FPSTR("<input type=\"checkbox\" name=\"")) + name + String(FPSTR("\" value=\"")) + value + String("\""); html = String(FPSTR("<input type=\"checkbox\" name=\"")) + name + String(FPSTR("\" value=\"")) + value + String("\"");
if (checked)
html += String(FPSTR(" checked"));
if (label.length()) if (label.length())
html += String(" id=\"") + name + String("\"><label for=\"") + name + String("\">") + label + String(FPSTR("</label")); html += String(" id=\"") + name + String("\"><label for=\"") + name + String("\">") + label + String(FPSTR("</label"));
html += String(FPSTR("><br>")); html += String(FPSTR("><br>"));
@ -238,10 +239,23 @@ const String AutoConnectAux::_insertElement(PageArgument& args) {
AC_UNUSED(args); AC_UNUSED(args);
String body = String(); String body = String();
if (_handler)
if (_order & AC_EXIT_AHEAD) {
AC_DBG("CB %s\n", uri());
body += _handler(args);
}
for (std::size_t n = 0; n < _addonElm.size(); n++) { for (std::size_t n = 0; n < _addonElm.size(); n++) {
AutoConnectElement& addon = _addonElm[n]; AutoConnectElement& addon = _addonElm[n];
body += addon.toHTML(); body += addon.toHTML();
} }
if (_handler)
if (_order & AC_EXIT_LATER) {
AC_DBG("CB %s\n", uri());
body += _handler(args);
}
return body; return body;
} }
@ -271,7 +285,6 @@ PageElement* AutoConnectAux::_setupPage(String uri) {
elm = new PageElement(); elm = new PageElement();
// Construct the auxiliary page // Construct the auxiliary page
elm->setMold(_PAGE_AUX); elm->setMold(_PAGE_AUX);
elm->addToken(PSTR("EXIT_HANDLE"), std::bind(&AutoConnectAux::_exitHandle, this, std::placeholders::_1));
elm->addToken(PSTR("HEAD"), std::bind(&AutoConnect::_token_HEAD, mother, std::placeholders::_1)); elm->addToken(PSTR("HEAD"), std::bind(&AutoConnect::_token_HEAD, mother, std::placeholders::_1));
elm->addToken(PSTR("AUX_TITLE"), std::bind(&AutoConnectAux::_injectTitle, this, std::placeholders::_1)); elm->addToken(PSTR("AUX_TITLE"), std::bind(&AutoConnectAux::_injectTitle, this, std::placeholders::_1));
elm->addToken(PSTR("CSS_BASE"), std::bind(&AutoConnect::_token_CSS_BASE, mother, std::placeholders::_1)); elm->addToken(PSTR("CSS_BASE"), std::bind(&AutoConnect::_token_CSS_BASE, mother, std::placeholders::_1));
@ -305,14 +318,3 @@ const String AutoConnectAux::_injectMenu(PageArgument& args) {
menuItem += _next->_injectMenu(args); menuItem += _next->_injectMenu(args);
return menuItem; return menuItem;
} }
/**
* The 'on' handler callback behavior wrapper.
*/
const String AutoConnectAux::_exitHandle(PageArgument& args) {
if (_handler) {
AC_DBG("CB %s\n", uri());
_handler(args);
}
return "";
}

@ -58,11 +58,12 @@ class AutoConnectButton : public AutoConnectElement {
*/ */
class AutoConnectCheckbox : public AutoConnectElement { class AutoConnectCheckbox : public AutoConnectElement {
public: public:
explicit AutoConnectCheckbox(const char* name = "", const char* value = "", const char* label = "") : AutoConnectElement(name, value), label(String(label)) {} explicit AutoConnectCheckbox(const char* name = "", const char* value = "", const char* label = "", const bool checked = false) : AutoConnectElement(name, value), label(String(label)), checked(checked) {}
~AutoConnectCheckbox() {} ~AutoConnectCheckbox() {}
const String toHTML(void) const; const String toHTML(void) const;
String label; /**< A label for a subsequent input box */ String label; /**< A label for a subsequent input box */
bool checked; /**< The element should be pre-selected */
}; };
/** /**
@ -157,7 +158,14 @@ typedef std::vector<std::reference_wrapper<AutoConnectElement>> AutoConnectEleme
// A type of callback function when AutoConnectAux page requested. // A type of callback function when AutoConnectAux page requested.
//typedef std::function<void(AutoConnectAux&, PageArgument&)> AuxHandleFuncT; //typedef std::function<void(AutoConnectAux&, PageArgument&)> AuxHandleFuncT;
typedef std::function<void(PageArgument&)> AuxHandlerFunctionT; typedef std::function<String(PageArgument&)> AuxHandlerFunctionT;
// A type for the order in which callback functions are called.
typedef enum {
AC_EXIT_AHEAD = 1,
AC_EXIT_LATER = 2,
AC_EXIT_BOTH = 3
} AutoConnectExitOrder_t;
/** /**
* A class that handles an auxiliary page with AutoConnectElement * A class that handles an auxiliary page with AutoConnectElement
@ -178,7 +186,7 @@ class AutoConnectAux : public PageBuilder {
bool release(const String name); /**< Release an AutoConnectElement */ bool release(const String name); /**< Release an AutoConnectElement */
void setTitle(const char* title) { _title = String(title); } /**< Set a title of the auxiliary page. */ void setTitle(const char* title) { _title = String(title); } /**< Set a title of the auxiliary page. */
void menu(const bool post) { _menu = post; } /**< Set or reset the display as menu item for this aux. */ void menu(const bool post) { _menu = post; } /**< Set or reset the display as menu item for this aux. */
void on(const AuxHandlerFunctionT handler) { _handler = handler; } /**< Set user handler */ void on(const AuxHandlerFunctionT handler, const AutoConnectExitOrder_t order = AC_EXIT_AHEAD) { _handler = handler; _order = order; } /**< Set user handler */
protected: protected:
void _concat(AutoConnectAux& aux); void _concat(AutoConnectAux& aux);
@ -187,7 +195,6 @@ class AutoConnectAux : public PageBuilder {
const String _insertElement(PageArgument& args); const String _insertElement(PageArgument& args);
const String _injectTitle(PageArgument& args) { return _title; } const String _injectTitle(PageArgument& args) { return _title; }
const String _injectMenu(PageArgument& args); const String _injectMenu(PageArgument& args);
const String _exitHandle(PageArgument& args);
String _title; /**< A title of the page */ String _title; /**< A title of the page */
bool _menu; /**< Switch for menu displaying */ bool _menu; /**< Switch for menu displaying */
@ -195,6 +202,7 @@ class AutoConnectAux : public PageBuilder {
std::unique_ptr<AutoConnectAux> _next; /**< Auxiliary pages chain list */ std::unique_ptr<AutoConnectAux> _next; /**< Auxiliary pages chain list */
std::unique_ptr<AutoConnect> _ac; /**< Hosted AutoConnect instance */ std::unique_ptr<AutoConnect> _ac; /**< Hosted AutoConnect instance */
AuxHandlerFunctionT _handler; /**< User sketch callback function when AutoConnectAux page requested. */ AuxHandlerFunctionT _handler; /**< User sketch callback function when AutoConnectAux page requested. */
AutoConnectExitOrder_t _order; /**< The order in which callback functions are called. */
static const char _PAGE_AUX[] PROGMEM; /**< Auxiliary page template */ static const char _PAGE_AUX[] PROGMEM; /**< Auxiliary page template */

@ -477,7 +477,7 @@ const char AutoConnect::_ELM_MENU_PRE[] PROGMEM = {
}; };
const char AutoConnect::_ELM_MENU_AUX[] PROGMEM = { const char AutoConnect::_ELM_MENU_AUX[] PROGMEM = {
"{{AUX_MENU}}" "{{AUX_MENU}}"
}; };
const char AutoConnect::_ELM_MENU_POST[] PROGMEM = { const char AutoConnect::_ELM_MENU_POST[] PROGMEM = {
@ -712,7 +712,8 @@ const char AutoConnect::_PAGE_SUCCESS[] PROGMEM = {
"</body>" "</body>"
"</html>" "</html>"
}; };
/**< A response page for connection failed. */
/**< A response page for connection failed. */
const char AutoConnect::_PAGE_FAIL[] PROGMEM = { const char AutoConnect::_PAGE_FAIL[] PROGMEM = {
"{{HEAD}}" "{{HEAD}}"
"<title>AutoConnect statistics</title>" "<title>AutoConnect statistics</title>"

Loading…
Cancel
Save