Search in sources :

Example 6 with WebLayoutSpecification

use of org.sablo.specification.WebLayoutSpecification in project servoy-client by Servoy.

the class FormLayoutGenerator method generateFormStartTag.

public static void generateFormStartTag(PrintWriter writer, Form form, String realFormName, boolean responsiveMode, boolean design) {
    if (design) {
        writer.print("<div ng-controller='DesignFormController' id='svyDesignForm' ");
        if (form.isResponsiveLayout()) {
            List<String> allowedChildren = new ArrayList<String>();
            Collection<PackageSpecification<WebLayoutSpecification>> values = WebComponentSpecProvider.getSpecProviderState().getLayoutSpecifications().values();
            for (PackageSpecification<WebLayoutSpecification> specifications : values) {
                for (WebLayoutSpecification specification : specifications.getSpecifications().values()) {
                    if (specification.isTopContainer()) {
                        allowedChildren.add(specification.getPackageName() + "." + specification.getName());
                    }
                }
            }
            if (allowedChildren.size() > 0) {
                String allowedChildrenJoin = String.join(",", allowedChildren);
                writer.print(" svy-allowed-children=\"");
                writer.print(allowedChildrenJoin);
                writer.print("\"");
                JSONObject ngClass = new JSONObject();
                String dropHighlightCondition = "<canContainDraggedElement(";
                if (allowedChildren.size() > 1) {
                    for (int i = 0; i < allowedChildren.size() - 1; i++) {
                        dropHighlightCondition += "'" + allowedChildren.get(i) + "', ";
                    }
                }
                dropHighlightCondition += "'" + allowedChildren.get(allowedChildren.size() - 1) + "'";
                dropHighlightCondition += ")<";
                // added <> tokens so that we can remove quotes around the values so that angular will evaluate at runtime
                ngClass.put("drop_highlight", dropHighlightCondition);
                writer.print(" ng-class='" + ngClass.toString().replaceAll("\"<", "").replaceAll("<\"", "").replaceAll("'", "\"") + "'");
            }
        }
    } else
        writer.print(String.format("<svy-formload formname=\"%1$s\"><div ng-controller=\"%1$s\" ", realFormName));
    if (Utils.getAsBoolean(Settings.getInstance().getProperty("servoy.ngclient.testingMode", "false"))) {
        writer.print(String.format("data-svy-name=\"%1$s\" ", realFormName));
    }
    if (!form.isResponsiveLayout() && !responsiveMode) {
        writer.print("svy-formstyle=\"formStyle\" ");
    } else if (design) {
        // design form should grow with content and dictate the height to parent
        writer.print(" style=\"min-height:100%\"");
    }
    writer.print("svy-layout-update svy-form-class-update svy-autosave ");
    // skip the scrollbars for forms in tableview then the portal component does this
    if (design || (form.getView() != IFormConstants.VIEW_TYPE_TABLE && form.getView() != IFormConstants.VIEW_TYPE_TABLE_LOCKED)) {
        writer.print(" svy-scrollbars='formProperties.scrollbars'");
    }
    String formClass = "svy-form";
    if (form.isResponsiveLayout()) {
        formClass += " svy-respform";
    }
    if (form.getStyleClass() != null) {
        formClass += " " + form.getStyleClass();
    }
    writer.print(" class=\"");
    writer.print(formClass);
    writer.print("\"");
    writer.print(">");
}
Also used : WebLayoutSpecification(org.sablo.specification.WebLayoutSpecification) JSONObject(org.json.JSONObject) ArrayList(java.util.ArrayList) PackageSpecification(org.sablo.specification.PackageSpecification)

Aggregations

WebLayoutSpecification (org.sablo.specification.WebLayoutSpecification)6 LayoutContainer (com.servoy.j2db.persistence.LayoutContainer)4 HashMap (java.util.HashMap)3 JSONObject (org.json.JSONObject)3 PropertyDescription (org.sablo.specification.PropertyDescription)3 IFormElement (com.servoy.j2db.persistence.IFormElement)2 IPersist (com.servoy.j2db.persistence.IPersist)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 PackageSpecification (org.sablo.specification.PackageSpecification)2 AbstractContainer (com.servoy.j2db.persistence.AbstractContainer)1 Form (com.servoy.j2db.persistence.Form)1 RepositoryException (com.servoy.j2db.persistence.RepositoryException)1 FormElement (com.servoy.j2db.server.ngclient.FormElement)1 Point (java.awt.Point)1 HashSet (java.util.HashSet)1