Console: Add js to /configui to preview themes

Save theme change before form processing so no refresh required
Enable/disable reset and apply buttons on config clicks
Prep for theme picker in wizard
This commit is contained in:
zzz
2021-09-30 09:55:35 -04:00
parent f015d1f490
commit 282460cb3f
7 changed files with 110 additions and 31 deletions

View File

@@ -69,6 +69,16 @@ public class CSSHelper extends HelperBase {
return url;
}
/**
* So we don't have to refresh after saving. Called from css.jsi.
* @since 0.9.52
*/
public void setTheme(String theme) {
if (theme != null && theme.length() > 0 &&
theme.replaceAll("[a-zA-Z0-9_-]", "").length() == 0)
_context.router().saveConfig(PROP_THEME_NAME, theme);
}
/**
* Returns whether app embedding is enabled or disabled
* @since 0.9.32

View File

@@ -28,7 +28,7 @@ public class ConfigUIHandler extends FormHandler {
delUser();
} else if (_action.equals(_t("Add user"))) {
addUser();
}
} // else lang change, handled in CSSHelper
}
public void setShouldsave(String moo) { _shouldSave = true; }
@@ -43,22 +43,23 @@ public class ConfigUIHandler extends FormHandler {
_config = val;
}
/** note - lang change is handled in CSSHelper but we still need to save it here */
/**
* This is for the theme options only.
* Lang change is handled in CSSHelper.
*/
private void saveChanges() {
if (_config == null || _config.length() <= 0)
return;
if (_config.replaceAll("[a-zA-Z0-9_-]", "").length() != 0) {
addFormError("Bad theme name");
return;
}
Map<String, String> changes = new HashMap<String, String>();
List<String> removes = new ArrayList<String>();
String oldTheme = _context.getProperty(CSSHelper.PROP_THEME_NAME, CSSHelper.DEFAULT_THEME);
boolean oldForceMobileConsole = _context.getBooleanProperty(CSSHelper.PROP_FORCE_MOBILE_CONSOLE);
if (_config.equals("default")) // obsolete
removes.add(CSSHelper.PROP_THEME_NAME);
else
changes.put(CSSHelper.PROP_THEME_NAME, _config);
boolean validTheme = _config != null && _config.length() > 0 &&
_config.replaceAll("[a-zA-Z0-9_-]", "").length() == 0;
if (validTheme) {
if (_config.equals("default")) // obsolete
removes.add(CSSHelper.PROP_THEME_NAME);
else
changes.put(CSSHelper.PROP_THEME_NAME, _config);
}
if (_universalTheming)
changes.put(CSSHelper.PROP_UNIVERSAL_THEMING, "true");
else
@@ -73,11 +74,11 @@ public class ConfigUIHandler extends FormHandler {
removes.add(CSSHelper.PROP_EMBED_APPS);
boolean ok = _context.router().saveConfig(changes, removes);
if (ok) {
if (!oldTheme.equals(_config))
addFormNoticeNoEscape(_t("Theme change saved.") +
" <a href=\"configui\">" +
_t("Refresh the page to view.") +
"</a>");
// Theme saving happens in CSSHelper
// so output this even if it didn't change
//if (!oldTheme.equals(_config))
if (validTheme)
addFormNotice(_t("Theme change saved."));
if (oldForceMobileConsole != _forceMobileConsole)
addFormNoticeNoEscape(_t("Mobile console option saved.") +
" <a href=\"configui\">" +

View File

@@ -41,7 +41,7 @@ public class ConfigUIHelper extends HelperBase {
}
boolean universalTheming = _context.getBooleanProperty(CSSHelper.PROP_UNIVERSAL_THEMING);
buf.append("</div><div id=\"themeoptions\">" +
"<label><input type=\"checkbox\" name=\"universalTheming\" ");
"<label><input id=\"themebox1\" type=\"checkbox\" name=\"universalTheming\" ");
if (universalTheming)
buf.append(CHECKED);
buf.append("value=\"1\">")
@@ -53,7 +53,7 @@ public class ConfigUIHelper extends HelperBase {
public String getForceMobileConsole() {
StringBuilder buf = new StringBuilder(256);
boolean forceMobileConsole = _context.getBooleanProperty(CSSHelper.PROP_FORCE_MOBILE_CONSOLE);
buf.append("<label><input type=\"checkbox\" name=\"forceMobileConsole\" ");
buf.append("<label><input id=\"themebox2\" type=\"checkbox\" name=\"forceMobileConsole\" ");
if (forceMobileConsole)
buf.append(CHECKED);
buf.append("value=\"1\">")
@@ -62,7 +62,7 @@ public class ConfigUIHelper extends HelperBase {
boolean embedApps = _context.getBooleanProperty(CSSHelper.PROP_EMBED_APPS);
buf.append("<label title=\"")
.append(_t("Enabling the Universal Theming option is recommended when embedding these applications"))
.append("\"><input type=\"checkbox\" name=\"embedApps\" ");
.append("\"><input id=\"themebox3\" type=\"checkbox\" name=\"embedApps\" ");
if (embedApps)
buf.append(CHECKED);
buf.append("value=\"1\">")