540 'resinput' : self.render_select(form, field, jsnodes['to'], selected=True), |
540 'resinput' : self.render_select(form, field, jsnodes['to'], selected=True), |
541 'addinput' : self.add_button % jsnodes, |
541 'addinput' : self.add_button % jsnodes, |
542 'removeinput': self.remove_button % jsnodes |
542 'removeinput': self.remove_button % jsnodes |
543 }) |
543 }) |
544 |
544 |
|
545 |
545 class BitSelect(Select): |
546 class BitSelect(Select): |
546 """Select widget for IntField using a vocabulary with bit masks as values. |
547 """Select widget for IntField using a vocabulary with bit masks as values. |
547 |
548 |
548 See also :class:`~cubicweb.web.facet.BitFieldFacet`. |
549 See also :class:`~cubicweb.web.facet.BitFieldFacet`. |
549 """ |
550 """ |
685 req.add_js('jquery.ui.datepicker-%s.js' % req.lang) |
686 req.add_js('jquery.ui.datepicker-%s.js' % req.lang) |
686 domid = field.dom_id(form, self.suffix) |
687 domid = field.dom_id(form, self.suffix) |
687 # XXX find a way to understand every format |
688 # XXX find a way to understand every format |
688 fmt = req.property_value('ui.date-format') |
689 fmt = req.property_value('ui.date-format') |
689 fmt = fmt.replace('%Y', 'yy').replace('%m', 'mm').replace('%d', 'dd') |
690 fmt = fmt.replace('%Y', 'yy').replace('%m', 'mm').replace('%d', 'dd') |
690 req.add_onload(u'cw.jqNode("%s").datepicker(' |
691 req.add_onload(u'$("#%s").datepicker(' |
691 '{buttonImage: "%s", dateFormat: "%s", firstDay: 1,' |
692 '{buttonImage: "%s", dateFormat: "%s", firstDay: 1,' |
692 ' showOn: "button", buttonImageOnly: true})' % ( |
693 ' showOn: "button", buttonImageOnly: true})' % ( |
693 domid, req.uiprops['CALENDAR_ICON'], fmt)) |
694 domid, req.uiprops['CALENDAR_ICON'], fmt)) |
694 return self._render_input(form, field, domid) |
695 return self._render_input(form, field) |
695 |
696 |
696 def _render_input(self, form, field, domid): |
697 def _render_input(self, form, field): |
697 if self.value is None: |
698 if self.value is None: |
698 value = self.values(form, field)[0] |
699 value = self.values(form, field)[0] |
699 else: |
700 else: |
700 value = self.value |
701 value = self.value |
701 attrs = self.attributes(form, field) |
702 attrs = self.attributes(form, field) |
702 attrs.setdefault('size', unicode(self.default_size)) |
703 attrs.setdefault('size', unicode(self.default_size)) |
703 return tags.input(name=domid, value=value, type='text', **attrs) |
704 return tags.input(name=field.input_name(form, self.suffix), |
|
705 value=value, type='text', **attrs) |
704 |
706 |
705 |
707 |
706 class JQueryTimePicker(JQueryDatePicker): |
708 class JQueryTimePicker(JQueryDatePicker): |
707 """Use jquery.timePicker to define a time picker. Will return the time as an |
709 """Use jquery.timePicker to define a time picker. Will return the time as an |
708 unicode string. |
710 unicode string. |
716 self.timesteps = timesteps |
718 self.timesteps = timesteps |
717 self.separator = separator |
719 self.separator = separator |
718 |
720 |
719 def _render(self, form, field, renderer): |
721 def _render(self, form, field, renderer): |
720 domid = field.dom_id(form, self.suffix) |
722 domid = field.dom_id(form, self.suffix) |
721 form._cw.add_onload(u'cw.jqNode("%s").timePicker({step: %s, separator: "%s"})' % ( |
723 form._cw.add_onload(u'$("#%s").timePicker({step: %s, separator: "%s"})' % ( |
722 domid, self.timesteps, self.separator)) |
724 domid, self.timesteps, self.separator)) |
723 return self._render_input(form, field, domid) |
725 return self._render_input(form, field) |
724 |
726 |
725 |
727 |
726 class JQueryDateTimePicker(FieldWidget): |
728 class JQueryDateTimePicker(FieldWidget): |
727 """Compound widget using :class:`JQueryDatePicker` and |
729 """Compound widget using :class:`JQueryDatePicker` and |
728 :class:`JQueryTimePicker` widgets to define a date and time picker. Will |
730 :class:`JQueryTimePicker` widgets to define a date and time picker. Will |