# HG changeset patch # User Aurelien Campeas # Date 1248439843 -7200 # Node ID 6e328fcc276ce7a5304a31bb25c5434c987bf4dc # Parent a459a6ab78d0d25faaaf0e80ba0cb70c1059d78d [reledit] backport stable fixes diff -r a459a6ab78d0 -r 6e328fcc276c web/data/cubicweb.edition.js --- a/web/data/cubicweb.edition.js Fri Jul 24 12:43:41 2009 +0200 +++ b/web/data/cubicweb.edition.js Fri Jul 24 14:50:43 2009 +0200 @@ -453,6 +453,8 @@ * @param rtype : the attribute being edited * @param eid : the eid of the entity being edited * @param reload: boolean to reload page if true (when changing URL dependant data) + * @param default_value : value if the field is empty + * @param lzone : html fragment (string) for a clic-zone triggering actual edition */ function inlineValidateAttributeForm(rtype, eid, divid, reload, default_value) { try { @@ -477,7 +479,7 @@ if (reload) { document.location.href = result[1]; } else { - var fieldview = getNode(divid); + var fieldview = getNode('value-' + divid); // XXX using innerHTML is very fragile and won't work if // we mix XHTML and HTML fieldview.innerHTML = result[2]; @@ -514,6 +516,7 @@ if (result[0]) { var d = asyncRemoteExec('reledit_form', eid, rtype, role, default_value, lzone); d.addCallback(function (result) { + // XXX brittle ... replace with loadxhtml jQuery('#'+divid+'-reledit').replaceWith(result); }); } diff -r a459a6ab78d0 -r 6e328fcc276c web/views/editforms.py --- a/web/views/editforms.py Fri Jul 24 12:43:41 2009 +0200 +++ b/web/views/editforms.py Fri Jul 24 14:50:43 2009 +0200 @@ -105,7 +105,7 @@ return self._one_rvid def _build_landing_zone(self, lzone): - return lzone or self._defaultlandingzone % {'msg' : self.req._(self._landingzonemsg)} + return lzone or self._defaultlandingzone % {'msg' : xml_escape(self.req._(self._landingzonemsg))} def _build_renderer(self, entity, rtype, role): return self.vreg.select_object('formrenderers', 'base', self.req, @@ -129,6 +129,7 @@ default = xml_escape(self.req._('')) entity = self.entity(row, col) rschema = entity.schema.rschema(rtype) + lzone = self._build_landing_zone(landing_zone) # compute value, checking perms, build form if rschema.is_final(): value = entity.printable_value(rtype) or default @@ -136,7 +137,7 @@ self.w(value) return self._attribute_form(entity, value, rtype, role, reload, - row, col, default, landing_zone) + row, col, default, lzone) else: dispctrl = uicfg.primaryview_display_ctrl.etype_get(entity.e_schema, rtype, role) @@ -160,15 +161,20 @@ self.warning('reledit cannot be applied : (... %s %s [composite])' % (rtype, entity.e_schema)) return self.w(value) - self._relation_form(entity, value, rtype, role, reload, row, col, - rvid, default, landing_zone) + self._relation_form(entity, value, rtype, role, reload, rvid, + default, lzone) - def _relation_form(self, entity, value, rtype, role, row, col, reload, rvid, default, lzone): - lzone = self._build_landing_zone(lzone) + def _relation_form(self, entity, value, rtype, role, reload, rvid, default, lzone): + """xxx-reledit div (class=field) + +-xxx div (class="editableField") + | +-landing zone + +-value + +-form-xxx div + """ divid = 'd%s' % make_uid('%s-%s' % (rtype, entity.eid)) event_data = {'divid' : divid, 'eid' : entity.eid, 'rtype' : rtype, 'vid' : rvid, - 'reload' : reload, 'default' : default, 'role' : role, + 'reload' : dumps(reload), 'default' : default, 'role' : role, 'lzone' : lzone} onsubmit = ("return inlineValidateRelationForm('%(rtype)s', '%(role)s', '%(eid)s', " "'%(divid)s', %(reload)s, '%(vid)s', '%(default)s', '%(lzone)s');" @@ -183,21 +189,30 @@ onclick=cancelclick)]) field = guess_field(entity.e_schema, entity.schema.rschema(rtype), role) form.append_field(field) - self.w(u'
' % divid) - self.w(tags.div(lzone, klass='editableField', id=divid, - onclick=self._onclick % event_data)) - self.w(value) + w = self.w + w(u'
' % divid) + w(tags.div(lzone, klass='editableField', id=divid, + onclick=self._onclick % event_data)) + w(value) renderer = self._build_renderer(entity, rtype, role) - self.w(form.form_render(renderer=renderer)) - self.w(u'
') + w(form.form_render(renderer=renderer)) + w(u'
') def _attribute_form(self, entity, value, rtype, role, reload, row, col, default, lzone): + """div (class=field) + +-xxx div + | +-xxx div (class=editableField) + | | +-landing zone + | +-value-xxx div + | +-value + +-form-xxx div + """ eid = entity.eid divid = 'd%s' % make_uid('%s-%s' % (rtype, eid)) event_data = {'divid' : divid, 'eid' : eid, 'rtype' : rtype, - 'reload' : dumps(reload), 'default' : default, 'lzone' : lzone} + 'reload' : dumps(reload), 'default' : default} onsubmit = ("return inlineValidateAttributeForm('%(rtype)s', '%(eid)s', '%(divid)s', " - "%(reload)s, '%(default)s', '%(lzone)s');") + "%(reload)s, '%(default)s');") buttons = [SubmitButton(stdmsgs.BUTTON_OK), Button(stdmsgs.BUTTON_CANCEL, onclick="hideInlineEdit(%s,\'%s\',\'%s\')" % ( @@ -207,10 +222,17 @@ domid='%s-form' % divid, action='#', cssstyle='display: none', onsubmit=onsubmit % event_data) - self.w(tags.div(value, klass='editableField', id=divid, - onclick=self._onclick % event_data)) + w = self.w + w(u'
') + w(u'
' % divid) + w(tags.div(lzone, klass='editableField', + onclick=self._onclick % event_data)) + w(u'
%s
' % + (divid, value)) + w(u'
') renderer = self._build_renderer(entity, rtype, role) - self.w(form.form_render(renderer=renderer)) + w(form.form_render(renderer=renderer)) + w(u'
') class EditionFormView(FormViewMixIn, EntityView):