209 if splitlabel: |
209 if splitlabel: |
210 label = key.split('.')[-1] |
210 label = key.split('.')[-1] |
211 else: |
211 else: |
212 label = key |
212 label = key |
213 subform = self._cw.vreg['forms'].select('base', self._cw, entity=entity, |
213 subform = self._cw.vreg['forms'].select('base', self._cw, entity=entity, |
214 mainform=False) |
214 mainform=False) |
215 subform.append_field(PropertyValueField(name='value', label=label, |
215 subform.append_field(PropertyValueField(name='value', label=label, |
216 eidparam=True)) |
216 eidparam=True)) |
217 subform.vreg = self._cw.vreg |
217 #subform.vreg = self._cw.vreg |
218 subform.form_add_hidden('pkey', key, eidparam=True) |
218 subform.form_add_hidden('pkey', key, eidparam=True) |
219 form.form_add_subform(subform) |
219 form.form_add_subform(subform) |
220 return subform |
220 return subform |
221 |
221 |
222 |
222 |
263 def render(self, form, field, renderer): |
263 def render(self, form, field, renderer): |
264 domid = form.context[field]['id'] |
264 domid = form.context[field]['id'] |
265 # empty span as well else html validation fail (label is refering to |
265 # empty span as well else html validation fail (label is refering to |
266 # this id) |
266 # this id) |
267 return '<div id="div:%s"><span id="%s">%s</span></div>' % ( |
267 return '<div id="div:%s"><span id="%s">%s</span></div>' % ( |
268 domid, domid, form.req._('select a key first')) |
268 domid, domid, form._cw._('select a key first')) |
269 |
269 |
270 |
270 |
271 class NotEditableWidget(object): |
271 class NotEditableWidget(object): |
272 def __init__(self, value, msg=None): |
272 def __init__(self, value, msg=None): |
273 self.value = value |
273 self.value = value |
287 """ |
287 """ |
288 widget = Select |
288 widget = Select |
289 |
289 |
290 def render(self, form, renderer): |
290 def render(self, form, renderer): |
291 wdg = self.get_widget(form) |
291 wdg = self.get_widget(form) |
292 wdg.attrs['tabindex'] = form.req.next_tabindex() |
292 wdg.attrs['tabindex'] = form._cw.next_tabindex() |
293 wdg.attrs['onchange'] = "javascript:setPropValueWidget('%s', %s)" % ( |
293 wdg.attrs['onchange'] = "javascript:setPropValueWidget('%s', %s)" % ( |
294 form.edited_entity.eid, form.req.next_tabindex()) |
294 form.edited_entity.eid, form._cw.next_tabindex()) |
295 return wdg.render(form, self, renderer) |
295 return wdg.render(form, self, renderer) |
296 |
296 |
297 def vocabulary(self, form): |
297 def vocabulary(self, form): |
298 entity = form.edited_entity |
298 entity = form.edited_entity |
299 _ = form.req._ |
299 _ = form._cw._ |
300 if entity.has_eid(): |
300 if entity.has_eid(): |
301 return [(_(entity.pkey), entity.pkey)] |
301 return [(_(entity.pkey), entity.pkey)] |
302 choices = entity.vreg.user_property_keys() |
302 choices = entity._cw.vreg.user_property_keys() |
303 return [(u'', u'')] + sorted(zip((_(v) for v in choices), choices)) |
303 return [(u'', u'')] + sorted(zip((_(v) for v in choices), choices)) |
304 |
304 |
305 |
305 |
306 class PropertyValueField(StringField): |
306 class PropertyValueField(StringField): |
307 """specific field for CWProperty.value which will be different according to |
307 """specific field for CWProperty.value which will be different according to |
320 if not (entity.has_eid() or 'pkey' in entity): |
320 if not (entity.has_eid() or 'pkey' in entity): |
321 # no key set yet, just include an empty div which will be filled |
321 # no key set yet, just include an empty div which will be filled |
322 # on key selection |
322 # on key selection |
323 return |
323 return |
324 try: |
324 try: |
325 pdef = form.vreg.property_info(entity.pkey) |
325 pdef = form._cw.vreg.property_info(entity.pkey) |
326 except UnknownProperty, ex: |
326 except UnknownProperty, ex: |
327 self.warning('%s (you should probably delete that property ' |
327 self.warning('%s (you should probably delete that property ' |
328 'from the database)', ex) |
328 'from the database)', ex) |
329 msg = form.req._('you should probably delete that property') |
329 msg = form._cw._('you should probably delete that property') |
330 self.widget = NotEditableWidget(entity.printable_value('value'), |
330 self.widget = NotEditableWidget(entity.printable_value('value'), |
331 '%s (%s)' % (msg, ex)) |
331 '%s (%s)' % (msg, ex)) |
332 if entity.pkey.startswith('system.'): |
332 if entity.pkey.startswith('system.'): |
333 msg = form.req._('value associated to this key is not editable ' |
333 msg = form._cw._('value associated to this key is not editable ' |
334 'manually') |
334 'manually') |
335 self.widget = NotEditableWidget(entity.printable_value('value'), msg) |
335 self.widget = NotEditableWidget(entity.printable_value('value'), msg) |
336 # XXX race condition when used from CWPropertyForm, should not rely on |
336 # XXX race condition when used from CWPropertyForm, should not rely on |
337 # instance attributes |
337 # instance attributes |
338 self.initial = pdef['default'] |
338 self.initial = pdef['default'] |
339 self.help = pdef['help'] |
339 self.help = pdef['help'] |
340 vocab = pdef['vocabulary'] |
340 vocab = pdef['vocabulary'] |
341 if vocab is not None: |
341 if vocab is not None: |
342 if callable(vocab): |
342 if callable(vocab): |
343 # list() just in case its a generator function |
343 # list() just in case its a generator function |
344 self.choices = list(vocab(form.req)) |
344 self.choices = list(vocab(form._cw)) |
345 else: |
345 else: |
346 self.choices = vocab |
346 self.choices = vocab |
347 wdg = Select() |
347 wdg = Select() |
348 elif pdef['type'] == 'String': # else we'll get a TextArea by default |
348 elif pdef['type'] == 'String': # else we'll get a TextArea by default |
349 wdg = TextInput() |
349 wdg = TextInput() |