web/formwidgets.py
changeset 5467 57372dbfd114
parent 5453 d0c8076e298b
child 5909 9af8ac182f53
equal deleted inserted replaced
5466:b5af2ac0c43c 5467:57372dbfd114
   547         helperid = '%shelper' % inputid
   547         helperid = '%shelper' % inputid
   548         year, month = value.year, value.month
   548         year, month = value.year, value.month
   549         return (u"""<a onclick="toggleCalendar('%s', '%s', %s, %s);" class="calhelper">
   549         return (u"""<a onclick="toggleCalendar('%s', '%s', %s, %s);" class="calhelper">
   550 <img src="%s" title="%s" alt="" /></a><div class="calpopup hidden" id="%s"></div>"""
   550 <img src="%s" title="%s" alt="" /></a><div class="calpopup hidden" id="%s"></div>"""
   551                 % (helperid, inputid, year, month,
   551                 % (helperid, inputid, year, month,
   552                    form._cw.vreg.config.uiprops['CALENDAR_ICON'],
   552                    form._cw.uiprops['CALENDAR_ICON'],
   553                    form._cw._('calendar'), helperid) )
   553                    form._cw._('calendar'), helperid) )
   554 
   554 
   555 
   555 
   556 class JQueryDatePicker(FieldWidget):
   556 class JQueryDatePicker(FieldWidget):
   557     """Use jquery.ui.datepicker to define a date picker. Will return the date as
   557     """Use jquery.ui.datepicker to define a date picker. Will return the date as
   571         fmt = req.property_value('ui.date-format')
   571         fmt = req.property_value('ui.date-format')
   572         fmt = fmt.replace('%Y', 'yy').replace('%m', 'mm').replace('%d', 'dd')
   572         fmt = fmt.replace('%Y', 'yy').replace('%m', 'mm').replace('%d', 'dd')
   573         req.add_onload(u'jqNode("%s").datepicker('
   573         req.add_onload(u'jqNode("%s").datepicker('
   574                        '{buttonImage: "%s", dateFormat: "%s", firstDay: 1,'
   574                        '{buttonImage: "%s", dateFormat: "%s", firstDay: 1,'
   575                        ' showOn: "button", buttonImageOnly: true})' % (
   575                        ' showOn: "button", buttonImageOnly: true})' % (
   576                            domid, req.vreg.config.uiprops['CALENDAR_ICON'], fmt))
   576                            domid, req.uiprops['CALENDAR_ICON'], fmt))
   577         if self.datestr is None:
   577         if self.datestr is None:
   578             value = self.values(form, field)[0]
   578             value = self.values(form, field)[0]
   579         else:
   579         else:
   580             value = self.datestr
   580             value = self.datestr
   581         return tags.input(id=domid, name=domid, value=value,
   581         return tags.input(id=domid, name=domid, value=value,
   933             if self.setdomid:
   933             if self.setdomid:
   934                 attrs['id'] = self.name
   934                 attrs['id'] = self.name
   935         if self.settabindex and not 'tabindex' in attrs:
   935         if self.settabindex and not 'tabindex' in attrs:
   936             attrs['tabindex'] = form._cw.next_tabindex()
   936             attrs['tabindex'] = form._cw.next_tabindex()
   937         if self.icon:
   937         if self.icon:
   938             img = tags.img(src=form._cw.vreg.config.uiprops[self.icon], alt=self.icon)
   938             img = tags.img(src=form._cw.uiprops[self.icon], alt=self.icon)
   939         else:
   939         else:
   940             img = u''
   940             img = u''
   941         return tags.button(img + xml_escape(label), escapecontent=False,
   941         return tags.button(img + xml_escape(label), escapecontent=False,
   942                            value=label, type=self.type, **attrs)
   942                            value=label, type=self.type, **attrs)
   943 
   943 
   964         self.imgressource = imgressource
   964         self.imgressource = imgressource
   965         self.label = label
   965         self.label = label
   966 
   966 
   967     def render(self, form, field=None, renderer=None):
   967     def render(self, form, field=None, renderer=None):
   968         label = form._cw._(self.label)
   968         label = form._cw._(self.label)
   969         imgsrc = form._cw.vreg.config.uiprops[self.imgressource]
   969         imgsrc = form._cw.uiprops[self.imgressource]
   970         return '<a id="%(domid)s" href="%(href)s">'\
   970         return '<a id="%(domid)s" href="%(href)s">'\
   971                '<img src="%(imgsrc)s" alt="%(label)s"/>%(label)s</a>' % {
   971                '<img src="%(imgsrc)s" alt="%(label)s"/>%(label)s</a>' % {
   972             'label': label, 'imgsrc': imgsrc,
   972             'label': label, 'imgsrc': imgsrc,
   973             'domid': self.domid, 'href': self.href}
   973             'domid': self.domid, 'href': self.href}
   974 
   974