def render(self, form, renderer): wdgs = [self.get_widget(form).render(form, self, renderer)] if self.format_field or self.encoding_field: divid = '%s-advanced' % self.input_name(form) wdgs.append( u'<a href="%s" title="%s"><img src="%s" alt="%s"/></a>' % (xml_escape(uilib.toggle_action(divid)), form._cw._('show advanced fields'), xml_escape(form._cw.data_url('puce_down.png')), form._cw._('show advanced fields'))) wdgs.append(u'<div id="%s" class="hidden">' % divid) if self.name_field: wdgs.append( self.render_subfield(form, self.name_field, renderer)) if self.format_field: wdgs.append( self.render_subfield(form, self.format_field, renderer)) if self.encoding_field: wdgs.append( self.render_subfield(form, self.encoding_field, renderer)) wdgs.append(u'</div>') if not self.required and self.typed_value(form): # trick to be able to delete an uploaded file wdgs.append(u'<br/>') wdgs.append( tags.input(name=self.input_name(form, u'__detach'), type=u'checkbox')) wdgs.append(form._cw._('detach attached file')) return u'\n'.join(wdgs)
def render_fields(self, w, form, values): if form.parent_form is None: w(u'<table class="listing">') # get fields from the first subform with something to display (we # may have subforms with nothing editable that will simply be # skipped later) for subform in form.forms: subfields = [field for field in subform.fields if field.is_visible()] if subfields: break if subfields: # main form, display table headers w(u'<tr class="header">') w(u'<th align="left">%s</th>' % tags.input(type='checkbox', title=self._cw._('toggle check boxes'), onclick="setCheckboxesState('eid', null, this.checked)")) for field in subfields: w(u'<th>%s</th>' % field_label(form, field)) w(u'</tr>') super(EntityCompositeFormRenderer, self).render_fields(w, form, values) if form.parent_form is None: w(u'</table>') if self._main_display_fields: super(EntityCompositeFormRenderer, self)._render_fields( self._main_display_fields, w, form)
def render_fields(self, w, form, values): if form.parent_form is None: # We should probably take those CSS classes to uiprops.py w(u'<table class="table table-striped table-bordered table-condensed">') # get fields from the first subform with something to display (we # may have subforms with nothing editable that will simply be # skipped later) for subform in form.forms: subfields = [field for field in subform.fields if field.is_visible()] if subfields: break if subfields: # main form, display table headers HTML5 w(u'<thead>') w(u'<tr>') w(u'<th>%s</th>' % tags.input(type='checkbox', title=self._cw._('toggle check boxes'), onclick="setCheckboxesState('eid', null, this.checked)")) for field in subfields: w(u'<th>%s</th>' % formrenderers.field_label(form, field)) w(u'</tr>') w(u'</thead>') super(formrenderers.EntityCompositeFormRenderer, self).render_fields(w, form, values) if form.parent_form is None: w(u'</table>') if self._main_display_fields: super(formrenderers.EntityCompositeFormRenderer, self)._render_fields( self._main_display_fields, w, form)
def render_select(self, form, field, name, selected=False): values, attrs = self.values_and_attributes(form, field) options = [] inputs = [] for option in field.vocabulary(form): try: label, value, _oattrs = option except ValueError: label, value = option if selected: # add values if value in values: options.append(tags.option(label, value=value)) # add hidden inputs inputs.append( tags.input(value=value, name=field.dom_id(form), type="hidden")) else: if value not in values: options.append(tags.option(label, value=value)) if 'size' not in attrs: attrs['size'] = self.default_size if 'id' in attrs: attrs.pop('id') return tags.select(name=name, multiple=self._multiple, id=name, options=options, **attrs) + '\n'.join(inputs)
def render_fields(self, w, form, values): if form.parent_form is None: # We should probably take those CSS classes to uiprops.py w(u'<table class="table table-striped table-bordered table-condensed">' ) # get fields from the first subform with something to display (we # may have subforms with nothing editable that will simply be # skipped later) for subform in form.forms: subfields = [ field for field in subform.fields if field.is_visible() ] if subfields: break if subfields: # main form, display table headers HTML5 w(u'<thead>') w(u'<tr>') w(u'<th>%s</th>' % tags.input( type='checkbox', title=self._cw._('toggle check boxes'), onclick="setCheckboxesState('eid', null, this.checked)")) for field in subfields: w(u'<th>%s</th>' % field_label(form, field)) w(u'</tr>') w(u'</thead>') super(EntityCompositeFormRenderer, self).render_fields(w, form, values) if form.parent_form is None: w(u'</table>') if self._main_display_fields: super(EntityCompositeFormRenderer, self)._render_fields(self._main_display_fields, w, form)
def _render(self, form, field, renderer): assert self.suffix is None, 'suffix not supported' values, attrs = self.values_and_attributes(form, field) assert len(values) == 1 domid = attrs.pop('id') inputs = [ tags.input(name=field.input_name(form), value=values[0], type=self.type, id=domid, **attrs), '<br/>', tags.input(name=field.input_name(form, '-confirm'), value=values[0], type=self.type, **attrs), ' ', tags.span(form._cw._('confirm password'), **{'class': 'emphasis'}) ] return u'\n'.join(inputs)
def _render_input(self, form, field): if self.value is None: value = self.values(form, field)[0] else: value = self.value attrs = self.attributes(form, field) attrs.setdefault('size', str(self.default_size)) return tags.input(name=field.input_name(form, self.suffix), value=value, type='text', **attrs)
def _render(self, form, field, renderer): """render the widget for the given `field` of `form`. Generate one <input> tag for each field's value """ values, attrs = self.values_and_attributes(form, field) # ensure something is rendered if not values: values = (INTERNAL_FIELD_VALUE, ) inputs = [ tags.input(name=field.input_name(form, self.suffix), type=self.type, value=value, **attrs) for value in values ] return u'\n'.join(inputs)
def _render(self, form, field, renderer): assert self.suffix is None, 'not supported' req = form._cw pathqname = field.input_name(form, 'path') fqsqname = field.input_name(form, 'fqs') # formatted query string if pathqname in form.form_previous_values: path = form.form_previous_values[pathqname] fqs = form.form_previous_values[fqsqname] else: if field.name in req.form: value = req.form[field.name] else: value = self.typed_value(form, field) if value: try: path, qs = value.split('?', 1) except ValueError: path = value qs = '' else: path = qs = '' fqs = u'\n'.join(u'%s=%s' % (k, v) for k, v in req.url_parse_qsl(qs)) attrs = dict(self.attrs) if self.setdomid: attrs['id'] = field.dom_id(form) # ensure something is rendered inputs = [ u'<table><tr><th>', req._('i18n_bookmark_url_path'), u'</th><td>', tags.input(name=pathqname, type='string', value=path, **attrs), u'</td></tr><tr><th>', req._('i18n_bookmark_url_fqs'), u'</th><td>' ] if self.setdomid: attrs['id'] = field.dom_id(form, 'fqs') attrs.setdefault('cols', 60) attrs.setdefault('onkeyup', 'autogrow(this)') inputs += [ tags.textarea(fqs, name=fqsqname, **attrs), u'</td></tr></table>' ] # surrounding div necessary for proper error localization return u'<div id="%s">%s</div>' % (field.dom_id(form), u'\n'.join(inputs))
def _render(self, form, field, renderer): curvalues, attrs = self.values_and_attributes(form, field) domid = attrs.pop('id', None) sep = self.separator options = [] for i, option in enumerate(field.vocabulary(form)): try: label, value, oattrs = option except ValueError: label, value = option oattrs = {} iattrs = attrs.copy() iattrs.update(oattrs) if i == 0 and domid is not None: iattrs.setdefault('id', domid) if value in curvalues: iattrs['checked'] = u'checked' tag = tags.input(name=field.input_name(form, self.suffix), type=self.type, value=value, **iattrs) options.append(u'<label>%s %s</label>' % (tag, xml_escape(label))) return sep.join(options)