Skip to content
Snippets Groups Projects
Commit 3fc27320dabe authored by sylvain thenault's avatar sylvain thenault
Browse files

update inline comment creation/edition form

parent bad0283105c5
No related branches found
No related tags found
No related merge requests found
......@@ -19,13 +19,12 @@
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
......@@ -27,12 +26,12 @@
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,7 +150,7 @@
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
......@@ -155,15 +154,4 @@
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):
......@@ -169,6 +157,12 @@
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
......@@ -173,13 +167,12 @@
# 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))
......@@ -185,5 +178,2 @@
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']
......@@ -189,11 +179,5 @@
# 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')
......@@ -197,12 +181,4 @@
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):
......@@ -208,22 +184,5 @@
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 ###########################################################
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment