|
|
@ -17,88 +17,91 @@ |
|
|
|
|
|
|
|
|
|
|
|
class AutoConnect; // Reference to avoid circular
|
|
|
|
class AutoConnect; // Reference to avoid circular
|
|
|
|
|
|
|
|
|
|
|
|
// Add-on element base class
|
|
|
|
/**
|
|
|
|
|
|
|
|
* AutoConnectAux element base. |
|
|
|
|
|
|
|
* Placed a labeled button that can be added by user sketch. |
|
|
|
|
|
|
|
* @param name Button name string. |
|
|
|
|
|
|
|
* @param value Button value string. |
|
|
|
|
|
|
|
*/ |
|
|
|
class AutoConnectElement { |
|
|
|
class AutoConnectElement { |
|
|
|
public: |
|
|
|
public: |
|
|
|
explicit AutoConnectElement(const char* name, const char* value) : _name(String(name)), _value(String(value)) {} |
|
|
|
explicit AutoConnectElement(const char* name, const char* value) : name(String(name)), value(String(value)) {} |
|
|
|
virtual ~AutoConnectElement() {} |
|
|
|
virtual ~AutoConnectElement() {} |
|
|
|
const String name(void) const { return _name; } /**< Element name */ |
|
|
|
virtual const String toHTML(void) const { return value; } /**< HTML code to be generated */ |
|
|
|
const String value(void) const { return _value; } /**< Element value */ |
|
|
|
|
|
|
|
virtual const String toHTML(void) { return String(); }; /**< HTML code to be generated */ |
|
|
|
|
|
|
|
void setValue(const char* value) { _value = String(value); } |
|
|
|
|
|
|
|
void setValue(const String value) { _value = value; } |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected: |
|
|
|
String name; /**< Element name */ |
|
|
|
String _name; |
|
|
|
String value; /**< Element value */ |
|
|
|
String _value; |
|
|
|
|
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Text arrangement class, a part of AutoConnectAux element. |
|
|
|
* Button arrangement class, a part of AutoConnectAux element. |
|
|
|
* @param
|
|
|
|
* Placed a labeled button that can be added by user sketch. |
|
|
|
* @param name Text name string. |
|
|
|
* @param name Button name string. |
|
|
|
* @param value Text value string. |
|
|
|
* @param value Button value string. |
|
|
|
* @param style A string of style-code for decoration, optionally. |
|
|
|
* @param action A sting of action code, it contains a simple JavaScript code. |
|
|
|
* An arrangement text would be placed with <div> contains. A string |
|
|
|
|
|
|
|
* of style-codes are given for '<div style=>'. |
|
|
|
|
|
|
|
*/ |
|
|
|
*/ |
|
|
|
class AutoConnectText : public AutoConnectElement { |
|
|
|
class AutoConnectButton : public AutoConnectElement { |
|
|
|
public: |
|
|
|
public: |
|
|
|
explicit AutoConnectText(const char* name = "", const char* value = "", const char* style = "") : AutoConnectElement(name, value), _style(String(style)) {} |
|
|
|
explicit AutoConnectButton(const char* name = "", const char* value = "", const String action = String()) : AutoConnectElement(name, value), action(action) {} |
|
|
|
~AutoConnectText() {} |
|
|
|
const String toHTML(void) const; |
|
|
|
const String style(void) const { return _style; } /**< A modify of HTML 'style' code */ |
|
|
|
|
|
|
|
void setStyle(const char* style) { _style = String(style); } |
|
|
|
|
|
|
|
void setStyle(const String style) { _style = style; } |
|
|
|
|
|
|
|
const String toHTML(void) { |
|
|
|
|
|
|
|
return String(FPSTR("<div style=\"")) + _style + String("\">") + _value + String(FPSTR("</div>")); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected: |
|
|
|
String action; /**< A script for an onclick */ |
|
|
|
String _style; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 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 AutoConnectCheckbox : public AutoConnectElement { |
|
|
|
|
|
|
|
public: |
|
|
|
|
|
|
|
explicit AutoConnectCheckbox(const char* name = "", const char* value = "", const char* label = "") : AutoConnectElement(name, value), label(String(label)) {} |
|
|
|
|
|
|
|
~AutoConnectCheckbox() {} |
|
|
|
|
|
|
|
const String toHTML(void) const; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String label; /**< A label for a subsequent input box */ |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Input-box arrangement class, a part of AutoConnectAux element. |
|
|
|
* Input-box arrangement class, a part of AutoConnectAux element. |
|
|
|
* Place a optionally labeled input-box that can be added by user sketch. |
|
|
|
* Place a optionally labeled input-box that can be added by user sketch. |
|
|
|
* @param name Input-box name string. |
|
|
|
* @param name Input-box name string. |
|
|
|
* @param value Button value 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. |
|
|
|
* @param label A label string that follows Input-box, optionally. |
|
|
|
* The label is placed in front of Input-box. |
|
|
|
* The label is placed in front of Input-box. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
class AutoConnectInput : public AutoConnectElement { |
|
|
|
class AutoConnectInput : public AutoConnectElement { |
|
|
|
public: |
|
|
|
public: |
|
|
|
explicit AutoConnectInput(const char* name = "", const char* value = "", const char* label = "") : AutoConnectElement(name, value), _label(String(label)) {} |
|
|
|
explicit AutoConnectInput(const char* name = "", const char* value = "", const char* label = "") : AutoConnectElement(name, value), label(String(label)) {} |
|
|
|
~AutoConnectInput() {} |
|
|
|
~AutoConnectInput() {} |
|
|
|
const String label(void) const { return _label; } |
|
|
|
const String toHTML(void) const; |
|
|
|
void setLabel(const char* label) { _label = String(label); } |
|
|
|
|
|
|
|
void setLabel(const String label) { _label = label; } |
|
|
|
|
|
|
|
const String toHTML(void) { |
|
|
|
|
|
|
|
return _label + String(FPSTR("<input type=\"text\" name=\"")) + _name + String(FPSTR("\" value=\"")) + _value + String("\"><br>"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected: |
|
|
|
String label; /**< A label for a subsequent input box */ |
|
|
|
String _label; |
|
|
|
|
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Button arrangement class, a part of AutoConnectAux element. |
|
|
|
* Selection-box arrangement class, A part of AutoConnectAux element. |
|
|
|
* Placed a labeled button that can be added by user sketch. |
|
|
|
* Place a optionally labeled Selection-box that can be added by user sketch. |
|
|
|
* @param name Button name string. |
|
|
|
* @param name Input-box name string. |
|
|
|
* @param value Button value string. |
|
|
|
* @param options String array display in a selection list. |
|
|
|
* @param action A sting of action code, it contains a simple JavaScript code. |
|
|
|
* @param label A label string that follows Input-box, optionally. |
|
|
|
|
|
|
|
* The label is placed in front of Input-box. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
class AutoConnectButton : public AutoConnectElement { |
|
|
|
class AutoConnectSelect : public AutoConnectElement { |
|
|
|
public: |
|
|
|
public: |
|
|
|
explicit AutoConnectButton(const char* name = "", const char* value = "", const String action = String()) : AutoConnectElement(name, value), _action(action) {} |
|
|
|
explicit AutoConnectSelect(const char* name = "", std::vector<String> options = {}, const char* label = "") : AutoConnectElement(name, ""), label(String(label)), _options(options) {} |
|
|
|
const String action(void) const { return _action; } |
|
|
|
~AutoConnectSelect() {} |
|
|
|
void setAction(const char* action) { _action = String(action); } |
|
|
|
const String toHTML(void) const; |
|
|
|
void setAction(const String action) { _action = action; } |
|
|
|
void option(const String value) { _options.push_back(value); } |
|
|
|
const String toHTML(void) { |
|
|
|
void empty(void) { _options.clear(); } |
|
|
|
return String(FPSTR("<button type=\"button\" name=\"")) + _name + String(FPSTR("\" value=\"")) + _value + String(FPSTR("\" onclick=\"")) + _action + String("\">") + _value + String(FPSTR("</button>")); |
|
|
|
|
|
|
|
} |
|
|
|
String label; /**< A label for a subsequent input box */ |
|
|
|
|
|
|
|
|
|
|
|
protected: |
|
|
|
protected: |
|
|
|
String _action; |
|
|
|
std::vector<String> _options; /**< List options array */ |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
@ -112,16 +115,28 @@ class AutoConnectButton : public AutoConnectElement { |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
class AutoConnectSubmit : public AutoConnectElement { |
|
|
|
class AutoConnectSubmit : public AutoConnectElement { |
|
|
|
public: |
|
|
|
public: |
|
|
|
explicit AutoConnectSubmit(const char* name = "", const char* value = "", const char* uri = "") : AutoConnectElement(name, value), _uri(String(uri)) {} |
|
|
|
explicit AutoConnectSubmit(const char* name = "", const char* value = "", const char* uri = "") : AutoConnectElement(name, value), uri(String(uri)) {} |
|
|
|
const String uri(void) const { return _uri; } |
|
|
|
const String toHTML(void) const; |
|
|
|
void setUri(const char* uri) { _uri = String(uri); } |
|
|
|
|
|
|
|
void setUri(const String uri) { _uri = uri; } |
|
|
|
|
|
|
|
const String toHTML(void) { |
|
|
|
|
|
|
|
return String(FPSTR("<button type=\"submit\" name=\"")) + _name + String(FPSTR("\" value=\"")) + _value + String(FPSTR("\" onclick=\"sa('")) + _uri + String("')\">") + _value + String(FPSTR("</button>")); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected: |
|
|
|
String uri; /**< An url of submitting to */ |
|
|
|
String _uri; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 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 <div> contains. A string |
|
|
|
|
|
|
|
* of style-codes are given for '<div style=>'. |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
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 */ |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
@ -129,19 +144,20 @@ class AutoConnectSubmit : public AutoConnectElement { |
|
|
|
* arguments. These macros declare the AutoConnectElement variable |
|
|
|
* arguments. These macros declare the AutoConnectElement variable |
|
|
|
* with the same name as a "name" argument. |
|
|
|
* with the same name as a "name" argument. |
|
|
|
*/
|
|
|
|
*/
|
|
|
|
#define ACText(name, ...) AutoConnectText name(#name, ## __VA_ARGS__) |
|
|
|
#define ACElement(n, v) AutoConnectElements n(#n, v) |
|
|
|
#define ACInput(name, ...) AutoConnectInput name(#name, ## __VA_ARGS__) |
|
|
|
#define ACButton(n, ...) AutoConnectButton n(#n, ## __VA_ARGS__) |
|
|
|
#define ACButton(name, ...) AutoConnectButton name(#name, ## __VA_ARGS__) |
|
|
|
#define ACCheckbox(n, ...) AutoConnectCheckbox n(#n, ## __VA_ARGS__) |
|
|
|
#define ACSubmit(name, ...) AutoConnectSubmit name(#name, ## __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__) |
|
|
|
|
|
|
|
|
|
|
|
// Manage placed AutoConnectElement with a vector
|
|
|
|
// Manage placed AutoConnectElement with a vector
|
|
|
|
typedef std::vector<std::reference_wrapper<AutoConnectElement>> AutoConnectElementVT; |
|
|
|
typedef std::vector<std::reference_wrapper<AutoConnectElement>> AutoConnectElementVT; |
|
|
|
|
|
|
|
|
|
|
|
// To solve the forward reference.
|
|
|
|
|
|
|
|
class AutoConnectAux; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 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; |
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* A class that handles an auxiliary page with AutoConnectElement |
|
|
|
* A class that handles an auxiliary page with AutoConnectElement |
|
|
@ -149,33 +165,36 @@ typedef std::function<void(AutoConnectAux&, PageArgument&)> AuxHandleFuncT; |
|
|
|
* @param uri An uri string of this page. |
|
|
|
* @param uri An uri string of this page. |
|
|
|
* @param title A title string of this page. |
|
|
|
* @param title A title string of this page. |
|
|
|
* @param addons A set of AutoConnectElement vector. |
|
|
|
* @param addons A set of AutoConnectElement vector. |
|
|
|
|
|
|
|
* @param menu A switch for item displaying in AutoConnect menu. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
class AutoConnectAux : public PageBuilder { |
|
|
|
class AutoConnectAux : public PageBuilder { |
|
|
|
public: |
|
|
|
public: |
|
|
|
explicit AutoConnectAux(const char* uri = nullptr, const char* title = "", const AutoConnectElementVT addons = AutoConnectElementVT()) : |
|
|
|
explicit AutoConnectAux(const char* uri = nullptr, const char* title = "", const bool menu = true, const AutoConnectElementVT addons = AutoConnectElementVT()) : |
|
|
|
_title(String(title)), _addonElm(addons) { setUri(uri); _next.release(); _ac.release(); _handler = nullptr; } |
|
|
|
_title(String(title)), _menu(menu), _addonElm(addons) { setUri(uri); _next.release(); _ac.release(); } |
|
|
|
~AutoConnectAux(); |
|
|
|
~AutoConnectAux(); |
|
|
|
void add(AutoConnectElement& addon); /**< Add an element to the auxiliary page. */ |
|
|
|
void add(AutoConnectElement& addon); /**< Add an element to the auxiliary page. */ |
|
|
|
void add(AutoConnectElementVT addons); /**< Add the element set to the auxiliary page. */ |
|
|
|
void add(AutoConnectElementVT addons); /**< Add the element set to the auxiliary page. */ |
|
|
|
|
|
|
|
bool release(const char* name) { return release(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 on(const AuxHandleFuncT handler) { _handler = &handler; } /**< Set user handler */ |
|
|
|
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 */ |
|
|
|
|
|
|
|
|
|
|
|
protected: |
|
|
|
protected: |
|
|
|
void _concat(AutoConnectAux& aux); |
|
|
|
void _concat(AutoConnectAux& aux); |
|
|
|
void _join(AutoConnect& ac); |
|
|
|
void _join(AutoConnect& ac); |
|
|
|
PageElement* _setupPage(String uri); |
|
|
|
PageElement* _setupPage(String uri); |
|
|
|
const String _insertElement(PageArgument& args); |
|
|
|
const String _insertElement(PageArgument& args); |
|
|
|
const String _injectTitle(PageArgument& args) { return _title.length() > 0 ? _title : _activeTitle; } |
|
|
|
const String _injectTitle(PageArgument& args) { return _title; } |
|
|
|
const String _injectMenu(PageArgument& args); |
|
|
|
const String _injectMenu(PageArgument& args); |
|
|
|
const String _exitHandle(PageArgument& args); |
|
|
|
const String _exitHandle(PageArgument& args); |
|
|
|
|
|
|
|
|
|
|
|
String _title; /**< A title of the page */ |
|
|
|
String _title; /**< A title of the page */ |
|
|
|
String _activeTitle; /**< Previous title of the page */ |
|
|
|
bool _menu; /**< Switch for menu displaying */ |
|
|
|
|
|
|
|
|
|
|
|
AutoConnectElementVT _addonElm; /**< A vector set of AutoConnectElements placed on this auxiliary page */ |
|
|
|
AutoConnectElementVT _addonElm; /**< A vector set of AutoConnectElements placed on this auxiliary page */ |
|
|
|
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 */ |
|
|
|
const AuxHandleFuncT* _handler; /**< User sketch callback function when AutoConnectAux page requested. */ |
|
|
|
AuxHandlerFunctionT _handler; /**< User sketch callback function when AutoConnectAux page requested. */ |
|
|
|
|
|
|
|
|
|
|
|
static const char _PAGE_AUX[] PROGMEM; /**< Auxiliary page template */ |
|
|
|
static const char _PAGE_AUX[] PROGMEM; /**< Auxiliary page template */ |
|
|
|
|
|
|
|
|
|
|
|