Search in sources :

Example 1 with EditMode

use of org.structr.web.common.RenderContext.EditMode in project structr by structr.

the class DOMElement method renderStructrAppLib.

static void renderStructrAppLib(final DOMElement thisElement, final AsyncBuffer out, final SecurityContext securityContext, final RenderContext renderContext, final int depth) throws FrameworkException {
    EditMode editMode = renderContext.getEditMode(securityContext.getUser(false));
    if (!(EditMode.DEPLOYMENT.equals(editMode) || EditMode.RAW.equals(editMode) || EditMode.WIDGET.equals(editMode)) && !renderContext.appLibRendered() && thisElement.getProperty(new StringProperty(STRUCTR_ACTION_PROPERTY)) != null) {
        out.append("<!--").append(DOMNode.indent(depth, renderContext)).append("--><script>if (!window.jQuery) { document.write('<script src=\"/structr/js/lib/jquery-1.11.1.min.js\"><\\/script>'); }</script><!--").append(DOMNode.indent(depth, renderContext)).append("--><script>if (!window.jQuery.ui) { document.write('<script src=\"/structr/js/lib/jquery-ui-1.11.0.custom.min.js\"><\\/script>'); }</script><!--").append(DOMNode.indent(depth, renderContext)).append("--><script>if (!window.jQuery.ui.timepicker) { document.write('<script src=\"/structr/js/lib/jquery-ui-timepicker-addon.min.js\"><\\/script>'); }</script><!--").append(DOMNode.indent(depth, renderContext)).append("--><script>if (!window.StructrApp) { document.write('<script src=\"/structr/js/structr-app.js\"><\\/script>'); }</script><!--").append(DOMNode.indent(depth, renderContext)).append("--><script>if (!window.moment) { document.write('<script src=\"/structr/js/lib/moment.min.js\"><\\/script>'); }</script><!--").append(DOMNode.indent(depth, renderContext)).append("--><link rel=\"stylesheet\" type=\"text/css\" href=\"/structr/css/lib/jquery-ui-1.10.3.custom.min.css\">");
        renderContext.setAppLibRendered(true);
    }
}
Also used : EditMode(org.structr.web.common.RenderContext.EditMode) StringProperty(org.structr.core.property.StringProperty)

Example 2 with EditMode

use of org.structr.web.common.RenderContext.EditMode in project structr by structr.

the class DOMNode method renderCustomAttributes.

static void renderCustomAttributes(final DOMNode thisNode, final AsyncBuffer out, final SecurityContext securityContext, final RenderContext renderContext) throws FrameworkException {
    final EditMode editMode = renderContext.getEditMode(securityContext.getUser(false));
    for (PropertyKey key : thisNode.getDataPropertyKeys()) {
        String value = "";
        if (EditMode.DEPLOYMENT.equals(editMode)) {
            final Object obj = thisNode.getProperty(key);
            if (obj != null) {
                value = obj.toString();
            }
        } else {
            value = thisNode.getPropertyWithVariableReplacement(renderContext, key);
            if (value != null) {
                value = value.trim();
            }
        }
        if (!(EditMode.RAW.equals(editMode) || EditMode.WIDGET.equals(editMode))) {
            value = escapeForHtmlAttributes(value);
        }
        if (StringUtils.isNotBlank(value)) {
            if (key instanceof CustomHtmlAttributeProperty) {
                out.append(" ").append(((CustomHtmlAttributeProperty) key).cleanName()).append("=\"").append(value).append("\"");
            } else {
                out.append(" ").append(key.dbName()).append("=\"").append(value).append("\"");
            }
        }
    }
    if (EditMode.DEPLOYMENT.equals(editMode) || EditMode.RAW.equals(editMode) || EditMode.WIDGET.equals(editMode)) {
        if (EditMode.DEPLOYMENT.equals(editMode)) {
            // export name property if set
            final String name = thisNode.getProperty(AbstractNode.name);
            if (name != null) {
                out.append(" data-structr-meta-name=\"").append(escapeForHtmlAttributes(name)).append("\"");
            }
        }
        for (final String p : rawProps) {
            String htmlName = "data-structr-meta-" + CaseHelper.toUnderscore(p, false).replaceAll("_", "-");
            Object value = thisNode.getProperty(p);
            if (value != null) {
                final PropertyKey key = StructrApp.key(DOMNode.class, p);
                final boolean isBoolean = key instanceof BooleanProperty;
                final String stringValue = value.toString();
                if ((isBoolean && "true".equals(stringValue)) || (!isBoolean && StringUtils.isNotBlank(stringValue))) {
                    out.append(" ").append(htmlName).append("=\"").append(escapeForHtmlAttributes(stringValue)).append("\"");
                }
            }
        }
    }
}
Also used : BooleanProperty(org.structr.core.property.BooleanProperty) CustomHtmlAttributeProperty(org.structr.web.property.CustomHtmlAttributeProperty) EditMode(org.structr.web.common.RenderContext.EditMode) GraphObject(org.structr.core.GraphObject) PropertyKey(org.structr.core.property.PropertyKey)

Example 3 with EditMode

use of org.structr.web.common.RenderContext.EditMode in project structr by structr.

the class DOMNode method displayForLocale.

static boolean displayForLocale(final DOMNode thisNode, final RenderContext renderContext) {
    // In raw or widget mode, render everything
    EditMode editMode = renderContext.getEditMode(thisNode.getSecurityContext().getUser(false));
    if (EditMode.DEPLOYMENT.equals(editMode) || EditMode.RAW.equals(editMode) || EditMode.WIDGET.equals(editMode)) {
        return true;
    }
    String localeString = renderContext.getLocale().toString();
    String show = thisNode.getProperty(StructrApp.key(DOMNode.class, "showForLocales"));
    String hide = thisNode.getProperty(StructrApp.key(DOMNode.class, "hideForLocales"));
    // If both fields are empty, render node
    if (StringUtils.isBlank(hide) && StringUtils.isBlank(show)) {
        return true;
    }
    // If locale string is found in hide, don't render
    if (StringUtils.contains(hide, localeString)) {
        return false;
    }
    // If locale string is found in hide, don't render
    if (StringUtils.isNotBlank(show) && !StringUtils.contains(show, localeString)) {
        return false;
    }
    return true;
}
Also used : EditMode(org.structr.web.common.RenderContext.EditMode)

Example 4 with EditMode

use of org.structr.web.common.RenderContext.EditMode in project structr by structr.

the class DOMNode method displayForConditions.

static boolean displayForConditions(final DOMNode thisNode, final RenderContext renderContext) {
    // In raw or widget mode, render everything
    EditMode editMode = renderContext.getEditMode(renderContext.getSecurityContext().getUser(false));
    if (EditMode.DEPLOYMENT.equals(editMode) || EditMode.RAW.equals(editMode) || EditMode.WIDGET.equals(editMode)) {
        return true;
    }
    String _showConditions = thisNode.getProperty(StructrApp.key(DOMNode.class, "showConditions"));
    String _hideConditions = thisNode.getProperty(StructrApp.key(DOMNode.class, "hideConditions"));
    // If both fields are empty, render node
    if (StringUtils.isBlank(_hideConditions) && StringUtils.isBlank(_showConditions)) {
        return true;
    }
    try {
        // If hide conditions evaluate to "true", don't render
        if (StringUtils.isNotBlank(_hideConditions) && Boolean.TRUE.equals(Scripting.evaluate(renderContext, thisNode, "${".concat(_hideConditions).concat("}"), "hide condition"))) {
            return false;
        }
    } catch (UnlicensedException | FrameworkException ex) {
        logger.error("Hide conditions " + _hideConditions + " could not be evaluated.", ex);
    }
    try {
        // If show conditions evaluate to "false", don't render
        if (StringUtils.isNotBlank(_showConditions) && Boolean.FALSE.equals(Scripting.evaluate(renderContext, thisNode, "${".concat(_showConditions).concat("}"), "show condition"))) {
            return false;
        }
    } catch (UnlicensedException | FrameworkException ex) {
        logger.error("Show conditions " + _showConditions + " could not be evaluated.", ex);
    }
    return true;
}
Also used : UnlicensedException(org.structr.common.error.UnlicensedException) FrameworkException(org.structr.common.error.FrameworkException) EditMode(org.structr.web.common.RenderContext.EditMode)

Example 5 with EditMode

use of org.structr.web.common.RenderContext.EditMode in project structr by structr.

the class DOMNode method render.

static void render(final DOMNode thisNode, final RenderContext renderContext, final int depth) throws FrameworkException {
    final SecurityContext securityContext = renderContext.getSecurityContext();
    if (!securityContext.isVisible(thisNode)) {
        return;
    }
    final GraphObject details = renderContext.getDetailsDataObject();
    final boolean detailMode = details != null;
    if (detailMode && thisNode.hideOnDetail()) {
        return;
    }
    if (!detailMode && thisNode.hideOnIndex()) {
        return;
    }
    final EditMode editMode = renderContext.getEditMode(securityContext.getUser(false));
    if (EditMode.RAW.equals(editMode) || EditMode.WIDGET.equals(editMode) || EditMode.DEPLOYMENT.equals(editMode)) {
        thisNode.renderContent(renderContext, depth);
    } else {
        final String subKey = thisNode.getDataKey();
        if (StringUtils.isNotBlank(subKey)) {
            final GraphObject currentDataNode = renderContext.getDataObject();
            // fetch (optional) list of external data elements
            final Iterable<GraphObject> listData = checkListSources(thisNode, securityContext, renderContext);
            final PropertyKey propertyKey;
            if (thisNode.renderDetails() && detailMode) {
                renderContext.setDataObject(details);
                renderContext.putDataObject(subKey, details);
                thisNode.renderContent(renderContext, depth);
            } else {
                if (Iterables.isEmpty(listData) && currentDataNode != null) {
                    // There are two alternative ways of retrieving sub elements:
                    // First try to get generic properties,
                    // if that fails, try to create a propertyKey for the subKey
                    final Object elements = currentDataNode.getProperty(new GenericProperty(subKey));
                    renderContext.setRelatedProperty(new GenericProperty(subKey));
                    renderContext.setSourceDataObject(currentDataNode);
                    if (elements != null) {
                        if (elements instanceof Iterable) {
                            for (Object o : (Iterable) elements) {
                                if (o instanceof GraphObject) {
                                    GraphObject graphObject = (GraphObject) o;
                                    renderContext.putDataObject(subKey, graphObject);
                                    thisNode.renderContent(renderContext, depth);
                                }
                            }
                        }
                    } else {
                        propertyKey = StructrApp.getConfiguration().getPropertyKeyForJSONName(currentDataNode.getClass(), subKey, false);
                        renderContext.setRelatedProperty(propertyKey);
                        if (propertyKey != null) {
                            final Object value = currentDataNode.getProperty(propertyKey);
                            if (value != null) {
                                if (value instanceof Iterable) {
                                    for (final Object o : ((Iterable) value)) {
                                        if (o instanceof GraphObject) {
                                            renderContext.putDataObject(subKey, (GraphObject) o);
                                            thisNode.renderContent(renderContext, depth);
                                        }
                                    }
                                }
                            }
                        }
                    }
                    // reset data node in render context
                    renderContext.setDataObject(currentDataNode);
                    renderContext.setRelatedProperty(null);
                } else {
                    renderContext.setListSource(listData);
                    thisNode.renderNodeList(securityContext, renderContext, depth, subKey);
                }
            }
        } else {
            thisNode.renderContent(renderContext, depth);
        }
    }
}
Also used : SecurityContext(org.structr.common.SecurityContext) GenericProperty(org.structr.core.property.GenericProperty) EditMode(org.structr.web.common.RenderContext.EditMode) GraphObject(org.structr.core.GraphObject) GraphObject(org.structr.core.GraphObject) PropertyKey(org.structr.core.property.PropertyKey)

Aggregations

EditMode (org.structr.web.common.RenderContext.EditMode)10 SecurityContext (org.structr.common.SecurityContext)6 FrameworkException (org.structr.common.error.FrameworkException)4 AsyncBuffer (org.structr.web.common.AsyncBuffer)3 Matcher (java.util.regex.Matcher)2 ThreadLocalMatcher (org.structr.common.ThreadLocalMatcher)2 GraphObject (org.structr.core.GraphObject)2 App (org.structr.core.app.App)2 StructrApp (org.structr.core.app.StructrApp)2 Authenticator (org.structr.core.auth.Authenticator)2 AbstractNode (org.structr.core.entity.AbstractNode)2 Principal (org.structr.core.entity.Principal)2 RelationshipInterface (org.structr.core.graph.RelationshipInterface)2 Tx (org.structr.core.graph.Tx)2 PropertyKey (org.structr.core.property.PropertyKey)2 UiAuthenticator (org.structr.web.auth.UiAuthenticator)2 RenderContext (org.structr.web.common.RenderContext)2 AbstractFile (org.structr.web.entity.AbstractFile)2 File (org.structr.web.entity.File)2 Linkable (org.structr.web.entity.Linkable)2