modify templates, remove placeholders

adds labels to all inputs, deprecates {p} placeholders, adds {t} to ttitles
This commit is contained in:
Shawn A
2017-09-14 15:38:12 -05:00
parent c6f7ac0012
commit e43a7d0b75
2 changed files with 76 additions and 49 deletions
+71 -46
View File
@@ -592,78 +592,103 @@ void WiFiManager::handleWifi(boolean scan) {
}
}
page += FPSTR(HTTP_FORM_START);
char parLength[5];
// add the extra parameters to the form
for (int i = 0; i < _paramsCount; i++) {
if (_params[i] == NULL) {
break;
}
String pitem = FPSTR(HTTP_FORM_START);
pitem.replace("{v}", WiFi.SSID());
page += pitem;
//String pitem = FPSTR(HTTP_FORM_PARAM);
String pitem;
switch (_params[i]->getLabelPlacement()) {
case WFM_LABEL_BEFORE:
pitem = FPSTR(HTTP_FORM_LABEL);
pitem += FPSTR(HTTP_FORM_PARAM);
break;
case WFM_LABEL_AFTER:
pitem = FPSTR(HTTP_FORM_PARAM);
pitem += FPSTR(HTTP_FORM_LABEL);
break;
default:
// WFM_NO_LABEL
pitem = FPSTR(HTTP_FORM_PARAM);
break;
}
if (_params[i]->getID() != NULL) {
pitem.replace("{i}", _params[i]->getID());
pitem.replace("{n}", _params[i]->getID());
pitem.replace("{p}", _params[i]->getPlaceholder());
snprintf(parLength, 5, "%d", _params[i]->getValueLength());
pitem.replace("{l}", parLength);
pitem.replace("{v}", _params[i]->getValue());
pitem.replace("{c}", _params[i]->getCustomHTML()); // additional attributes not html
} else {
pitem = _params[i]->getCustomHTML();
}
page += pitem;
}
if (_params[0] != NULL) {
page += "<br/>";
if(_paramsCount > 0){
page += FPSTR(HTTP_FORM_PARAM_START);
char parLength[5];
// add the extra parameters to the form
for (int i = 0; i < _paramsCount; i++) {
if (_params[i] == NULL) {
break;
}
String pitem;
switch (_params[i]->getLabelPlacement()) {
case WFM_LABEL_BEFORE:
pitem = FPSTR(HTTP_FORM_LABEL);
pitem += FPSTR(HTTP_FORM_PARAM);
break;
case WFM_LABEL_AFTER:
pitem = FPSTR(HTTP_FORM_PARAM);
pitem += FPSTR(HTTP_FORM_LABEL);
break;
default:
// WFM_NO_LABEL
pitem = FPSTR(HTTP_FORM_PARAM);
break;
}
if (_params[i]->getID() != NULL) {
pitem.replace("{i}", _params[i]->getID());
pitem.replace("{n}", _params[i]->getID());
pitem.replace("{p}", "{t}");
pitem.replace("{t}", _params[i]->getPlaceholder());
snprintf(parLength, 5, "%d", _params[i]->getValueLength());
pitem.replace("{l}", parLength);
pitem.replace("{v}", _params[i]->getValue());
pitem.replace("{c}", _params[i]->getCustomHTML()); // additional attributes not html
} else {
pitem = _params[i]->getCustomHTML();
}
page += pitem;
}
if (_params[0] != NULL) {
page += FPSTR(HTTP_FORM_PARAM_END);
}
}
if (_sta_show_static_fields || _sta_static_ip) {
String item = FPSTR(HTTP_FORM_PARAM);
// @todo how do we get these settings from memory , wifi_get_ip_info does not seem to reveal if struct ip_info is static or not
// @todo move titles to params for i18n
String item = FPSTR(HTTP_FORM_LABEL);
item += FPSTR(HTTP_FORM_PARAM);
item.replace("{i}", "ip");
item.replace("{n}", "ip");
item.replace("{p}", "Static IP");
item.replace("{p}", "{t}");
item.replace("{t}", "Static IP");
item.replace("{l}", "15");
item.replace("{v}", (_sta_static_ip ? _sta_static_ip.toString() : ""));
// IPAddress sta_ip = WiFi.localIP();
// item.replace("{p}", sta_ip.toString());
page += item;
item = FPSTR(HTTP_FORM_PARAM);
item = FPSTR(HTTP_FORM_LABEL);
item += FPSTR(HTTP_FORM_PARAM);
item.replace("{i}", "gw");
item.replace("{n}", "gw");
item.replace("{p}", "Static Gateway");
item.replace("{p}", "{t}");
item.replace("{t}", "Static Gateway");
item.replace("{l}", "15");
item.replace("{v}", (_sta_static_gw ? _sta_static_gw.toString() : ""));
// IPAddress sta_gateway = WiFi.gatewayIP();
// item.replace("{p}", sta_gateway.toString());
page += item;
item = FPSTR(HTTP_FORM_PARAM);
item = FPSTR(HTTP_FORM_LABEL);
item += FPSTR(HTTP_FORM_PARAM);
item.replace("{i}", "sn");
item.replace("{n}", "sn");
item.replace("{p}", "Subnet");
item.replace("{p}", "{t}");
item.replace("{t}", "Subnet");
item.replace("{l}", "15");
item.replace("{v}", (_sta_static_sn ? _sta_static_sn.toString() : ""));
// IPAddress sta_subnet = WiFi.subnetMask();
// item.replace("{p}", sta_subnet.toString());
page += item;
page += "<br/>";
page += "<br/>"; // @todo remove these, use css
}
page += FPSTR(HTTP_FORM_END);
+5 -3
View File
@@ -47,10 +47,12 @@ const char HTTP_HEAD_END[] PROGMEM = "</head><body><div class='wrap'>";
const char HTTP_PORTAL_OPTIONS[] PROGMEM = "<form action='/wifi' method='GET'><button>Configure WiFi</button></form><br/><form action='/0wifi' method='GET'><button>Configure WiFi (No Scan)</button></form><br/><form action='/i' method='GET'><button>Info</button></form><br/><form action='/r' method='GET'><button>Restart</button></form>";
const char HTTP_ITEM[] PROGMEM = "<div><a href='#p' onclick='c(this)'>{v}</a><div role='img' aria-label='{r}%' title='{r}%' class='q q-{q} {i}'></div></div>";
//const char HTTP_ITEM_PADLOCK[] PROGMEM = "<img src='data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAMAAABEpIrGAAAALVBMVEX///8EBwfBwsLw8PAzNjaCg4NTVVUjJiZDRUUUFxdiZGSho6OSk5Pg4eFydHTCjaf3AAAAZElEQVQ4je2NSw7AIAhEBamKn97/uMXEGBvozkWb9C2Zx4xzWykBhFAeYp9gkLyZE0zIMno9n4g19hmdY39scwqVkOXaxph0ZCXQcqxSpgQpONa59wkRDOL93eAXvimwlbPbwwVAegLS1HGfZAAAAABJRU5ErkJggg==' width='13px'/>";
const char HTTP_FORM_START[] PROGMEM = "<form method='POST' action='wifisave'><input id='s' name='s' maxlength=32 placeholder='SSID'><br/><input id='p' name='p' length=64 type='password' placeholder='password'><br/>";
const char HTTP_FORM_LABEL[] PROGMEM = "<label for='{i}'>{p}</label>";
const char HTTP_FORM_PARAM[] PROGMEM = "<br/><input id='{i}' name='{n}' maxlength={l} placeholder='{p}' value='{v}' {c}>";
const char HTTP_FORM_START[] PROGMEM = "<form method='POST' action='wifisave'><label for='s'>SSID</label><input id='s' name='s' maxlength=32 placeholder='{v}'><br/><label for='p'>Password</label><input id='p' name='p' length=64 type='password' placeholder=''><br/>";
const char HTTP_FORM_END[] PROGMEM = "<br/><button type='submit'>Save</button></form>";
const char HTTP_FORM_LABEL[] PROGMEM = "<label for='{i}'>{p}</label>";
const char HTTP_FORM_PARAM_START[] PROGMEM = "<hr>";
const char HTTP_FORM_PARAM[] PROGMEM = "<br/><input id='{i}' name='{n}' maxlength={l} placeholder='' value='{v}' {c}>";
const char HTTP_FORM_PARAM_END[] PROGMEM = "<br/>";
const char HTTP_SCAN_LINK[] PROGMEM = "<br/><form action='/wifi' method='get'><button>Refresh</button></form>";
const char HTTP_SAVED[] PROGMEM = "<div class='msg'>Saving Credentials<br/>Trying to connect ESP to network.<br />If it fails reconnect to AP to try again</div>";
const char HTTP_END[] PROGMEM = "</div></body></html>";