use of com.revolsys.ui.html.view.TabElementContainer in project com.revolsys.open by revolsys.
the class HtmlUiBuilder method newObjectAddPage.
public Element newObjectAddPage(final Map<String, Object> defaultValues, final String prefix, final String preInsertMethod) throws IOException, ServletException {
final T object = newObject();
final HttpServletRequest request = HttpServletUtils.getRequest();
Property.set(object, defaultValues);
// if (!canAddObject(request)) {
// response.sendError(HttpServletResponse.SC_FORBIDDEN,
// "No permission to edit " + getTypeName() + " #" + getId());
// return null;
// }
final Map<String, Object> parameters = new HashMap<>();
final String pageName = getName(prefix, "add");
final Set<String> parameterNamesToSave = new HashSet<>();
final Form form = newTableForm(object, pageName);
for (final String param : parameterNamesToSave) {
form.addSavedParameter(param, request.getParameter(param));
}
form.initialize(request);
if (form.isPosted() && form.isMainFormTask()) {
if (form.isValid()) {
if ((Boolean) JavaBeanUtil.method(this, preInsertMethod, form, object)) {
insertObject(object);
parameters.put("message", "Saved");
final Object id = Property.get(object, getIdPropertyName());
parameters.put(getIdParameterName(), id);
postInsert(object);
final String viewName = getName(prefix, "view");
final String url = getPageUrl(viewName, parameters);
redirectAfterCommit(url);
return new TabElementContainer();
}
}
}
final Page page = getPage(pageName);
final String title = page.getExpandedTitle();
request.setAttribute("title", title);
final Menu actionMenu = new Menu();
addMenuItem(actionMenu, prefix, "list", "Cancel", "_top").addProperty("buttonClass", "btn-danger");
addMenuItem(actionMenu, prefix, "add", "Clear Fields").addProperty("buttonClass", "btn-warning");
final String name = form.getName();
final Menu saveMenu = new Menu("Save", "javascript:$('#" + name + "').submit()");
saveMenu.addProperty("buttonClass", "btn-primary");
actionMenu.addMenuItem(saveMenu);
final ButtonsToolbarElement buttonsToolbar = new ButtonsToolbarElement(actionMenu);
final ElementContainer view = new ElementContainer(form, buttonsToolbar);
final TabElementContainer tabs = new TabElementContainer();
tabs.add(title, view);
return tabs;
}
use of com.revolsys.ui.html.view.TabElementContainer in project com.revolsys.open by revolsys.
the class HtmlUiBuilder method newDataTableHandler.
public Object newDataTableHandler(final HttpServletRequest request, final String pageName, final Map<String, Object> parameters, final Collection<? extends Object> rows) {
if (isDataTableCallback(request)) {
return newDataTableMap(request, rows, pageName);
} else {
parameters.put("serverSide", false);
final TabElementContainer tabs = new TabElementContainer();
addTabDataTable(tabs, this, pageName, parameters);
return tabs;
}
}
use of com.revolsys.ui.html.view.TabElementContainer in project com.revolsys.open by revolsys.
the class HtmlUiBuilder method addObjectViewPage.
public void addObjectViewPage(final TabElementContainer tabs, final Object object, final String prefix) {
final HttpServletRequest request = getRequest();
if (object == null) {
throw new PageNotFoundException();
} else {
final String pageName = getName(prefix, "view");
final Page page = getPage(pageName);
if (page == null) {
throw new PageNotFoundException("Page not found " + pageName);
} else {
final List<KeySerializer> serializers = getSerializers(pageName, "view");
final Element detailView = newDetailView(object, serializers);
setPageTitle(request, pageName);
final Menu actionMenu = new Menu();
final Menu editMenu = addMenuItem(actionMenu, prefix, "edit", "Edit", "_top");
if (editMenu != null) {
editMenu.addProperty("buttonClass", "btn-primary");
}
final ElementContainer view = new ElementContainer(detailView);
addMenuElement(view, actionMenu);
final String tabId = getTypeName() + "_" + pageName;
final String title = getPageTitle(pageName);
tabs.add(tabId, title, view);
}
}
}
use of com.revolsys.ui.html.view.TabElementContainer in project com.revolsys.open by revolsys.
the class HtmlUiBuilder method addTabDataTable.
public void addTabDataTable(final TabElementContainer container, final Object builderName, final String pageName, Map<String, Object> parameters) {
final HtmlUiBuilder<?> builder = getBuilder(builderName);
if (builder != null) {
parameters = new HashMap<>(parameters);
parameters.put("deferLoading", 0);
parameters.put("tabbed", true);
parameters.put("scrollYPercent", 1);
final HttpServletRequest request = getRequest();
final ElementContainer element = builder.newDataTable(request, pageName, parameters);
if (element != null) {
final String tabId = builder.getTypeName() + "_" + pageName;
final String title = builder.getPageTitle(pageName);
container.add(tabId, title, element);
}
}
}
use of com.revolsys.ui.html.view.TabElementContainer in project com.revolsys.open by revolsys.
the class HtmlUiBuilder method newObjectEditPage.
public Element newObjectEditPage(final T object, final String prefix) throws IOException, ServletException {
if (object == null) {
throw new PageNotFoundException();
} else {
final HttpServletRequest request = HttpServletUtils.getRequest();
final Set<String> parameterNamesToSave = new HashSet<>();
parameterNamesToSave.add(getIdParameterName());
final String pageName = getName(prefix, "edit");
final Form form = newTableForm(object, pageName);
for (final String param : parameterNamesToSave) {
form.addSavedParameter(param, request.getParameter(param));
}
form.initialize(request);
if (form.isPosted() && form.isMainFormTask()) {
if (form.isValid() && preUpdate(form, object)) {
updateObject(object);
postUpdate(object);
final Map<String, Object> parameters = new HashMap<>();
// Get after object has changed
final Object id = Property.get(object, getIdPropertyName());
parameters.put(getIdParameterName(), id);
final Page viewPage = getPage(prefix, "view");
final String url = viewPage.getFullUrl(parameters);
redirectAfterCommit(url);
return new TabElementContainer();
} else {
setRollbackOnly(object);
}
} else {
setRollbackOnly(object);
}
final Page page = getPage(prefix, "edit");
final String title = page.getExpandedTitle();
request.setAttribute("title", title);
final Menu actionMenu = new Menu();
addMenuItem(actionMenu, prefix, "view", "Cancel", "_top").addProperty("buttonClass", "btn-danger");
addMenuItem(actionMenu, prefix, "edit", "Revert to Saved", "_top").addProperty("buttonClass", "btn-warning");
final String name = form.getName();
final Menu saveItem = new Menu("Save", "javascript:$('#" + name + "').submit()");
saveItem.addProperty("buttonClass", "btn-primary");
actionMenu.addMenuItem(saveItem);
final ButtonsToolbarElement buttonsToolbar = new ButtonsToolbarElement(actionMenu);
final ElementContainer view = new ElementContainer(form, buttonsToolbar);
final TabElementContainer tabs = new TabElementContainer();
tabs.add(title, view);
return tabs;
}
}
Aggregations