fix primary edition of eproperty (weird js pb remaining though) tls-sprint
authorsylvain.thenault@logilab.fr
Thu, 09 Apr 2009 12:40:30 +0200
branchtls-sprint
changeset 1314 dc5499bff1a9
parent 1313 9cff1eee0208
child 1315 86bddd181e03
fix primary edition of eproperty (weird js pb remaining though)
web/data/cubicweb.edition.js
web/views/basecontrollers.py
web/views/eproperties.py
--- a/web/data/cubicweb.edition.js	Thu Apr 09 12:37:00 2009 +0200
+++ b/web/data/cubicweb.edition.js	Thu Apr 09 12:40:30 2009 +0200
@@ -20,10 +20,10 @@
  * @param tabindex the tabindex that should be set on the widget
  */
 function setPropValueWidget(varname, tabindex) {
-    var key = firstSelected(jQuery('#pkey:'+varname));
+    var key = firstSelected(document.getElementById('pkey:'+varname));
     if (key) {
 	var args = _buildRemoteArgs('prop_widget', key, varname, tabindex);
-	jQuery('#div:value:'+varname).loadxhtml(JSON_BASE_URL, args, 'post');
+	jqNode('div:value:'+varname).loadxhtml(JSON_BASE_URL, args, 'post');
     }
 }
 
--- a/web/views/basecontrollers.py	Thu Apr 09 12:37:00 2009 +0200
+++ b/web/views/basecontrollers.py	Thu Apr 09 12:40:30 2009 +0200
@@ -388,15 +388,17 @@
 
     def js_prop_widget(self, propkey, varname, tabindex=None):
         """specific method for EProperty handling"""
+        print 'PROP WIDGET', propkey, varname, tabindex
         entity = self.vreg.etype_class('EProperty')(self.req, None, None)
         entity.eid = varname
         entity['pkey'] = propkey
-        entity['value'] = self.vreg.property_info(propkey)['default']
-        form = self.vreg.select_object('forms', 'edition', entity=entity)
+        form = self.vreg.select_object('forms', 'edition', self.req, None,
+                                       entity=entity)
+        form.form_build_context()
         vfield = form.field_by_name('value')
         renderer = FormRenderer()
-        return (vfield.render(form, renderer, tabindex=tabindex)
-                + renderer.render_help(form, vfield))
+        return vfield.render(form, renderer, tabindex=tabindex) \
+                   + renderer.render_help(form, vfield)
 
     def js_component(self, compid, rql, registry='components', extraargs=None):
         if rql:
--- a/web/views/eproperties.py	Thu Apr 09 12:37:00 2009 +0200
+++ b/web/views/eproperties.py	Thu Apr 09 12:40:30 2009 +0200
@@ -227,7 +227,30 @@
             subform.form_add_hidden('for_user', self.user.eid, eidparam=True)
 
 
-# eproperty entity edition ####################################################
+# eproperty form objects ######################################################
+
+class PlaceHolderWidget(object):
+    
+    def render(self, form, field):
+        domid = form.context[field]['id']
+        # empty span as well else html validation fail (label is refering to
+        # this id)
+        return '<div id="div:%s"><span id="%s">%s</span></div>' % (
+            domid, domid, form.req._('select a key first'))
+
+
+class NotEditableWidget(object):
+    def __init__(self, value, msg=None):
+        self.value = value
+        self.msg = msg
+    
+    def render(self, form, field):
+        domid = form.context[field]['id']
+        value = '<span class="value" id="%s">%s</span>' % (domid, self.value)
+        if self.msg:
+            value + '<div class="helper">%s</div>' % self.msg
+        return value
+
 
 class PropertyKeyField(StringField):
     """specific field for EProperty.pkey to set the value widget according to
@@ -249,21 +272,16 @@
             return [(_(entity.pkey), entity.pkey)]
         # key beginning with 'system.' should usually not be edited by hand
         choices = entity.vreg.user_property_keys()
-        return sorted(zip((_(v) for v in choices), choices))
+        return [(u'', u'')] + sorted(zip((_(v) for v in choices), choices))
 
 
 class PropertyValueField(StringField):
     """specific field for EProperty.value  which will be different according to
     the selected key type and vocabulary information
-    """        
+    """
+    widget = PlaceHolderWidget
+    
     def render(self, form, renderer=None, tabindex=None):
-        if not (form.edited_entity.has_eid() or 'pkey' in form.edited_entity):
-            # no key set yet, just include an empty div which will be filled
-            # on key selection
-            # empty span as well elsehtml validation fail (label is refering to
-            # this id)
-            domid = form.context[self]['id']
-            return u'<div id="div:%s"><span id="%s"/></div>' % (domid, domid)
         wdg = self.get_widget(form)
         if tabindex is not None:
             wdg.attrs['tabindex'] = tabindex
@@ -271,6 +289,10 @@
 
     def form_init(self, form):
         entity = form.edited_entity
+        if not (entity.has_eid() or 'pkey' in entity):
+            # no key set yet, just include an empty div which will be filled
+            # on key selection
+            return
         try:
             pdef = form.vreg.property_info(entity.pkey)
         except UnknownProperty, ex:
@@ -303,22 +325,7 @@
                 wdg.attrs.setdefault('size', 3)
         self.widget = wdg
 
-
-class NotEditableWidget(object):
-    def __init__(self, value, msg=None):
-        self.value = value
-        self.msg = msg
+from cubicweb.web import uicfg
+uicfg.rfields.set_rtag(PropertyKeyField, 'pkey', 'subject', 'EProperty')
+uicfg.rfields.set_rtag(PropertyValueField, 'value', 'subject', 'EProperty')
     
-    def render(self, form, field):
-        domid = form.context[field]['id']
-        value = '<span class="value" id="%s">%s</span>' % (domid, self.value)
-        if self.msg:
-            value + '<div class="helper">%s</div>' % self.msg
-        return value
-        
-
-class EPropertyForm(AutomaticEntityForm):
-    __select__ = entity_implements('EProperty')
-    pkey = PropertyKeyField(eidparam=True)
-    value = PropertyValueField(eidparam=True)
-