web/formwidgets.py
changeset 5444 f7fdb5dd82f6
parent 5424 8ecbcbff9777
child 5453 d0c8076e298b
equal deleted inserted replaced
5443:f299ee54d7e0 5444:f7fdb5dd82f6
   548         helperid = '%shelper' % inputid
   548         helperid = '%shelper' % inputid
   549         year, month = value.year, value.month
   549         year, month = value.year, value.month
   550         return (u"""<a onclick="toggleCalendar('%s', '%s', %s, %s);" class="calhelper">
   550         return (u"""<a onclick="toggleCalendar('%s', '%s', %s, %s);" class="calhelper">
   551 <img src="%s" title="%s" alt="" /></a><div class="calpopup hidden" id="%s"></div>"""
   551 <img src="%s" title="%s" alt="" /></a><div class="calpopup hidden" id="%s"></div>"""
   552                 % (helperid, inputid, year, month,
   552                 % (helperid, inputid, year, month,
   553                    form._cw.external_resource('CALENDAR_ICON'),
   553                    form._cw.vreg.config.uiprops['CALENDAR_ICON'],
   554                    form._cw._('calendar'), helperid) )
   554                    form._cw._('calendar'), helperid) )
   555 
   555 
   556 
   556 
   557 class JQueryDatePicker(FieldWidget):
   557 class JQueryDatePicker(FieldWidget):
   558     """Use jquery.ui.datepicker to define a date picker. Will return the date as
   558     """Use jquery.ui.datepicker to define a date picker. Will return the date as
   572         fmt = req.property_value('ui.date-format')
   572         fmt = req.property_value('ui.date-format')
   573         fmt = fmt.replace('%Y', 'yy').replace('%m', 'mm').replace('%d', 'dd')
   573         fmt = fmt.replace('%Y', 'yy').replace('%m', 'mm').replace('%d', 'dd')
   574         req.add_onload(u'jqNode("%s").datepicker('
   574         req.add_onload(u'jqNode("%s").datepicker('
   575                        '{buttonImage: "%s", dateFormat: "%s", firstDay: 1,'
   575                        '{buttonImage: "%s", dateFormat: "%s", firstDay: 1,'
   576                        ' showOn: "button", buttonImageOnly: true})' % (
   576                        ' showOn: "button", buttonImageOnly: true})' % (
   577                            domid, req.external_resource('CALENDAR_ICON'), fmt))
   577                            domid, req.vreg.config.uiprops['CALENDAR_ICON'], fmt))
   578         if self.datestr is None:
   578         if self.datestr is None:
   579             value = self.values(form, field)[0]
   579             value = self.values(form, field)[0]
   580         else:
   580         else:
   581             value = self.datestr
   581             value = self.datestr
   582         return tags.input(id=domid, name=domid, value=value,
   582         return tags.input(id=domid, name=domid, value=value,
   952             if self.setdomid:
   952             if self.setdomid:
   953                 attrs['id'] = self.name
   953                 attrs['id'] = self.name
   954         if self.settabindex and not 'tabindex' in attrs:
   954         if self.settabindex and not 'tabindex' in attrs:
   955             attrs['tabindex'] = form._cw.next_tabindex()
   955             attrs['tabindex'] = form._cw.next_tabindex()
   956         if self.icon:
   956         if self.icon:
   957             img = tags.img(src=form._cw.external_resource(self.icon), alt=self.icon)
   957             img = tags.img(src=form._cw.vreg.config.uiprops[self.icon], alt=self.icon)
   958         else:
   958         else:
   959             img = u''
   959             img = u''
   960         return tags.button(img + xml_escape(label), escapecontent=False,
   960         return tags.button(img + xml_escape(label), escapecontent=False,
   961                            value=label, type=self.type, **attrs)
   961                            value=label, type=self.type, **attrs)
   962 
   962 
   983         self.imgressource = imgressource
   983         self.imgressource = imgressource
   984         self.label = label
   984         self.label = label
   985 
   985 
   986     def render(self, form, field=None, renderer=None):
   986     def render(self, form, field=None, renderer=None):
   987         label = form._cw._(self.label)
   987         label = form._cw._(self.label)
   988         imgsrc = form._cw.external_resource(self.imgressource)
   988         imgsrc = form._cw.vreg.config.uiprops[self.imgressource]
   989         return '<a id="%(domid)s" href="%(href)s">'\
   989         return '<a id="%(domid)s" href="%(href)s">'\
   990                '<img src="%(imgsrc)s" alt="%(label)s"/>%(label)s</a>' % {
   990                '<img src="%(imgsrc)s" alt="%(label)s"/>%(label)s</a>' % {
   991             'label': label, 'imgsrc': imgsrc,
   991             'label': label, 'imgsrc': imgsrc,
   992             'domid': self.domid, 'href': self.href}
   992             'domid': self.domid, 'href': self.href}
   993 
   993