# HG changeset patch # User Sylvain Thénault <sylvain.thenault@logilab.fr> # Date 1272013670 -7200 # Fri Apr 23 11:07:50 2010 +0200 # Branch stable # Node ID ea34a0ba9f268fa056f56d49a83623d1c816b8f9 # Parent acaf3d2bb7cbe70890de1410845002c7b7e0f7a5 refactor: no need for InlineCommentView, nicer id on comment forms. Also properly fix #473629: register/login link should appears on the top of the form when clicking "add comment" diff --git a/data/cubes.comment.js b/data/cubes.comment.js --- a/data/cubes.comment.js +++ b/data/cubes.comment.js @@ -66,14 +66,11 @@ } } -$(document).ready(function() { - function scroll_top(event){ - toggleVisibility('popupLoginBox'); - $('html, body').animate({scrollTop:0}, 'fast'); - return false; - } - $('a.loadPopupLogin').click(scroll_top); -}); +function showLoginBox() { + toggleVisibility('popupLoginBox'); + $('html, body').animate({scrollTop:0}, 'fast'); + return false; +} -CubicWeb.provide('ecomment.js'); +CubicWeb.provide('comment.js'); diff --git a/i18n/en.po b/i18n/en.po --- a/i18n/en.po +++ b/i18n/en.po @@ -37,6 +37,9 @@ msgid "Unknown author" msgstr "" +msgid "You are not authenticated." +msgstr "" + msgid "a comment is a reply about another entity" msgstr "" @@ -58,7 +61,6 @@ msgid "actions_reply_comment" msgstr "reply comment" -# add related box generated message msgid "actions_reply_comment_description" msgstr "" @@ -135,9 +137,6 @@ msgid "thread view" msgstr "" -msgid "to comment" -msgstr "" - msgid "unknown author" msgstr "" diff --git a/i18n/fr.po b/i18n/fr.po --- a/i18n/fr.po +++ b/i18n/fr.po @@ -37,6 +37,9 @@ msgid "Unknown author" msgstr "Auteur inconnu" +msgid "You are not authenticated." +msgstr "Vous n'êtes pas authentifié." + msgid "a comment is a reply about another entity" msgstr "un commentaire autour d'une autre entité" @@ -134,11 +137,11 @@ msgid "thread view" msgstr "vue fil de discussions" -msgid "to comment" -msgstr "pour commenter" - msgid "unknown author" msgstr "auteur inconnu" msgid "written by" msgstr "écrit par" + +#~ msgid "to comment" +#~ msgstr "pour commenter" diff --git a/views.py b/views.py --- a/views.py +++ b/views.py @@ -43,14 +43,6 @@ {'vid': 'list', 'label': _('latest comment(s):'), 'limit': True, 'filter': lambda rset: rset.filtered_rset(lambda x: x.e_schema == 'Comment')}) -def _login_register_link(req): - if 'registration' in req.vreg.config.cubes(): - link = u'<a href="%s">%s</a> or ' % (req.build_url('register'), - req._(u'register')) - else: - link = u'' - link += u'<a class="loadPopupLogin">%s</a>' % req._(u'login') - return link # comment views ############################################################### @@ -129,21 +121,16 @@ if replyaction is not None: url = self._cw.build_ajax_replace_url( 'comment%sHolder' % entity.eid, rql_for_eid(entity.eid), - 'inlinecomment') - if self._cw.cnx.anonymous_connection: - self.w(u' | <span class="replyto">%s <a href="%s">%s</a></span>' - % (_login_register_link(self._cw), - xml_escape(url), self._cw._(replyaction.title))) - else: - self.w(u' | <span class="replyto"><a href="%s">%s</a></span>' - % (xml_escape(url), self._cw._(replyaction.title))) + 'addcommentform') + self.w(u' | <span class="replyto"><a href="%s">%s</a></span>' + % (xml_escape(url), self._cw._(replyaction.title))) editaction = actions.select_or_none('edit_comment', self._cw, rset=self.cw_rset, row=row) if editaction is not None: # split(':', 1)[1] to remove javascript: formjs = self._cw.build_ajax_replace_url( cdivid, rql_for_eid(entity.eid), - 'editcomment', 'append').split(':', 1)[1] + 'editcommentform', 'append').split(':', 1)[1] url = "javascript: jQuery('#%s div').hide(); %s" % (cdivid, formjs) self.w(u' | <span class="replyto"><a href="%s">%s</a></span>' % (xml_escape(url), self._cw._(editaction.title))) @@ -176,16 +163,8 @@ # comment edition views ####################################################### -class InlineCommentView(EntityView): - __regid__ = 'inlinecomment' - __select__ = yes() # explicit call when it makes sense - - def cell_call(self, row, col): - entity = self.cw_rset.get_entity(row, col) - self.wview('inlinecommentform', None, commented=entity) - class InlineEditCommentForm(FormViewMixIn, EntityView): - __regid__ = 'editcomment' + __regid__ = 'editcommentform' __select__ = implements('Comment') jsfunc = "processComment(%s, '%s', false)" @@ -194,10 +173,20 @@ def cell_call(self, row, col): self.comment_form(self.cw_rset.get_entity(row, col)) + def propose_to_login(self): + self.w(u'<div class="warning">%s ' % self._cw._('You are not authenticated.')) + if 'registration' in self._cw.vreg.config.cubes(): + self.w(u'<a href="%s">%s</a> or ' % (self._cw.build_url('register'), + self._cw._(u'register'))) + self.w(u'<a onclick="showLoginBox()">%s</a>' % self._cw._(u'login')) + self.w(u'</div>') + def comment_form(self, commented, newcomment=None): self._cw.add_js('cubes.comment.js') if newcomment is None: newcomment = commented + 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 = dumps(commented.eid) @@ -214,14 +203,15 @@ display_relations_form=False))) -class InlineCommentForm(InlineEditCommentForm): - __regid__ = 'inlinecommentform' - __select__ = match_kwargs('commented') # explicit call when it makes sense +class InlineAddCommentForm(InlineEditCommentForm): + __regid__ = 'addcommentform' + __select__ = relation_possible('comments', 'object', 'Comment', 'add') jsfunc = "processComment(%s, '%s', true)" jsonmeth = 'add_comment' - def call(self, commented): + def cell_call(self, row, col): + commented = self.cw_rset.get_entity(row, col) newcomment = self._cw.vreg['etypes'].etype_class('Comment')(self._cw) newcomment.eid = self._cw.varmaker.next() self.comment_form(commented, newcomment) @@ -263,14 +253,11 @@ if addcomment is not None: self.w(u'<div id="comment%sHolder"></div>' % eid) url = req.build_ajax_replace_url( - 'comment%sHolder' % eid, rql_for_eid(eid), 'inlinecomment') - self.w(u' (<a href="%s" onclick="javascript:toggleVisibility(\'addCommentLinks\');">%s</a>)' % (url, req._(addcomment.title))) + 'comment%sHolder' % eid, rql_for_eid(eid), 'addcommentform') + self.w(u' (<a href="%s">%s</a>)' % (url, req._(addcomment.title))) # XXX still necessary? #if req.use_fckeditor() and req.property_value('ui.default-text-format') == 'text/html': # req.fckeditor_config() - if req.cnx.anonymous_connection: - self.w(u'<div id="addCommentLinks" class="hidden">%s %s</div>' % \ - (_login_register_link(req), req._(u'to comment'))) # comment actions #############################################################