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);
}
}
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("\"");
}
}
}
}
}
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;
}
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;
}
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);
}
}
}
Aggregations