use of org.structr.api.config.SettingsGroup in project structr by structr.
the class ConfigServlet method createConfigDocument.
// ----- private methods -----
private Document createConfigDocument(final HttpServletRequest request, final PrintWriter writer) {
final Document doc = new Document(writer);
final Tag body = setupDocument(request, doc);
final Tag form = body.block("form").css("config-form");
final Tag main = form.block("div").id("main");
final Tag tabs = main.block("div").id("configTabs");
final Tag menu = tabs.block("ul").id("configTabsMenu");
// configure form
form.attr(new Attr("action", ConfigUrl), new Attr("method", "post"));
for (final SettingsGroup group : Settings.getGroups()) {
final String key = group.getKey();
final String name = group.getName();
menu.block("li").block("a").id(key + "Menu").attr(new Attr("href", "#" + key)).block("span").text(name);
final Tag container = tabs.block("div").css("tab-content").id(key);
// let settings group render itself
group.render(container);
// stop floating
container.block("div").attr(new Style("clear: both;"));
}
// add services tab
menu.block("li").block("a").id("servicesMenu").attr(new Attr("href", "#services")).block("span").text("Services");
final Services services = Services.getInstance();
final Tag container = tabs.block("div").css("tab-content").id("services");
final Tag table = container.block("table").id("services-table");
final Tag header = table.block("tr");
header.block("th").text("Service Name");
header.block("th").attr(new Attr("colspan", "2"));
for (final String serviceClassName : services.getServices()) {
final Class<Service> serviceClass = services.getServiceClassForName(serviceClassName);
final boolean running = serviceClass != null ? services.isReady(serviceClass) : false;
final Tag row = table.block("tr");
row.block("td").text(serviceClassName);
if (running) {
row.block("td").block("button").attr(new Type("button"), new OnClick("window.location.href='" + ConfigUrl + "?restart=" + serviceClassName + "';")).text("Restart");
if ("HttpService".equals(serviceClassName)) {
row.block("td");
} else {
row.block("td").block("button").attr(new Type("button"), new OnClick("window.location.href='" + ConfigUrl + "?stop=" + serviceClassName + "';")).text("Stop");
}
row.block("td");
} else {
row.block("td");
row.block("td");
row.block("td").block("button").attr(new Type("button"), new OnClick("window.location.href='" + ConfigUrl + "?start=" + serviceClassName + "';")).text("Start");
}
}
// update active section so we can restore it when redirecting
container.empty("input").attr(new Type("hidden"), new Name("active_section")).id("active_section");
// stop floating
container.block("div").attr(new Style("clear: both;"));
// buttons
final Tag buttons = form.block("div").css("buttons");
buttons.block("button").attr(new Type("button")).id("new-entry-button").text("Add entry");
buttons.block("button").attr(new Type("button"), new OnClick("window.location.href='" + ConfigUrl + "?reload';")).text("Reload configuration file");
buttons.empty("input").attr(new Type("submit"), new Value("Save to structr.conf"));
body.block("script").text("$('#new-entry-button').on('click', createNewEntry);");
return doc;
}