def morph_inputtag_switch(node): space = node.space assert space.formpath is not None fp = "-".join([str(s) for s in space.formpath[1:]]) if space.formtype != "switch": return Handler.NO_MATCH fields = ("defaultvalue",) p = _extract_fields(space, space.form, fields) checked = None attributes = [ ("type", "checkbox"), ("name", fp), ("id", fp), ("value", ""), ] if p.defaultvalue: attributes.append(("checked","checked")) inputtag = VoidTag("input", attributes) divtag = ComplexTag ( "div", [ ("class", "field-item switch align-left"), ], ( inputtag, TextWrapTag("label", "Off", [ ("for", fp) ], inline = True ), TextWrapTag("label", "On", [ ("for", fp) ], inline = True ), SimpleTag("span", [ ("class", "toggle") ], inline = True) ), ) return _leaf_tag(node, divtag)
def _add_head(node, tag): space = node.space formname = space.formname if space.formnode is not None: formname = space.group.name assert formname is not None, (node.name, space.formpath, node.parent.name, node.parent.space.formpath) fields = ("tooltip", "tooltip_doc", "style") p = _extract_fields(space, space.form, fields) if p.style is None: if space.formtype == "switch": p.style = "h3" else: p.style = "p" divtag = SimpleTag("div", [("class", "title")], inline=True) style = TextWrapTag(p.style, str(formname), inline=True) divtag.attachChild(style, "child") tag.attachChild(divtag, "tag-formname") if p.tooltip is not None: if p.tooltip_doc is not None: tooltiptext = TextWrapTag("a", p.tooltip, [("href", p.tooltip_doc), ("target", "_blank")], inline=True) else: tooltiptext = StringTag(p.tooltip) divtag = SimpleTag("div", [("class", "tooltip")], inline=True) divtag2 = SimpleTag("div", [("class", "tooltip-body")], inline=True) divtag2.attachChild(tooltiptext, "child") divtag.attachChild(divtag2, "child") tag.attachChild(divtag, "tag-tooltip") tip = NullTag() tag.attachChild(tip, "tag-tip") tag.space.htmltip = tip
def morph_selecttag(node): space = node.space assert space.formpath is not None fp = "-".join([str(s) for s in space.formpath[1:]]) if space.formtype != "option": return Handler.NO_MATCH fields = ("defaultvalue",) p = _extract_fields(space, space.form, fields) attributes = [ ("name", fp), ("id", fp), ] options, optiontitles = space.options, space.optiontitles assert len(options) and len(options) == len(optiontitles) children = [] if p.defaultvalue is None: child = SimpleTag("option", (("value",""),"selected"), inline=True ) children.append(child) for opt, optitle in zip(options, optiontitles): attrs = (("value",str(opt)),) if opt == p.defaultvalue: attrs = (("value",str(opt)),"selected") child = TextWrapTag("option", optitle, attrs, inline=True) children.append(child) inputtag = ComplexTag("select", attributes, children) return _div_leaf_tag(node, inputtag, "field-item select align-right")
def _add_headers(node, tag, begin=False): space = node.space if space.othertokens is None: return headers = [h[1][0] for h in space.othertokens if h[0] == "header"] h = "<br>".join(headers) divtag = SimpleTag("div", [("class", "field-container")]) divtag2 = SimpleTag("div", [("class", "title")], inline=True) h3 = TextWrapTag("p", h, inline=True) divtag2.attachChild(h3, "child") divtag.attachChild(divtag2, "child") tag.attachChild(divtag, "tag-header")
def _add_title(node, tag): space = node.space fields = ("title", "title2") p = _extract_fields(space, space.form, fields) if p.title is None and space.form is not None and node.space.complexity is not None: p.title = str(space.formname) if p.title is not None: if p.title2 is not None: fixtag = SimpleTag("div", [("class", "group-inline clearfix")], comment=" <!--END: group-inline -->", lines_after=1, lines_inside_after=1) divtag = SimpleTag("div", [("class", "field-container")], lines_before=1) divtag2 = SimpleTag("div", [("class", "title")], inline=True) h3 = TextWrapTag("h3", p.title, inline=True) divtag2.attachChild(h3, "child") divtag.attachChild(divtag2, "child") fixtag.attachChild(divtag, "tag-title1") divtag = SimpleTag("div", [("class", "field-container")], lines_before=1) divtag2 = SimpleTag("div", [("class", "title")], inline=True) h3 = TextWrapTag("h3", p.title2, inline=True) divtag2.attachChild(h3, "child") divtag.attachChild(divtag2, "child") fixtag.attachChild(divtag, "tag-title2") tag.attachChild(fixtag, "tag-title") else: divtag = SimpleTag("div", [("class", "field-container")]) divtag2 = SimpleTag("div", [("class", "title")], inline=True) h3 = TextWrapTag("h3", p.title, inline=True) divtag2.attachChild(h3, "child") divtag.attachChild(divtag2, "child") tag.attachChild(divtag, "tag-title")
def _add_controls(node): controlchildren = [] if not node.space.controltitle: return NullTag() t = ComplexTag("div", [("class", "title")], [TextWrapTag("h4", node.space.controltitle, inline=True)], inline=True) controlchildren.append(t) t = ComplexTag("div", [ ("class", "button reload-icon reload-form-block") ], [ ComplexTag("div", [("class", "controls-tooltip")], [TextWrapTag("p", "Restore default values", inline=True)], inline=True) ], inline=True) controlchildren.append(t) if node.space.clone is not None and node.space.clone.button is not None: t = ComplexTag( "div", [ ("id", "remove-block-%s-%d" % (node.space.blockname, node.space.blockindex)), ("class", "button close-icon"), ], [ ComplexTag("div", [("class", "controls-tooltip")], [TextWrapTag("p", "Remove partner", inline=True)], inline=True) ], inline=True, ) controlchildren.append(t) return ComplexTag("div", [("class", "controls")], controlchildren, lines_before=1)
def morph_textarea(node): space = node.space if space.formtype != "textarea": return Handler.NO_MATCH assert space.formpath is not None fp = "-".join([str(s) for s in space.formpath[1:]]) fields = ("defaultvalue", "rows") p = _extract_fields(space, space.form, fields) if p.defaultvalue is None: p.defaultvalue = "" p.defaultvalue = str(p.defaultvalue) if p.rows is not None: p.rows = str(p.rows) attributes = [ ("name", fp), ("rows", p.rows), ("id", fp), ] textareatag = TextWrapTag("textarea", p.defaultvalue, attributes, inline=True) return _div_leaf_tag(node, textareatag, "field-item textarea align-right")
def morph_categorywrapper(node): space = node.space divtag = SimpleTag( "div", [ ("id", "page%d" % space.page), ("class", "category-container"), ], lines_before=1, ) if space.html_description: desctexttag = StringTag(space.description) else: desctexttag = TextWrapTag("p", space.description, inline=True) texttag = ComplexTag( "div", [("class", "description")], [ TextWrapTag("h2", space.title, inline=True), desctexttag, ], ) desctag = ComplexTag( "div", [("class", "form-category-description")], [ SimpleTag("div", [("class", "large-icon %s" % space.icon)], inline=True), texttag, ], lines_after=1, ) if space.clones is not None and len(space.clones): children = [] for clone in space.clones: if clone.button is not None: onClick = "cloneBlock('block-%s-',%d);" % (clone.name, clone.length) child = ComplexTag( "div", [("class", "field-container")], [ ComplexTag( "div", [("class", "field-item button align-right")], [ VoidTag( "input", [ ("type", "button"), ("value", clone.button), ("id", "block-%s-add" % clone.name), ("onClick", onClick), ], inline=True, ) ], ) ], ) children.append(child) controltag = ComplexTag( "div", [("class", "category-controls")], children, lines_before=1, lines_after=1, ) desctag.attachChild(controltag, "control") divtag.attachChild(desctag, "description") commenttag = StringTag( "<!-- UI CONTAINER FOR FORM ELEMENTS OF A CATEGORY SELECTED IN CATEGORY NAVIGATION MENU -->", ) divtag.attachChild(commenttag, "comment") contenttag = ComplexTag("div", [("class", "form-category")], comment="<!-- END: UI container -->") divtag.attachChild(contenttag, "content") divtag.space.htmltip = contenttag return _container_tag(node, divtag)