Search in sources :

Example 1 with ButtonsToolbarElement

use of com.revolsys.ui.html.view.ButtonsToolbarElement 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;
}
Also used : ElementContainer(com.revolsys.ui.html.view.ElementContainer) TabElementContainer(com.revolsys.ui.html.view.TabElementContainer) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) UiBuilderObjectForm(com.revolsys.ui.html.form.UiBuilderObjectForm) HtmlUiBuilderObjectForm(com.revolsys.ui.html.form.HtmlUiBuilderObjectForm) Form(com.revolsys.ui.html.form.Form) Page(com.revolsys.ui.web.config.Page) TabElementContainer(com.revolsys.ui.html.view.TabElementContainer) HttpServletRequest(javax.servlet.http.HttpServletRequest) Menu(com.revolsys.ui.model.Menu) ButtonsToolbarElement(com.revolsys.ui.html.view.ButtonsToolbarElement) HashSet(java.util.HashSet)

Example 2 with ButtonsToolbarElement

use of com.revolsys.ui.html.view.ButtonsToolbarElement in project com.revolsys.open by revolsys.

the class HtmlUiBuilder method addMenuElement.

public void addMenuElement(final ElementContainer container, final Menu menu) {
    if (menu.getMenus().size() > 0) {
        final ButtonsToolbarElement buttonsToolbar = new ButtonsToolbarElement(menu);
        container.add(buttonsToolbar);
    }
}
Also used : ButtonsToolbarElement(com.revolsys.ui.html.view.ButtonsToolbarElement)

Example 3 with ButtonsToolbarElement

use of com.revolsys.ui.html.view.ButtonsToolbarElement in project com.revolsys.open by revolsys.

the class BaseController method getbuttonsToolbar.

public ButtonsToolbarElement getbuttonsToolbar(final HttpServletRequest request) {
    final Menu menu = getActionMenu(request);
    final ButtonsToolbarElement menuElement = new ButtonsToolbarElement(menu);
    menuElement.initialize(request);
    return menuElement;
}
Also used : Menu(com.revolsys.ui.model.Menu) ButtonsToolbarElement(com.revolsys.ui.html.view.ButtonsToolbarElement)

Example 4 with ButtonsToolbarElement

use of com.revolsys.ui.html.view.ButtonsToolbarElement 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;
    }
}
Also used : ElementContainer(com.revolsys.ui.html.view.ElementContainer) TabElementContainer(com.revolsys.ui.html.view.TabElementContainer) UiBuilderObjectForm(com.revolsys.ui.html.form.UiBuilderObjectForm) HtmlUiBuilderObjectForm(com.revolsys.ui.html.form.HtmlUiBuilderObjectForm) Form(com.revolsys.ui.html.form.Form) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Page(com.revolsys.ui.web.config.Page) TabElementContainer(com.revolsys.ui.html.view.TabElementContainer) HttpServletRequest(javax.servlet.http.HttpServletRequest) PageNotFoundException(com.revolsys.ui.web.exception.PageNotFoundException) Menu(com.revolsys.ui.model.Menu) ButtonsToolbarElement(com.revolsys.ui.html.view.ButtonsToolbarElement) HashSet(java.util.HashSet)

Aggregations

ButtonsToolbarElement (com.revolsys.ui.html.view.ButtonsToolbarElement)4 Menu (com.revolsys.ui.model.Menu)3 Form (com.revolsys.ui.html.form.Form)2 HtmlUiBuilderObjectForm (com.revolsys.ui.html.form.HtmlUiBuilderObjectForm)2 UiBuilderObjectForm (com.revolsys.ui.html.form.UiBuilderObjectForm)2 ElementContainer (com.revolsys.ui.html.view.ElementContainer)2 TabElementContainer (com.revolsys.ui.html.view.TabElementContainer)2 Page (com.revolsys.ui.web.config.Page)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 LinkedHashMap (java.util.LinkedHashMap)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 PageNotFoundException (com.revolsys.ui.web.exception.PageNotFoundException)1