Search in sources :

Example 1 with ElementContainer

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

the class DisplayConfigAction method addSiteNode.

private void addSiteNode(final ElementContainer view, final SiteNode siteNode) {
    if (siteNode != null) {
        final ElementContainer nodeView = new ElementContainer();
        view.add(nodeView);
        final String path = siteNode.getPath();
        if (path == null) {
            nodeView.add(new XmlTagElement(HtmlElem.H4, "/"));
        } else {
            nodeView.add(new XmlTagElement(HtmlElem.H4, path));
        }
        final SiteNodeController controller = siteNode.getController();
        if (controller instanceof PageController) {
            final PageController pageController = (PageController) controller;
            final ElementContainer pageView = new ElementContainer(new DefinitionListLayout());
            nodeView.add(pageView);
            pageView.add("Actions");
            final ElementContainer actionsView = new ElementContainer(new UnorderedListLayout());
            pageView.add(actionsView);
            for (final Iterator actions = pageController.getActions().iterator(); actions.hasNext(); ) {
                final Action action = (Action) actions.next();
                actionsView.add(action.getClass().getName());
            }
            pageView.add("Menus");
            final ElementContainer menusView = new ElementContainer(new UnorderedListLayout());
            pageView.add(menusView);
            for (final Iterator menus = pageController.getMenus().entrySet().iterator(); menus.hasNext(); ) {
                final Map.Entry entry = (Entry) menus.next();
                final String name = (String) entry.getKey();
                final Menu menu = (Menu) entry.getValue();
                addMenu(menusView, name, menu);
            }
        }
        final Collection nodes = siteNode.getNodes();
        if (!nodes.isEmpty()) {
            final ElementContainer childNodesView = new ElementContainer(new UnorderedListLayout());
            nodeView.add(childNodesView);
            for (final Iterator nodeIter = nodes.iterator(); nodeIter.hasNext(); ) {
                final SiteNode childNode = (SiteNode) nodeIter.next();
                addSiteNode(childNodesView, childNode);
            }
        }
    }
}
Also used : Entry(java.util.Map.Entry) Action(com.revolsys.ui.web.config.Action) ElementContainer(com.revolsys.ui.html.view.ElementContainer) DivElementContainer(com.revolsys.ui.html.view.DivElementContainer) UnorderedListLayout(com.revolsys.ui.html.layout.UnorderedListLayout) SiteNodeController(com.revolsys.ui.web.config.SiteNodeController) Entry(java.util.Map.Entry) PageController(com.revolsys.ui.web.config.PageController) DefinitionListLayout(com.revolsys.ui.html.layout.DefinitionListLayout) Iterator(java.util.Iterator) Collection(java.util.Collection) Menu(com.revolsys.ui.model.Menu) XmlTagElement(com.revolsys.ui.html.view.XmlTagElement) Map(java.util.Map) SiteNode(com.revolsys.ui.web.config.SiteNode)

Example 2 with ElementContainer

use of com.revolsys.ui.html.view.ElementContainer 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 3 with ElementContainer

use of com.revolsys.ui.html.view.ElementContainer 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);
        }
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) PageNotFoundException(com.revolsys.ui.web.exception.PageNotFoundException) ElementContainer(com.revolsys.ui.html.view.ElementContainer) TabElementContainer(com.revolsys.ui.html.view.TabElementContainer) ButtonsToolbarElement(com.revolsys.ui.html.view.ButtonsToolbarElement) Element(com.revolsys.ui.html.view.Element) Page(com.revolsys.ui.web.config.Page) Menu(com.revolsys.ui.model.Menu) KeySerializer(com.revolsys.ui.html.serializer.key.KeySerializer)

Example 4 with ElementContainer

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

the class HtmlUiBuilder method newDataTable.

public ElementContainer newDataTable(final HttpServletRequest request, final String pageName, Map<String, ? extends Object> parameters, final Collection<? extends Object> rows) {
    parameters = new HashMap<>(parameters);
    final List<KeySerializer> serializers = getSerializers(pageName, "list");
    final RowsTableSerializer model = new KeySerializerTableSerializer(serializers, rows);
    final String typeName = getTypeName();
    final TableView tableView = new TableView(model, typeName + " dataTable no-footer");
    tableView.setWidth("100%");
    final String tableId = typeName + "_" + pageName + "_table";
    tableView.setId(tableId);
    tableView.setNoRecordsMessgae(null);
    final Map<String, Object> tableParams = new LinkedHashMap<>();
    tableParams.put("stateSave", true);
    tableParams.put("autoWidth", true);
    tableParams.put("dom", Maps.getString(parameters, "dom", "frtiS"));
    final Boolean ordering = Maps.getBoolean(parameters, "ordering");
    if (ordering != null) {
        tableParams.put("ordering", ordering);
    }
    final String scrollY = (String) parameters.get("scrollY");
    if (scrollY == null) {
        tableParams.put("scrollY", "300px");
    } else {
        tableParams.put("scrollY", scrollY);
    }
    final String scrollX = (String) parameters.get("scrollX");
    if (scrollX == null) {
        tableParams.put("scrollX", "true");
    } else {
        tableParams.put("scrollX", scrollX);
    }
    tableParams.put("order", getListSortOrder(pageName));
    Boolean serverSide = (Boolean) parameters.get("serverSide");
    final String ajaxSource = (String) parameters.get("ajaxSource");
    if (Property.hasValue(ajaxSource)) {
        if (serverSide == null) {
            serverSide = true;
        }
        tableParams.put("serverSide", serverSide);
        tableParams.put("ajax", ajaxSource);
    } else if (serverSide == null) {
        serverSide = false;
    }
    tableParams.put("scroller", Collections.singletonMap("loadingIndicator", true));
    final List<Map<String, Object>> columnDefs = new ArrayList<>();
    int i = 0;
    for (final KeySerializer serializer : serializers) {
        final Map<String, Object> columnDef = new LinkedHashMap<>();
        columnDef.put("targets", Arrays.asList(i));
        columnDef.put("name", serializer.getKey());
        columnDef.put("className", serializer.getKey().replaceAll("[^A-Za-z0-9]", "_"));
        columnDef.put("title", serializer.getLabel());
        final Boolean sortable = serializer.getProperty("sortable");
        if (sortable != null) {
            columnDef.put("orderable", sortable);
        }
        final Boolean searchable = serializer.getProperty("searchable");
        if (searchable != null) {
            columnDef.put("searchable", searchable);
        }
        final Boolean visible = serializer.getProperty("visible");
        if (visible != null) {
            columnDef.put("visible", visible);
        }
        final String width = serializer.getWidth();
        if (width != null) {
            columnDef.put("width", width);
        }
        columnDefs.add(columnDef);
        i++;
    }
    if (!columnDefs.isEmpty()) {
        tableParams.put("columnDefs", columnDefs);
    }
    Number scrollYPercent = (Number) parameters.get("scrollYPercent");
    if (scrollYPercent == null) {
        if (scrollY == null) {
            scrollYPercent = 0;
        } else {
            scrollYPercent = 0.98;
        }
    }
    final Script script = new Script();
    String jsonMap = Json.toString(tableParams);
    jsonMap = jsonMap.substring(0, jsonMap.length() - 1) + ",\"createdRow\": function( row, data, dataIndex ) {refreshButtons(row);}" + ",\"initComplete\": function() {$(this).DataTable().columns.adjust();}";
    jsonMap += "}";
    final StringBuffer scriptBody = new StringBuffer();
    scriptBody.append("$(document).ready(function() {\n");
    scriptBody.append("  var tableDiv = $('#");
    scriptBody.append(tableId);
    scriptBody.append(" table');\n");
    scriptBody.append("  var table = tableDiv.dataTable(");
    scriptBody.append(jsonMap);
    scriptBody.append("\n );\n");
    scriptBody.append("  tableShowEvents(table,");
    scriptBody.append(scrollYPercent);
    scriptBody.append(");\n");
    scriptBody.append("$(window).bind('resize', function () {$(table).DataTable().columns.adjust();} );");
    scriptBody.append("});");
    script.setContent(scriptBody.toString());
    final ElementContainer container = new ElementContainer(tableView, script);
    final String prefix = pageName.replaceAll("[lL]ist$", "");
    final Menu actionMenu = new Menu();
    final Menu addMenuItem = addMenuItem(actionMenu, prefix, "add", "Add", "_top");
    if (addMenuItem != null) {
        addMenuItem.addProperty("buttonClass", "btn-primary");
    }
    addListMenuItems(actionMenu, prefix);
    addMenuElement(container, actionMenu);
    return container;
}
Also used : KeySerializerTableSerializer(com.revolsys.ui.html.serializer.KeySerializerTableSerializer) Script(com.revolsys.ui.html.view.Script) ElementContainer(com.revolsys.ui.html.view.ElementContainer) TabElementContainer(com.revolsys.ui.html.view.TabElementContainer) ArrayList(java.util.ArrayList) KeySerializer(com.revolsys.ui.html.serializer.key.KeySerializer) LinkedHashMap(java.util.LinkedHashMap) Menu(com.revolsys.ui.model.Menu) RowsTableSerializer(com.revolsys.ui.html.serializer.RowsTableSerializer) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) TableView(com.revolsys.ui.html.view.TableView)

Example 5 with ElementContainer

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

the class HtmlUiBuilder method newDataTable.

public ElementContainer newDataTable(final HttpServletRequest request, final String pageName, final Map<String, ? extends Object> parameters) {
    final String pageUrl = getPageUrl(pageName);
    if (Property.hasValue(pageUrl)) {
        final Map<String, Object> params = new HashMap<>();
        params.putAll(parameters);
        params.put("ajaxSource", pageUrl.replaceAll("/+$", ".json"));
        final List<T> rows = Collections.emptyList();
        final ElementContainer table = newDataTable(request, pageName, params, rows);
        return table;
    } else {
        return null;
    }
}
Also used : ElementContainer(com.revolsys.ui.html.view.ElementContainer) TabElementContainer(com.revolsys.ui.html.view.TabElementContainer) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

ElementContainer (com.revolsys.ui.html.view.ElementContainer)8 TabElementContainer (com.revolsys.ui.html.view.TabElementContainer)7 Menu (com.revolsys.ui.model.Menu)5 HashMap (java.util.HashMap)4 LinkedHashMap (java.util.LinkedHashMap)4 HttpServletRequest (javax.servlet.http.HttpServletRequest)4 ButtonsToolbarElement (com.revolsys.ui.html.view.ButtonsToolbarElement)3 Page (com.revolsys.ui.web.config.Page)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 KeySerializer (com.revolsys.ui.html.serializer.key.KeySerializer)2 PageNotFoundException (com.revolsys.ui.web.exception.PageNotFoundException)2 HashSet (java.util.HashSet)2 Map (java.util.Map)2 DefinitionListLayout (com.revolsys.ui.html.layout.DefinitionListLayout)1 UnorderedListLayout (com.revolsys.ui.html.layout.UnorderedListLayout)1 KeySerializerDetailSerializer (com.revolsys.ui.html.serializer.KeySerializerDetailSerializer)1 KeySerializerTableSerializer (com.revolsys.ui.html.serializer.KeySerializerTableSerializer)1 RowsTableSerializer (com.revolsys.ui.html.serializer.RowsTableSerializer)1