# HG changeset patch # User sylvain.thenault@logilab.fr # Date 1240422204 -7200 # Wed Apr 22 19:43:24 2009 +0200 # Branch tls-sprint # Node ID 3fc27320dabec0ca30b01995ea1612f62ff405e7 # Parent bad0283105c582b0bf6b2f63a7edd8769c9335bf update inline comment creation/edition form diff --git a/views.py b/views.py --- a/views.py +++ b/views.py @@ -19,20 +19,19 @@ from cubicweb.selectors import match_kwargs, accept from cubicweb.common.uilib import rql_for_eid, cut, safe_cut, ajax_replace_url from cubicweb.common.mixins import TreeViewMixIn -from cubicweb.web import stdmsgs -from cubicweb.web.action import (LinkToEntityAction, Action) -from cubicweb.web.views import baseviews, baseforms -from cubicweb.web.views.editforms import AutomaticEntityForm -from cubicweb.web.views.boxes import EditBox +from cubicweb.web import stdmsgs, uicfg +from cubicweb.web.action import LinkToEntityAction, Action +from cubicweb.web.form import FormViewMixIn +from cubicweb.web.views import baseviews from cubicweb.web.component import EntityVComponent from cubicweb.web.views.basecontrollers import JSonController _ = unicode -AutomaticEntityForm.rcategories.set_rtag('generic', 'comments', 'subject') -AutomaticEntityForm.rcategories.set_rtag('generic', 'comments', 'object') -EditBox.rmode.set_rtag('link', 'comments', 'subject') -EditBox.rmode.set_rtag('link', 'comments', 'object') +uicfg.rcategories.set_rtag('generated', 'comments', 'subject') +uicfg.rcategories.set_rtag('generated', 'comments', 'object') +uicfg.rmode.set_rtag('link', 'comments', 'subject') +uicfg.rmode.set_rtag('link', 'comments', 'object') # comment views ############################################################### @@ -151,79 +150,39 @@ self.wview('inlinecommentform', None, commented=entity) -class InlineCommentForm(baseforms.CreationForm): +class InlineCommentForm(FormViewMixIn, EntityView): id = 'inlinecommentform' __select__ = match_kwargs('commented') # explicit call when it makes sense - title = None # hidden - - EDITION_BODY = u""" - - <div id="comment%(eid)sSlot">%(attrform)s - <div id="comment%(eid)sbbar"><button onclick="%(onclick)s" tabindex="%(tabindex1)s">%(validate)s</button> - <button onclick="%(oncancelclick)s" tabindex="%(tabindex2)s">%(cancel)s</button> - - </div> -</div> -""" def call(self, commented): - self.req.add_js('cubicweb.ajax.js','cubes.comment.js') - newcomment = self.vreg.etype_class('Comment')(self.req, None, None) - newcomment.eid = 'INLINE' + self.initialize_varmaker() + newcomment = self.vreg.etype_class('Comment')(self.req) + newcomment.eid = self.varmaker.next() + self.comment_form(commented, newcomment) + + def comment_form(self, commented, newcomment=None): + self.req.add_js('cubes.comment.js') + if newcomment is None: + newcomment = comment # hack to avoid tabindex conflicts caused by Ajax requests self.req.next_tabindex = count(20).next - self._hiddens = [] - attrform = self.attributes_form(newcomment, {}) - onclick = html_escape("processComment(%s, 'add_comment')" % dumps(commented.eid)) - oncancelclick = html_escape("processComment(%s, '')" % dumps(commented.eid)) - self.w(self.EDITION_BODY % dict(attrform=attrform, onclick=onclick, oncancelclick=oncancelclick, - eid=commented.eid, - tabindex1=self.req.next_tabindex(), - tabindex2=self.req.next_tabindex(), - validate=self.req._(stdmsgs.BUTTON_OK), - cancel=self.req._(stdmsgs.BUTTON_CANCEL))) + jseid = dumps(commented.eid) + buttons = [Button(onclick="processComment(%s, 'add_comment')" % jseid), + Button(stdmsgs.BUTTON_CANCEL, onclick="processComment(%s, '')" % jseid)] + form = self.vreg.select_object('forms', 'edition', self.req, + entity=newcomment, + form_buttons=buttons, + attrcategories=('primary',)) + self.w(u'<div id="comment%sSlot">%s</div>' % ( + commented.eid, form.form_render(display_relations_form=False)) - def editable_attributes(self, entity): - return [(rschema, x) for rschema, _, x in entity.relations_by_category(('primary'), 'add') - if rschema.is_final() and rschema != 'eid'] - # don't show comments relation in edition forms -try: - baseforms.EditionForm.skip_relations.add('comments') -except AttributeError: - pass # XXX bw compat cubicweb < 2.49 - -class InlineEditCommentForm(baseforms.EditionForm): +class InlineEditCommentForm(InlineCommentForm): id = 'editcomment' __select__ = implements('Comment') - EDITION_BODY = u""" - <div id="comment%(eid)sSlot">%(attrform)s - <div> - <button onclick="%(onclick)s" tabindex="%(tabindex1)s">%(validate)s</button> - <button onclick="%(oncancelclick)s" tabindex="%(tabindex2)s">%(cancel)s</button> - </div> -</div> -""" def cell_call(self, row, col): - self.req.add_js( ('cubicweb.ajax.js', 'cubes.comment.js') ) - # hack to avoid tabindex conflicts caused by Ajax request - self.req.next_tabindex = count(20).next - comment = self.entity(row, col) - self._hiddens = [] - attrform = self.attributes_form(comment, {'tab_class': ''}) - onclick = html_escape("processComment(%s, 'edit_comment')" % dumps(comment.eid)) - oncancelclick = html_escape("processComment(%s, '')" % dumps(comment.eid)) - self.w(self.EDITION_BODY % dict(attrform=attrform, onclick=onclick, oncancelclick=oncancelclick, - eid=comment.eid, - tabindex1=self.req.next_tabindex(), - tabindex2=self.req.next_tabindex(), - validate=self.req._(stdmsgs.BUTTON_OK), - cancel=self.req._(stdmsgs.BUTTON_CANCEL))) - - def editable_attributes(self, entity): - return [(rschema, x) for rschema, _, x in entity.relations_by_category(('primary'), 'add') - if rschema.is_final() and rschema != 'eid'] + self.comment_form(self.entity(row, col)) # comment component ###########################################################