|
|
|
@ -17,88 +17,91 @@ |
|
|
|
|
|
|
|
|
|
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 { |
|
|
|
|
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() {} |
|
|
|
|
const String name(void) const { return _name; } /**< Element name */ |
|
|
|
|
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; } |
|
|
|
|
virtual const String toHTML(void) const { return value; } /**< HTML code to be generated */ |
|
|
|
|
|
|
|
|
|
protected: |
|
|
|
|
String _name; |
|
|
|
|
String _value; |
|
|
|
|
String name; /**< Element name */ |
|
|
|
|
String value; /**< Element value */ |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 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=>'. |
|
|
|
|
* Button arrangement class, a part of AutoConnectAux element. |
|
|
|
|
* Placed a labeled button that can be added by user sketch. |
|
|
|
|
* @param name Button name string. |
|
|
|
|
* @param value Button value string. |
|
|
|
|
* @param action A sting of action code, it contains a simple JavaScript code. |
|
|
|
|
*/ |
|
|
|
|
class AutoConnectText : public AutoConnectElement { |
|
|
|
|
class AutoConnectButton : public AutoConnectElement { |
|
|
|
|
public: |
|
|
|
|
explicit AutoConnectText(const char* name = "", const char* value = "", const char* style = "") : AutoConnectElement(name, value), _style(String(style)) {} |
|
|
|
|
~AutoConnectText() {} |
|
|
|
|
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>")); |
|
|
|
|
} |
|
|
|
|
explicit AutoConnectButton(const char* name = "", const char* value = "", const String action = String()) : AutoConnectElement(name, value), action(action) {} |
|
|
|
|
const String toHTML(void) const; |
|
|
|
|
|
|
|
|
|
protected: |
|
|
|
|
String _style; |
|
|
|
|
String action; /**< A script for an onclick */ |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 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. |
|
|
|
|
* Place a optionally labeled input-box that can be added by user sketch. |
|
|
|
|
* @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. |
|
|
|
|
* The label is placed in front of Input-box. |
|
|
|
|
*/ |
|
|
|
|
class AutoConnectInput : public AutoConnectElement { |
|
|
|
|
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() {} |
|
|
|
|
const String label(void) const { return _label; } |
|
|
|
|
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>"); |
|
|
|
|
} |
|
|
|
|
const String toHTML(void) const; |
|
|
|
|
|
|
|
|
|
protected: |
|
|
|
|
String _label; |
|
|
|
|
String label; /**< A label for a subsequent input box */ |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Button arrangement class, a part of AutoConnectAux element. |
|
|
|
|
* Placed a labeled button that can be added by user sketch. |
|
|
|
|
* @param name Button name string. |
|
|
|
|
* @param value Button value string. |
|
|
|
|
* @param action A sting of action code, it contains a simple JavaScript code. |
|
|
|
|
* Selection-box arrangement class, A part of AutoConnectAux element. |
|
|
|
|
* Place a optionally labeled Selection-box that can be added by user sketch. |
|
|
|
|
* @param name Input-box name string. |
|
|
|
|
* @param options String array display in a selection list. |
|
|
|
|
* @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: |
|
|
|
|
explicit AutoConnectButton(const char* name = "", const char* value = "", const String action = String()) : AutoConnectElement(name, value), _action(action) {} |
|
|
|
|
const String action(void) const { return _action; } |
|
|
|
|
void setAction(const char* action) { _action = String(action); } |
|
|
|
|
void setAction(const String action) { _action = action; } |
|
|
|
|
const String toHTML(void) { |
|
|
|
|
return String(FPSTR("<button type=\"button\" name=\"")) + _name + String(FPSTR("\" value=\"")) + _value + String(FPSTR("\" onclick=\"")) + _action + String("\">") + _value + String(FPSTR("</button>")); |
|
|
|
|
} |
|
|
|
|
explicit AutoConnectSelect(const char* name = "", std::vector<String> options = {}, const char* label = "") : AutoConnectElement(name, ""), label(String(label)), _options(options) {} |
|
|
|
|
~AutoConnectSelect() {} |
|
|
|
|
const String toHTML(void) const; |
|
|
|
|
void option(const String value) { _options.push_back(value); } |
|
|
|
|
void empty(void) { _options.clear(); } |
|
|
|
|
|
|
|
|
|
String label; /**< A label for a subsequent input box */ |
|
|
|
|
|
|
|
|
|
protected: |
|
|
|
|
String _action; |
|
|
|
|
std::vector<String> _options; /**< List options array */ |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -112,16 +115,28 @@ class AutoConnectButton : public AutoConnectElement { |
|
|
|
|
*/ |
|
|
|
|
class AutoConnectSubmit : public AutoConnectElement { |
|
|
|
|
public: |
|
|
|
|
explicit AutoConnectSubmit(const char* name = "", const char* value = "", const char* uri = "") : AutoConnectElement(name, value), _uri(String(uri)) {} |
|
|
|
|
const String uri(void) const { return _uri; } |
|
|
|
|
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>")); |
|
|
|
|
} |
|
|
|
|
explicit AutoConnectSubmit(const char* name = "", const char* value = "", const char* uri = "") : AutoConnectElement(name, value), uri(String(uri)) {} |
|
|
|
|
const String toHTML(void) const; |
|
|
|
|
|
|
|
|
|
protected: |
|
|
|
|
String _uri; |
|
|
|
|
String uri; /**< An url of submitting to */ |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 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 |
|
|
|
|
* with the same name as a "name" argument. |
|
|
|
|
*/
|
|
|
|
|
#define ACText(name, ...) AutoConnectText name(#name, ## __VA_ARGS__) |
|
|
|
|
#define ACInput(name, ...) AutoConnectInput name(#name, ## __VA_ARGS__) |
|
|
|
|
#define ACButton(name, ...) AutoConnectButton name(#name, ## __VA_ARGS__) |
|
|
|
|
#define ACSubmit(name, ...) AutoConnectSubmit name(#name, ## __VA_ARGS__) |
|
|
|
|
#define ACElement(n, v) AutoConnectElements n(#n, v) |
|
|
|
|
#define ACButton(n, ...) AutoConnectButton n(#n, ## __VA_ARGS__) |
|
|
|
|
#define ACCheckbox(n, ...) AutoConnectCheckbox n(#n, ## __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
|
|
|
|
|
typedef std::vector<std::reference_wrapper<AutoConnectElement>> AutoConnectElementVT; |
|
|
|
|
|
|
|
|
|
// To solve the forward reference.
|
|
|
|
|
class AutoConnectAux; |
|
|
|
|
|
|
|
|
|
// 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 |
|
|
|
@ -149,33 +165,36 @@ typedef std::function<void(AutoConnectAux&, PageArgument&)> AuxHandleFuncT; |
|
|
|
|
* @param uri An uri string of this page. |
|
|
|
|
* @param title A title string of this page. |
|
|
|
|
* @param addons A set of AutoConnectElement vector. |
|
|
|
|
* @param menu A switch for item displaying in AutoConnect menu. |
|
|
|
|
*/ |
|
|
|
|
class AutoConnectAux : public PageBuilder { |
|
|
|
|
public: |
|
|
|
|
explicit AutoConnectAux(const char* uri = nullptr, const char* title = "", const AutoConnectElementVT addons = AutoConnectElementVT()) : |
|
|
|
|
_title(String(title)), _addonElm(addons) { setUri(uri); _next.release(); _ac.release(); _handler = nullptr; } |
|
|
|
|
explicit AutoConnectAux(const char* uri = nullptr, const char* title = "", const bool menu = true, const AutoConnectElementVT addons = AutoConnectElementVT()) : |
|
|
|
|
_title(String(title)), _menu(menu), _addonElm(addons) { setUri(uri); _next.release(); _ac.release(); } |
|
|
|
|
~AutoConnectAux(); |
|
|
|
|
void add(AutoConnectElement& addon); /**< Add an element 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 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: |
|
|
|
|
void _concat(AutoConnectAux& aux); |
|
|
|
|
void _join(AutoConnect& ac); |
|
|
|
|
PageElement* _setupPage(String uri); |
|
|
|
|
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 _exitHandle(PageArgument& args); |
|
|
|
|
|
|
|
|
|
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 */ |
|
|
|
|
std::unique_ptr<AutoConnectAux> _next; /**< Auxiliary pages chain list */ |
|
|
|
|
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 */ |
|
|
|
|
|
|
|
|
|