diff --git a/.hgtags b/.hgtags index 082c8235ed099ad5bc662d1881a44799accadbce_LmhndGFncw==..5fd9cff8fc4371fd05656d7dc18bd4bb1c14fad1_LmhndGFncw== 100644 --- a/.hgtags +++ b/.hgtags @@ -23,3 +23,5 @@ 4b66ebd9ddf69f877b51fc858a8aaa2d363e3701 cubicweb-comment-debian-version-1.7.1-1 46cc97b563324a908ba029661355663738e900b3 cubicweb-comment-version-1.7.2 a63fa00a1cca5a0f27bb0a57182473a5aabcc604 cubicweb-comment-debian-version-1.7.2-1 +63bd8d2d0591d5b10a919c7c9cdec17f379843d9 cubicweb-comment-version-1.8.0 +5bd7643387325cf0c080ba22fba28e72dca5e07d cubicweb-comment-debian-version-1.8.0-1 diff --git a/__pkginfo__.py b/__pkginfo__.py index 082c8235ed099ad5bc662d1881a44799accadbce_X19wa2dpbmZvX18ucHk=..5fd9cff8fc4371fd05656d7dc18bd4bb1c14fad1_X19wa2dpbmZvX18ucHk= 100644 --- a/__pkginfo__.py +++ b/__pkginfo__.py @@ -4,7 +4,7 @@ modname = 'comment' distname = "cubicweb-%s" % modname -numversion = (1, 7, 2) +numversion = (1, 8, 0) version = '.'.join(str(num) for num in numversion) license = 'LGPL' @@ -19,7 +19,7 @@ 'Programming Language :: JavaScript', ] -__depends__ = {'cubicweb': '>= 3.10.0'} +__depends__ = {'cubicweb': '>= 3.10.8'} # packaging ### diff --git a/data/cubes.comment.js b/data/cubes.comment.js index 082c8235ed099ad5bc662d1881a44799accadbce_ZGF0YS9jdWJlcy5jb21tZW50Lmpz..5fd9cff8fc4371fd05656d7dc18bd4bb1c14fad1_ZGF0YS9jdWJlcy5jb21tZW50Lmpz 100644 --- a/data/cubes.comment.js +++ b/data/cubes.comment.js @@ -1,7 +1,7 @@ /* * :organization: Logilab - * :copyright: 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved. + * :copyright: 2003-2011 LOGILAB S.A. (Paris, FRANCE), all rights reserved. * :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr */ /* this function is called on inlined-comment editions @@ -4,7 +4,8 @@ * :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr */ /* this function is called on inlined-comment editions + * * It calls the [add|eid]_comment method on the jsoncontroller and [re]load * only the view for the added or edited comment */ @@ -8,43 +9,45 @@ * It calls the [add|eid]_comment method on the jsoncontroller and [re]load * only the view for the added or edited comment */ -function processComment(eid, cancel, creation) { - var divId = 'comment' + eid + 'Slot'; - var divNode = jQuery('#'+divId); - var textarea = divNode.find('textarea')[0]; - if (!cancel) { - validateForm('commentForm' + eid, null, - function(result, formid, cbargs) { - var neweid = result[2].eid; - if (creation) { - var commentNode = $('#comment'+ eid); - var ul = null; - if (!commentNode.length) { - // we are adding a comment to the top level entity - commentNode = $('#commentsection' + eid); - klass = 'comment'; - } else { - klass = 'section'; - } - ul = commentNode.find('> ul:first'); - if (!ul.length) { - ul = jQuery(UL({'class': klass})); - commentNode.append(ul); - } - ul.append(LI({'id': 'comment'+ neweid, 'class': 'comment'}, - DIV({'id': 'comment'+ neweid + 'Div'}))); - divNode.remove(); - } - var form = ajaxFuncArgs('render', null, 'views', 'treeitem', neweid); - $('#comment' + neweid + 'Div').loadxhtml('json', form, null, null, true); - }); - } else { - // comment cancelled, close div holding the form - divNode.remove(); - // on edition, show back the comment's content - if (!creation) { - jQuery('#comment' + eid + 'Div div').show(); - } +function processComment(eid, creation, parentcreated, context) { + validateForm( + 'commentsForm' + eid, null, + function(result, formid, cbargs) { + var neweid = result[2].eid; + if (creation) { + var $commentNode = $('#comment'+ eid); + if (!$commentNode.length) { + if (parentcreated) { + // the top level entity has just been created, reload + // the whole components section + reloadCtxComponentsSection(context, neweid, eid) + } else { + // only reload the comments component + reload('commentsection' + eid, 'commentsection', + 'ctxcomponents', null, eid); + } + return ; + } + var ul = $commentNode.find('> ul:first'); + if (!ul.length) { + ul = $(UL({'class': 'section'})); + $commentNode.append(ul); + } + ul.append(LI({'id': 'comment'+ neweid, 'class': 'comment'}, + DIV({'id': 'comment'+ neweid + 'Div'}))); + $('#comment' + eid + 'Slot').remove(); + } + var params = ajaxFuncArgs('render', null, 'views', 'treeitem', neweid); + $('#comment' + neweid + 'Div').loadxhtml('json', params, null, null, true); + }); +} + +function cancelCommentEdition(eid, creation) { + // comment cancelled, close div holding the form + $('#comment' + eid + 'Slot').remove(); + // on edition, show back the comment's content + if (!creation) { + $('#comment' + eid + 'Div div').show(); } } diff --git a/debian/changelog b/debian/changelog index 082c8235ed099ad5bc662d1881a44799accadbce_ZGViaWFuL2NoYW5nZWxvZw==..5fd9cff8fc4371fd05656d7dc18bd4bb1c14fad1_ZGViaWFuL2NoYW5nZWxvZw== 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,9 @@ +cubicweb-comment (1.8.0-1) unstable; urgency=low + + * new upstream release + + -- Sylvain Thénault <sylvain.thenault@logilab.fr> Thu, 10 Feb 2011 17:30:30 +0100 + cubicweb-comment (1.7.2-1) unstable; urgency=low * new upstream release diff --git a/entities.py b/entities.py index 082c8235ed099ad5bc662d1881a44799accadbce_ZW50aXRpZXMucHk=..5fd9cff8fc4371fd05656d7dc18bd4bb1c14fad1_ZW50aXRpZXMucHk= 100644 --- a/entities.py +++ b/entities.py @@ -1,7 +1,7 @@ """entity classes for Comment entities :organization: Logilab -:copyright: 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved. +:copyright: 2003-2011 LOGILAB S.A. (Paris, FRANCE), all rights reserved. :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr """ __docformat__ = "restructuredtext en" diff --git a/i18n/en.po b/i18n/en.po index 082c8235ed099ad5bc662d1881a44799accadbce_aTE4bi9lbi5wbw==..5fd9cff8fc4371fd05656d7dc18bd4bb1c14fad1_aTE4bi9lbi5wbw== 100644 --- a/i18n/en.po +++ b/i18n/en.po @@ -7,6 +7,7 @@ "PO-Revision-Date: 2008-02-15 10:46+0100\n" "Last-Translator: Logilab Team <contact@logilab.fr>\n" "Language-Team: en <contact@logilab.fr>\n" +"Language: \n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" @@ -71,7 +72,6 @@ msgid "comments" msgstr "" -msgctxt "Comment" msgid "comments_object" msgstr "commented by" @@ -75,6 +75,7 @@ msgid "comments_object" msgstr "commented by" +msgctxt "Comment" msgid "comments_object" msgstr "commented by" @@ -92,6 +93,6 @@ msgid "content_format" msgstr "format" -msgid "contentnavigation_commentsection" +msgid "ctxcomponents_commentsection" msgstr "comments thread" @@ -96,7 +97,7 @@ msgstr "comments thread" -msgid "contentnavigation_commentsection_description" +msgid "ctxcomponents_commentsection_description" msgstr "" "section containing comments thread an allowing to post comment on " "commentable entities" @@ -99,7 +100,7 @@ msgstr "" "section containing comments thread an allowing to post comment on " "commentable entities" -msgid "contentnavigation_latestcomments" +msgid "ctxcomponents_latestcomments" msgstr "latest comments" @@ -104,6 +105,6 @@ msgstr "latest comments" -msgid "contentnavigation_latestcomments_description" +msgid "ctxcomponents_latestcomments_description" msgstr "" "section containing latest comments from a user, displayed on his primary view" diff --git a/i18n/fr.po b/i18n/fr.po index 082c8235ed099ad5bc662d1881a44799accadbce_aTE4bi9mci5wbw==..5fd9cff8fc4371fd05656d7dc18bd4bb1c14fad1_aTE4bi9mci5wbw== 100644 --- a/i18n/fr.po +++ b/i18n/fr.po @@ -7,6 +7,7 @@ "PO-Revision-Date: 2008-02-15 10:45+0100\n" "Last-Translator: Logilab Team <contact@logilab.fr>\n" "Language-Team: fr <contact@logilab.fr>\n" +"Language: \n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" @@ -74,7 +75,6 @@ msgid "comments" msgstr "commente" -msgctxt "Comment" msgid "comments_object" msgstr "commenté par" @@ -78,6 +78,7 @@ msgid "comments_object" msgstr "commenté par" +msgctxt "Comment" msgid "comments_object" msgstr "commenté par" @@ -95,6 +96,6 @@ msgid "content_format" msgstr "format" -msgid "contentnavigation_commentsection" +msgid "ctxcomponents_commentsection" msgstr "enfilade de commentaires" @@ -99,6 +100,6 @@ msgstr "enfilade de commentaires" -msgid "contentnavigation_commentsection_description" +msgid "ctxcomponents_commentsection_description" msgstr "" "section affichant la liste des commentaires à propos de l'entité visualisée" @@ -102,6 +103,6 @@ msgstr "" "section affichant la liste des commentaires à propos de l'entité visualisée" -msgid "contentnavigation_latestcomments" +msgid "ctxcomponents_latestcomments" msgstr "derniers commentaires de l'utilisateur" @@ -106,6 +107,6 @@ msgstr "derniers commentaires de l'utilisateur" -msgid "contentnavigation_latestcomments_description" +msgid "ctxcomponents_latestcomments_description" msgstr "" "section affichant les derniers commentaires postés par un utilisateur (sur " "sa vue primaire)" diff --git a/views.py b/views.py index 082c8235ed099ad5bc662d1881a44799accadbce_dmlld3MucHk=..5fd9cff8fc4371fd05656d7dc18bd4bb1c14fad1_dmlld3MucHk= 100644 --- a/views.py +++ b/views.py @@ -1,7 +1,7 @@ """Specific views and actions for application using the Comment entity type :organization: Logilab -:copyright: 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved. +:copyright: 2003-2011 LOGILAB S.A. (Paris, FRANCE), all rights reserved. :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr """ from __future__ import with_statement @@ -21,7 +21,7 @@ match_kwargs, match_form_params, partial_relation_possible, traced_selection) from cubicweb.view import EntityView -from cubicweb.uilib import rql_for_eid, cut, safe_cut +from cubicweb.uilib import rql_for_eid, cut, safe_cut, js from cubicweb.mixins import TreeViewMixIn from cubicweb.web import stdmsgs, uicfg, component, form, formwidgets as fw from cubicweb.web.action import LinkToEntityAction, Action @@ -25,7 +25,8 @@ from cubicweb.mixins import TreeViewMixIn from cubicweb.web import stdmsgs, uicfg, component, form, formwidgets as fw from cubicweb.web.action import LinkToEntityAction, Action -from cubicweb.web.views import primary, baseviews, xmlrss, basecontrollers, treeview +from cubicweb.web.views import (primary, baseviews, xmlrss, basecontrollers, + treeview, ajaxedit) _afs = uicfg.autoform_section _afs.tag_object_of(('*', 'comments', '*'), formtype='main', section='hidden') @@ -204,8 +205,6 @@ __regid__ = 'editcommentform' __select__ = is_instance('Comment') - jsfunc = "processComment(%s, %s, false)" - def entity_call(self, entity): self.comment_form(entity) @@ -220,30 +219,13 @@ self._cw.add_js(('cubicweb.edition.js', 'cubes.comment.js')) if self._cw.cnx.anonymous_connection: self.propose_to_login() - # hack to avoid tabindex conflicts caused by Ajax requests - self._cw.next_tabindex = count(20).next - jseid = json_dumps(commented.eid) - buttons = [fw.Button(onclick=self.jsfunc % (jseid, 'false')), - fw.Button(stdmsgs.BUTTON_CANCEL, - onclick=self.jsfunc % (jseid, 'true'))] - fvreg = self._cw.vreg['forms'] - formvalues = {} - if newcomment is not None: # creation - formvalues['comments'] = commented.eid - if newcomment is None or commented.has_eid(): # creation / edition - # use formtype=inlined to avoid viewing the relation edition section - form = fvreg.select('edition', self._cw, entity=newcomment or commented, - domid='commentForm%s' % commented.eid, - form_buttons=buttons, - formtype='inlined') - else: # creation of both commented and comment entities - form = fvreg.select('composite', self._cw, form_buttons=buttons, - domid='commentForm%s' % commented.eid, - form_renderer_id='default') - form.add_subform(fvreg.select('edition', self._cw, entity=commented, - mainform=False)) - form.add_subform(fvreg.select('edition', self._cw, entity=newcomment, - mainform=False)) + entity = newcomment or commented + okjs = js.processComment(commented.eid, not entity.has_eid(), + not (newcomment is None or commented.has_eid()), + self.cw_extra_kwargs.get('context')) + canceljs = js.cancelCommentEdition(commented.eid, not entity.has_eid()) + form, formvalues = ajaxedit.ajax_composite_form( + commented, newcomment, 'comments', okjs, canceljs) self.w(u'<div id="comment%sSlot">' % commented.eid) form.render(w=self.w, formvalues=formvalues, main_form_title=u'', display_label=False) @@ -255,8 +237,6 @@ __select__ = (relation_possible('comments', 'object', 'Comment', 'add') | match_form_params('etype')) - jsfunc = "processComment(%s, %s, true)" - def call(self, **kwargs): if self.cw_rset is None: entity = self._cw.vreg['etypes'].etype_class(self._cw.form['etype'])(self._cw) @@ -260,7 +240,7 @@ def call(self, **kwargs): if self.cw_rset is None: entity = self._cw.vreg['etypes'].etype_class(self._cw.form['etype'])(self._cw) - entity.eid = self._cw.varmaker.next() + entity.eid = self._cw.form['tempEid'] self.entity_call(entity) else: super(InlineAddCommentFormView, self).call(**kwargs) @@ -295,14 +275,10 @@ 'C comments X, C creation_date CD, C content CC, C content_format CCF, ' \ 'C created_by U?, U login UL, U firstname UF, U surname US, X eid %(x)s' rset = req.execute(rql, {'x': entity.eid}) - else: - rset = None - if not (rset or addcomment): - return - if rset.rowcount: - w(u'<h4>%s</h4>' % (req._('Comment_plural'))) - w(u'<ul class="comment">') - for i in xrange(rset.rowcount): - self.view('tree', rset, row=i, w=w) - w(u'</ul>') + if rset.rowcount: + w(u'<h4>%s</h4>' % (req._('Comment_plural'))) + w(u'<ul class="comment">') + for i in xrange(rset.rowcount): + self._cw.view('tree', rset, row=i, w=w) + w(u'</ul>') if addcomment is not None: @@ -308,18 +284,9 @@ if addcomment is not None: - w(u'<div id="comment%sHolder"></div>' % entity.eid) - params = self.cw_extra_kwargs.copy() - params.pop('view', None) - params.pop('context', None) - if entity.has_eid(): - params['eid'] = entity.eid - else: - params['etype'] = entity.__regid__ - url = req.ajax_replace_url( - 'comment%sHolder' % entity.eid, vid='addcommentform', **params) - w(u' (<a href="%s">%s</a>)' % (xml_escape(url), req._(addcomment.title))) + url = self.lazy_view_holder(w, entity, 'addcommentform') + w(u' <span>(<a href="%s">%s</a>)</span>' % (xml_escape(url), req._(addcomment.title))) class UserLatestCommentsSection(component.EntityCtxComponent): """a section to display latest comments by a user""" __select__ = component.EntityCtxComponent.__select__ & is_instance('CWUser') __regid__ = 'latestcomments' @@ -320,9 +287,10 @@ class UserLatestCommentsSection(component.EntityCtxComponent): """a section to display latest comments by a user""" __select__ = component.EntityCtxComponent.__select__ & is_instance('CWUser') __regid__ = 'latestcomments' + context = 'navcontentbottom' def render_body(self, w): maxrelated = self._cw.property_value('navigation.related-limit') + 1 @@ -334,9 +302,9 @@ if rset: w(u'<div class="section">') w(u'<h4>%s</h4>\n' % self._cw._('Latest comments').capitalize()) - self.view('table', rset, w=w, - headers=[_('about'), _('on date'), - _('comment content')], + self._cw.view('table', rset, w=w, + headers=[_('about'), _('on date'), + _('comment content')], cellvids={0: 'commentroot', 2: 'commentsummary', })