Search in sources :

Example 1 with Type

use of org.structr.api.util.html.attr.Type in project structr by structr.

the class StructrConfigHtmlWriter method beginDocument.

@Override
public RestWriter beginDocument(final String baseUrl, final String propertyView) throws IOException {
    String currentType = baseUrl.replace(restPath + "/", "").replace("/" + propertyView, "");
    if (!propertyView.equals("public")) {
        this.propertyView = "/" + propertyView;
    }
    Tag head = doc.block("head");
    // head.empty("link").attr(new Rel("stylesheet"), new Type("text/css"), new Href("/structr/css/rest.css"));
    // head.inline("script").attr(new Type("text/javascript"), new Src("/structr/js/CollapsibleLists.js"));
    head.inline("style").attr(new Type("text/css")).text("body,html{font-family:\"Liberation Mono\",\"DejaVu Sans Mono\",Consolas,Monaco,\"Vera Sans Mono\",\"Lucida Console\",\"Courier New\",monospace!important;font-size:9pt;padding:0;margin:0}div#top{border-bottom:1px solid #a5a5a5;line-height:2em;background:#363636;background:-webkit-gradient(linear,left bottom,left top,from(#363636),to(#666)) no-repeat;background:-moz-linear-gradient(90deg,#363636,#666) no-repeat;filter:progid:DXImageTransform.Microsoft.Gradient(StartColorStr='#666666', EndColorStr='#363636', GradientType=0);padding:20px;font-family:Arial,Helvetica,Sans-serif}div#top a{color:#fff;text-decoration:none;font-weight:700;margin-right:1em}div#left{background-color:#eee;padding:10px 20px}div#left a{color:#666;text-decoration:none;font-weight:700;margin-right:1em}div#right{clear:both;padding-left:20px}ul{list-style-type:none}b{font-weight:700;color:#444}a.id,a.id:visited{color:#00a}span.type{font-weight:400;color:#080}span.id{font-weight:400;color:#999}span.name{font-weight:700;color:#666}span.string{color:#c60}span.boolean,span.number{color:#00a}span.null{color:#999}.collapsibleListOpen{list-style-image:url(data:image/gif;base64,R0lGODlhBwAHAOcYAAAAAAEBAQICAgMDAwQEBAUFBQYGBgcHBwgICAkJCQoKCgsLCwwMDA0NDQ4ODg8PDxAQEBERERISEhMTExQUFBUVFRYWFhcXFxgYGBkZGRoaGhsbGxwcHB0dHR4eHh8fHyAgICEhISIiIiMjIyQkJCUlJSYmJicnJ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mono\",Consolas,Monaco,\"Vera Sans Mono\",\"Lucida Console\",\"Courier New\",monospace!important;float:right;margin:-.3em 1em 0 0}");
    head.inline("script").attr(new Type("text/javascript")).text("var CollapsibleLists=new function(){function g(b){return function(a){a||(a=window.event);for(a=a.target?a.target:a.srcElement;\"LI\"!=a.nodeName;)a=a.parentNode;a==b&&f(b)}}function f(b){for(var a=b.className.match(/(^| )collapsibleListClosed( |$)/),c=b.getElementsByTagName(\"ul\"),d=0;d<c.length;d++){for(var e=c[d];\"LI\"!=e.nodeName;)e=e.parentNode;e==b&&(c[d].style.display=a?\"block\":\"none\")}b.className=b.className.replace(/(^| )collapsibleList(Open|Closed)( |$)/,\"\");0<c.length&&(b.className+=\" collapsibleList\"+\n" + "(a?\"Open\":\"Closed\"))}this.apply=function(b){for(var a=document.getElementsByTagName(\"ul\"),c=0;c<a.length;c++)if(a[c].className.match(/(^| )collapsibleList( |$)/)&&(this.applyTo(a[c],!0),!b))for(var d=a[c].getElementsByTagName(\"ul\"),e=0;e<d.length;e++)d[e].className+=\" collapsibleList\"};this.applyTo=function(b,a){for(var c=b.getElementsByTagName(\"li\"),d=0;d<c.length;d++)a&&b!=c[d].parentNode||(c[d].addEventListener?c[d].addEventListener(\"click\",g(c[d]),!1):c[d].attachEvent(\"onclick\",g(c[d])),f(c[d]))};\n" + "this.openAll=function(){var b = [].slice.call(document.getElementsByClassName(\"collapsibleListClosed\")); [].forEach.call(b, function (el) { f(el); });};this.closeAll=function(){var b = [].slice.call(document.getElementsByClassName(\"collapsibleListOpen\")); [].forEach.call(b, function (el) { f(el); });}};");
    head.inline("title").text(baseUrl);
    Tag body = doc.block("body").attr(new Onload("if (document.querySelectorAll('#right > ul > li > ul > li > ul.collapsibleList > li').length > 5) { CollapsibleLists.apply(true); }"));
    Tag top = body.block("div").id("top");
    final App app = StructrApp.getInstance(securityContext);
    final Tag left = body.block("div").id("left");
    left.inline("button").attr(new Css("collapse right")).attr(new Attr("onclick", "CollapsibleLists.closeAll()")).text(" - ");
    left.inline("button").attr(new Css("expand right")).attr(new Attr("onclick", "CollapsibleLists.openAll()")).text(" + ");
    try (final Tx tx = app.tx()) {
        final List<SchemaNode> schemaNodes = app.nodeQuery(SchemaNode.class).getAsList();
        Collections.sort(schemaNodes);
        for (SchemaNode node : schemaNodes) {
            final String rawType = node.getName();
            top.inline("a").attr(new Href(restPath + "/" + rawType), new If(rawType.equals(currentType), new Css("active"))).text(rawType);
        }
    } catch (Throwable t) {
        logger.warn("", t);
    }
    for (String view : StructrApp.getConfiguration().getPropertyViews()) {
        if (!hiddenViews.contains(view)) {
            left.inline("a").attr(new Href(restPath + "/" + currentType + "/" + view), new If(view.equals(propertyView), new Css("active"))).text(view);
        }
    }
    // main div
    currentElement = body.block("div").id("right");
    // h1 title
    currentElement.block("h1").text(baseUrl);
    // begin ul
    currentElement = currentElement.block("ul");
    return this;
}
Also used : StructrApp(org.structr.core.app.StructrApp) App(org.structr.core.app.App) Css(org.structr.api.util.html.attr.Css) Tx(org.structr.core.graph.Tx) Href(org.structr.api.util.html.attr.Href) Onload(org.structr.api.util.html.attr.Onload) Attr(org.structr.api.util.html.Attr) SchemaNode(org.structr.core.entity.SchemaNode) Type(org.structr.api.util.html.attr.Type) Tag(org.structr.api.util.html.Tag) If(org.structr.api.util.html.attr.If)

Example 2 with Type

use of org.structr.api.util.html.attr.Type in project structr by structr.

the class StructrJsonHtmlWriter method beginDocument.

@Override
public RestWriter beginDocument(final String baseUrl, final String propertyView) throws IOException {
    String currentType = baseUrl.replace(restPath + "/", "").replace("/" + propertyView, "");
    if (!propertyView.equals("public")) {
        this.propertyView = "/" + propertyView;
    }
    Tag head = doc.block("head");
    // head.empty("link").attr(new Rel("stylesheet"), new Type("text/css"), new Href("/structr/css/rest.css"));
    // head.inline("script").attr(new Type("text/javascript"), new Src("/structr/js/CollapsibleLists.js"));
    head.inline("style").attr(new Type("text/css")).text("body,html{font-family:\"Liberation Mono\",\"DejaVu Sans Mono\",Consolas,Monaco,\"Vera Sans Mono\",\"Lucida Console\",\"Courier New\",monospace!important;font-size:9pt;padding:0;margin:0}div#top{border-bottom:1px solid #a5a5a5;line-height:2em;background:#363636;background:-webkit-gradient(linear,left bottom,left top,from(#363636),to(#666)) no-repeat;background:-moz-linear-gradient(90deg,#363636,#666) no-repeat;filter:progid:DXImageTransform.Microsoft.Gradient(StartColorStr='#666666', EndColorStr='#363636', GradientType=0);padding:20px;font-family:Arial,Helvetica,Sans-serif}div#top a{color:#fff;text-decoration:none;font-weight:700;margin-right:1em}div#left{background-color:#eee;padding:10px 20px}div#left a{color:#666;text-decoration:none;font-weight:700;margin-right:1em}div#right{clear:both;padding-left:20px}ul{list-style-type:none}b{font-weight:700;color:#444}a.id,a.id:visited{color:#00a}span.type{font-weight:400;color:#080}span.id{font-weight:400;color:#999}span.name{font-weight:700;color:#666}span.string{color:#c60}span.boolean,span.number{color:#00a}span.null{color:#999}span.comma{color:#000}.collapsibleListOpen{list-style-image:url(data:image/gif;base64,R0lGODlhBwAHAOcYAAAAAAEBAQICAgMDAwQEBAUFBQYGBgcHBwgICAkJCQoKCgsLCwwMDA0NDQ4ODg8PDxAQEBERERISEhMTExQUFBUVFRYWFhcXFxgYGBkZGRoaGhsbGxwcHB0dHR4eHh8fHyAgICEhISIiIiMjIyQkJCUlJSYmJicnJygoKCkpKSoqKisrKywsLC0tLS4uLi8vLzAwMDExMTIyMjMzMzQ0NDU1NTY2Njc3Nzg4ODk5OTo6Ojs7Ozw8PD09PT4+Pj8/P0BAQEFBQUJCQkNDQ0REREVFRUZGRkdHR0hISElJSUpKSktLS0xMTE1NTU5OTk9PT1BQUFFRUVJSUlNTU1RUVFVVVVZWVldXV1hYWFlZWVpaWltbW1xcXF1dXV5eXl9fX2BgYGFhYWJiYmNjY2RkZGVlZWZmZmdnZ2hoaGlpaWpqamtra2xsbG1tbW5ubm9vb3BwcHFxcXJycnNzc3R0dHV1dXZ2dnd3d3h4eHl5eXp6ent7e3x8fH19fX5+fn9/f4CAgIGB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b3BwcHFxcXJycnNzc3R0dHV1dXZ2dnd3d3h4eHl5eXp6ent7e3x8fH19fX5+fn9/f4CAgIGBgYKCgoODg4SEhIWFhYaGhoeHh4iIiImJiYqKiouLi4yMjI2NjY6Ojo+Pj5CQkJGRkZKSkpOTk5SUlJWVlZaWlpeXl5iYmJmZmZqampubm5ycnJ2dnZ6enp+fn6CgoKGhoaKioqOjo6SkpKWlpaampqenp6ioqKmpqaqqqqurq6ysrK2tra6urq+vr7CwsLGxsbKysrOzs7S0tLW1tba2tre3t7i4uLm5ubq6uru7u7y8vL29vb6+vr+/v8DAwMHBwcLCwsPDw8TExMXFxcbGxsfHx8jIyMnJycrKysvLy8zMzM3Nzc7Ozs/Pz9DQ0NHR0dLS0tPT09TU1NXV1dbW1tfX19jY2NnZ2dra2tvb29zc3N3d3d7e3t/f3+Dg4OHh4eLi4uPj4+Tk5OXl5ebm5ufn5+jo6Onp6erq6uvr6+zs7O3t7e7u7u/v7/Dw8PHx8fLy8vPz8/T09PX19fb29vf39/j4+Pn5+fr6+vv7+/z8/P39/f7+/v///yH5BAEKAP8ALAAAAAAHAAcAAAgXAP8JHEgwE0GBBgdmWriw4MF/CR8KDAgAOw==);cursor:pointer}.collapsibleList{cursor:default}button.collapse,button.expand{font-family:\"Liberation Mono\",\"DejaVu Sans Mono\",Consolas,Monaco,\"Vera Sans Mono\",\"Lucida Console\",\"Courier New\",monospace!important;float:right;margin:-.3em 1em 0 0}li.collapsibleListClosed>ul.collapsibleList>li{display:none}li.collapsibleListClosed>ul.collapsibleList::before{content:\"…\"}li.collapsibleListClosed>ul.collapsibleList:empty{display:none}li.collapsibleListClosed>ul.collapsibleList{line-height:11px;display:inline-block;border:1px solid #aaa;border-radius:6px;padding-left:2px;cursor:pointer;background-color:#ddd;padding-right:3px;margin-left:-5px;margin-right:-5px;font-family:initial}");
    head.inline("script").attr(new Type("text/javascript")).text("var CollapsibleLists=new function(){function g(b){return function(a){a||(a=window.event);for(a=a.target?a.target:a.srcElement;\"LI\"!=a.nodeName;)a=a.parentNode;a==b&&f(b)}}function f(b){for(var a=b.className.match(/(^| )collapsibleListClosed( |$)/),c=b.getElementsByTagName(\"ul\"),d=0;d<c.length;d++){for(var e=c[d];\"LI\"!=e.nodeName;)e=e.parentNode}b.className=b.className.replace(/(^| )collapsibleList(Open|Closed)( |$)/,\"\");0<c.length&&(b.className+=\" collapsibleList\"+\n" + "(a?\"Open\":\"Closed\"))}this.apply=function(b){for(var a=document.getElementsByTagName(\"ul\"),c=0;c<a.length;c++)if(a[c].className.match(/(^| )collapsibleList( |$)/)&&(this.applyTo(a[c],!0),!b))for(var d=a[c].getElementsByTagName(\"ul\"),e=0;e<d.length;e++)d[e].className+=\" collapsibleList\"};this.applyTo=function(b,a){for(var c=b.getElementsByTagName(\"li\"),d=0;d<c.length;d++)a&&b!=c[d].parentNode||(c[d].addEventListener?c[d].addEventListener(\"click\",g(c[d]),!1):c[d].attachEvent(\"onclick\",g(c[d])),f(c[d]))};\n" + "this.openAll=function(){var b = [].slice.call(document.getElementsByClassName(\"collapsibleListClosed\")); [].forEach.call(b, function (el) { f(el); });};this.closeAll=function(){var b = [].slice.call(document.getElementsByClassName(\"collapsibleListOpen\")); [].forEach.call(b, function (el) { f(el); });}};");
    head.inline("title").text(baseUrl);
    Tag body = doc.block("body").attr(new Onload("if (document.querySelectorAll('#right > ul > li > ul > li > ul.collapsibleList > li').length > 5) { CollapsibleLists.apply(true); }"));
    Tag top = body.block("div").id("top");
    final App app = StructrApp.getInstance(securityContext);
    final Tag left = body.block("div").id("left");
    left.inline("button").attr(new Css("collapse right")).attr(new Attr("onclick", "CollapsibleLists.closeAll()")).text(" - ");
    left.inline("button").attr(new Css("expand right")).attr(new Attr("onclick", "CollapsibleLists.openAll()")).text(" + ");
    try (final Tx tx = app.tx()) {
        final List<SchemaNode> schemaNodes = app.nodeQuery(SchemaNode.class).getAsList();
        Collections.sort(schemaNodes);
        for (SchemaNode node : schemaNodes) {
            final String rawType = node.getName();
            top.inline("a").attr(new Href(restPath + "/" + rawType), new If(rawType.equals(currentType), new Css("active"))).text(rawType);
        }
    } catch (Throwable t) {
        logger.warn("", t);
    }
    for (String view : StructrApp.getConfiguration().getPropertyViews()) {
        if (!hiddenViews.contains(view)) {
            left.inline("a").attr(new Href(restPath + "/" + currentType + "/" + view), new If(view.equals(propertyView), new Css("active"))).text(view);
        }
    }
    // main div
    currentElement = body.block("div").id("right");
    // h1 title
    currentElement.block("h1").text(baseUrl);
    // begin ul
    currentElement = currentElement.block("ul");
    return this;
}
Also used : StructrApp(org.structr.core.app.StructrApp) App(org.structr.core.app.App) Css(org.structr.api.util.html.attr.Css) Tx(org.structr.core.graph.Tx) Href(org.structr.api.util.html.attr.Href) Onload(org.structr.api.util.html.attr.Onload) Attr(org.structr.api.util.html.Attr) SchemaNode(org.structr.core.entity.SchemaNode) Type(org.structr.api.util.html.attr.Type) Tag(org.structr.api.util.html.Tag) If(org.structr.api.util.html.attr.If)

Aggregations

Attr (org.structr.api.util.html.Attr)2 Tag (org.structr.api.util.html.Tag)2 Css (org.structr.api.util.html.attr.Css)2 Href (org.structr.api.util.html.attr.Href)2 If (org.structr.api.util.html.attr.If)2 Onload (org.structr.api.util.html.attr.Onload)2 Type (org.structr.api.util.html.attr.Type)2 App (org.structr.core.app.App)2 StructrApp (org.structr.core.app.StructrApp)2 SchemaNode (org.structr.core.entity.SchemaNode)2 Tx (org.structr.core.graph.Tx)2