def _renderTag(self, ctx, tparser, tvalue, namer, readonly): tag = T.invisible() if len(self.parsers) > 1: tp = T.select(name=namer('tparser'), id=render_cssid(namer('tparser'))) if readonly: tp(class_='disabled', disabled='disabled') for k, v in self.parsers: if k == tparser: tp[T.option(selected='selected', value=k)[v]] else: tp[T.option(value=k)[v]] else: tp = T.input(type='hidden', name=namer('tparser'), id=render_cssid(namer('tparser')), value=self.parsers[0][0]) ta = T.textarea(name=namer('tvalue'), id=render_cssid(namer('tvalue')), cols=self.cols, rows=self.rows)[tvalue or ''] if readonly: ta(class_='readonly', readonly='readonly') tag[tp, T.br, ta] return tag
def render_field(self, ctx, data): # The field we're rendering field = self.field # Get stuff from the context formData = iformal.IFormData(ctx) formErrors = iformal.IFormErrors(ctx, None) # Find any error if formErrors is None: error = None else: error = formErrors.getFieldError(field.key) # Build the error message if error is None: message = '' else: message = T.div(class_='message')[error.message] # Create the widget (it's created in __init__ as a hack) widget = self.widget # Build the list of CSS classes classes = [ 'field', field.type.__class__.__name__.lower(), widget.__class__.__name__.lower(), ] if field.type.required: classes.append('required') if field.cssClass: classes.append(field.cssClass) if error: classes.append('error') # Create the widget and decide the method that should be called if field.type.immutable: render = widget.renderImmutable else: render = widget.render # Fill the slots tag = ctx.tag tag.fillSlots('id', util.render_cssid(field.key)) tag.fillSlots('fieldId', [util.render_cssid(field.key), '-field']) tag.fillSlots('class', ' '.join(classes)) tag.fillSlots('label', field.label) tag.fillSlots('inputs', render(ctx, field.key, formData, formErrors)) tag.fillSlots('message', message) tag.fillSlots('description', T.div(class_='description')[field.description or '']) return ctx.tag
def render(self, ctx, key, args, errors): res = T.div(id=render_cssid("_OUTPUT"), style="position:relative")[customwidgets.SelectChoice( formaltypes.String(), options=self.availableFormats, noneOption=("HTML", "HTML")).render( ctx, "_FORMAT", args, errors)(onchange="output_broadcast(this.value)")] if self.availableFields: res[T.div(title="Additional output column selector", id=render_cssid("_ADDITEMS"), style="visibility:hidden;position:absolute;")[ self._makeAdditionalSelector()]] return res
def render(self, ctx, key, args, errors): # The whole plan sucks -- these should have been two separate widgets children = [] if '_DBOPTIONS' in args: # we're working from pre-parsed (nevow formal) arguments v = [[args["_DBOPTIONS"]["order"]] or "", [args["_DBOPTIONS"]["limit"] or 100], [args["_DBOPTIONS"]["direction"] or "ASC"]] else: # args come raw from nevow contexts v = [args.get("_DBOPTIONS_ORDER", ['']), args.get("MAXREC", [100]), args.get("_DBOPTIONS_DIR", "ASC")] if errors: args = {"_DBOPTIONS_ORDER": v[0], "MAXREC": v[1], "_DBOPTIONS_DIR": v[2]} else: args = {"_DBOPTIONS_ORDER": v[0][0], "MAXREC": int(v[1][0]), "_DBOPTIONS_DIR": v[2][0]} if self.sortWidget: children.extend(["Sort by ", self.sortWidget.render(ctx, "_DBOPTIONS_ORDER", args, errors), " "]) children.extend([" ", self.directionWidget.render(ctx, "_DBOPTIONS_DIR", args, errors)]) if self.limitWidget: children.extend([T.br, "Limit to ", self.limitWidget.render(ctx, "MAXREC", args, errors), " items."]) return T.span(id=render_cssid(key))[children]
def _renderTag(self, ctx, key, value, converter, disabled): if not isinstance(value, (list, tuple)): value = [value] # unfortunately, I need to copy all that code from formal to let # me keep multiple selections def renderOptions(ctx, data): if self.noneOption is not None: noneVal = iformal.IKey(self.noneOption).key() option = T.option(value=noneVal)[ iformal.ILabel(self.noneOption).label()] if value is None or value==noneVal: option = option(selected='selected') yield option if data is None: return for item in data: optValue = iformal.IKey(item).key() optLabel = iformal.ILabel(item).label() optValue = converter.fromType(optValue) option = T.option(value=optValue)[optLabel] if optValue in value: option = option(selected='selected') yield option tag = T.select(name=key, id=render_cssid(key), data=self.options)[ renderOptions] if disabled: tag(class_='disabled', disabled='disabled') return T.span(style="white-space:nowrap")[ tag(size=str(self.size), multiple="multiple"), " ", T.span(class_="fieldlegend")[ "No selection matches all, multiple values legal."]]
def _renderTag(self, ctx, key, value, converter, disabled): def renderOptions(ctx, data): if self.noneOption is not None: yield T.option( value=iformal.IKey(self.noneOption).key())[iformal.ILabel( self.noneOption).label()] if data is None: return for item in data: optValue = iformal.IKey(item).key() optLabel = iformal.ILabel(item).label() optValue = converter.fromType(optValue) option = T.option(value=optValue)[optLabel] if value and optValue in value: option = option(selected='selected') yield option tag = T.select(name=key, id=render_cssid(key), data=self.options, multiple="multiple")[renderOptions] if disabled: tag(class_='disabled', disabled='disabled') return tag
def _renderTag(self, ctx, key, value, readonly): tag = T.invisible() ta = T.textarea(name=key, id=render_cssid(key), cols=self.cols, rows=self.rows)[value or ''] if readonly: ta(class_='readonly', readonly='readonly') tag[ta] if not readonly: try: import docutils except ImportError: raise else: form = iformal.IForm(ctx) srcId = render_cssid(key) previewDiv = render_cssid(key, 'preview-div') frameId = render_cssid(key, 'preview-frame') targetURL = widgetResourceURLFromContext( ctx, form.name).child(key).child(srcId) tag[T.br()] onclick = [ "return Forms.Util.previewShow('", previewDiv, "', '", frameId, "', '", targetURL, "');" ] tag[T.button(onclick=onclick)['Preview ...']] tag[T.div(id=previewDiv, class_="preview-hidden")[ T.iframe(class_="preview-frame", name=frameId, id=frameId), T.br(), T.button(onclick=[ "return Forms.Util.previewHide('", previewDiv, "');" ])['Close']]] return tag
def render_group(self, ctx, data): # Get a reference to the group, for simpler code. group = self.group # Build the CSS class string cssClass = ['group'] if group.cssClass is not None: cssClass.append(group.cssClass) cssClass = ' '.join(cssClass) # Fill the slots tag = ctx.tag tag.fillSlots('id', util.render_cssid(group.key)) tag.fillSlots('cssClass', cssClass) tag.fillSlots('label', group.label) tag.fillSlots('description', group.description or '') tag.fillSlots('items', [inevow.IRenderer(item) for item in group.items]) return ctx.tag
def _renderTag(self, ctx, key, value, readonly): html = [] tag=T.textarea(name=key, id=render_cssid(key), cols=self.cols, rows=self.rows)[value or ''] if readonly: tag(class_='readonly', readonly='readonly') html.append(tag) if self.values is None: return html def renderOptions(ctx,options): for value,label in options: yield T.option(value=value)[label] selecttrigger = T.select(name='%s__selecttrigger'%key, data=self.values)[ renderOptions ] form = iformal.IForm( ctx ) js = T.xml("var x = document.getElementById('%(form)s');x.%(key)s.value += x.%(key)s__selecttrigger.options[x.%(key)s__selecttrigger.options.selectedIndex].value + "\\n";"%{'key':key,'form':form.name}) aonclick = T.a(onclick=js)[ 'add' ] html.append(T.div(class_="add")[selecttrigger,aonclick]) return html
def _renderTag(self, ctx, key, value, readonly): tag=T.textarea(name=key, id=render_cssid(key), rows=self.rows, style="width:100% !important")[value or ''] if readonly: tag(class_='readonly', readonly='readonly') return tag