src/cm/media/js/client/c_icomment.js
changeset 525 89ef5ed3c48b
parent 504 b2e0186daa5b
child 532 0bad3613f59d
equal deleted inserted replaced
524:322d0feea350 525:89ef5ed3c48b
    73         duration: gPrefs.get('general','animduration'),
    73         duration: gPrefs.get('general','animduration'),
    74         easing: CY.Easing.easeOut
    74         easing: CY.Easing.easeOut
    75     });   
    75     });   
    76 
    76 
    77   // CY.on won't work 
    77   // CY.on won't work 
    78   this.overlay.get('contentBox').query(".c-close").on("click", this.onCloseCommentClick, this);
    78   this.overlay.get('contentBox').one(".c-close").on("click", this.onCloseCommentClick, this);
    79   this.overlay.get('contentBox').query(".c-moderate").on("click", this.onModerateCommentClick, this);
    79   this.overlay.get('contentBox').one(".c-moderate").on("click", this.onModerateCommentClick, this);
    80   this.overlay.get('contentBox').query(".c-state-pending").on("click", this.onPendingCommentClick, this);
    80   this.overlay.get('contentBox').one(".c-state-pending").on("click", this.onPendingCommentClick, this);
    81   this.overlay.get('contentBox').query(".c-state-approved").on("click", this.onApprovedCommentClick, this);
    81   this.overlay.get('contentBox').one(".c-state-approved").on("click", this.onApprovedCommentClick, this);
    82   this.overlay.get('contentBox').query(".c-state-unapproved").on("click", this.onUnapprovedCommentClick, this);
    82   this.overlay.get('contentBox').one(".c-state-unapproved").on("click", this.onUnapprovedCommentClick, this);
    83   this.overlay.get('contentBox').query(".c-state-cancel").on("click", this.onCancelStateChangeClick, this);
    83   this.overlay.get('contentBox').one(".c-state-cancel").on("click", this.onCancelStateChangeClick, this);
    84   this.overlay.get('contentBox').query(".c-edit").on("click", this.onEditCommentClick, this);
    84   this.overlay.get('contentBox').one(".c-edit").on("click", this.onEditCommentClick, this);
    85   this.overlay.get('contentBox').query(".c-delete").on("click", this.onDeleteCommentClick, this);
    85   this.overlay.get('contentBox').one(".c-delete").on("click", this.onDeleteCommentClick, this);
    86   this.overlay.get('contentBox').query(".c-reply").on("click", this.onReplyCommentClick, this);
    86   this.overlay.get('contentBox').one(".c-reply").on("click", this.onReplyCommentClick, this);
    87   this.overlay.get('contentBox').query(".c-readreplies").on("click", this.onReadRepliesCommentClick, this);
    87   this.overlay.get('contentBox').one(".c-readreplies").on("click", this.onReadRepliesCommentClick, this);
    88 
    88 
    89   this.overlay.get('contentBox').query(".icomment-header").on("mouseenter", this.onMouseEnterHeader, this);
    89   this.overlay.get('contentBox').one(".icomment-header").on("mouseenter", this.onMouseEnterHeader, this);
    90   this.overlay.get('contentBox').query(".icomment-header").on("mouseleave", this.onMouseLeaveHeader, this);
    90   this.overlay.get('contentBox').one(".icomment-header").on("mouseleave", this.onMouseLeaveHeader, this);
    91   
    91   
    92   this.overlay.get('contentBox').on("click", this.onCommentClick, this);
    92   this.overlay.get('contentBox').on("click", this.onCommentClick, this);
    93 }
    93 }
    94 
    94 
    95 IComment.prototype = {
    95 IComment.prototype = {
   103       gSync.closeComment(this) ;
   103       gSync.closeComment(this) ;
   104   },
   104   },
   105   onModerateCommentClick : function (e) {
   105   onModerateCommentClick : function (e) {
   106     e.halt() ; // prevent click triggered on content box
   106     e.halt() ; // prevent click triggered on content box
   107     if (readyForAction() && this.isVisible()) {
   107     if (readyForAction() && this.isVisible()) {
   108       this.overlay.get('contentBox').query(".c-iactions").addClass("displaynone") ;
   108       this.overlay.get('contentBox').one(".c-iactions").addClass("displaynone") ;
   109       this.overlay.get('contentBox').query(".c-state-actions").removeClass("displaynone") ;
   109       this.overlay.get('contentBox').one(".c-state-actions").removeClass("displaynone") ;
   110     }
   110     }
   111   },
   111   },
   112   onPendingCommentClick : function (e) {
   112   onPendingCommentClick : function (e) {
   113     e.halt() ; // prevent click triggered on content box
   113     e.halt() ; // prevent click triggered on content box
   114     if (readyForAction() && this.isVisible()) {
   114     if (readyForAction() && this.isVisible()) {
   128     }
   128     }
   129   },
   129   },
   130   onCancelStateChangeClick : function (e) {
   130   onCancelStateChangeClick : function (e) {
   131     e.halt() ; // prevent click triggered on content box
   131     e.halt() ; // prevent click triggered on content box
   132     if (readyForAction() && this.isVisible()) {
   132     if (readyForAction() && this.isVisible()) {
   133       this.overlay.get('contentBox').query(".c-iactions").removeClass("displaynone") ;
   133       this.overlay.get('contentBox').one(".c-iactions").removeClass("displaynone") ;
   134       this.overlay.get('contentBox').query(".c-state-actions").addClass("displaynone") ;
   134       this.overlay.get('contentBox').one(".c-state-actions").addClass("displaynone") ;
   135     }
   135     }
   136   },
   136   },
   137   onDeleteCommentClick : function (e) {
   137   onDeleteCommentClick : function (e) {
   138     e.halt() ; // prevent click triggered on content box
   138     e.halt() ; // prevent click triggered on content box
   139     if (readyForAction() && this.isVisible()) {
   139     if (readyForAction() && this.isVisible()) {
   197     }
   197     }
   198   },  
   198   },  
   199   
   199   
   200   onMouseEnterHeader : function () {
   200   onMouseEnterHeader : function () {
   201     if (readyForAction() && this.isVisible()) {
   201     if (readyForAction() && this.isVisible()) {
   202       this.overlay.get('contentBox').query(".c-permalink").removeClass('displaynone');
   202       this.overlay.get('contentBox').one(".c-permalink").removeClass('displaynone');
   203     }
   203     }
   204   },
   204   },
   205   
   205   
   206   onMouseLeaveHeader : function () {
   206   onMouseLeaveHeader : function () {
   207     if (readyForAction() && this.isVisible()) {
   207     if (readyForAction() && this.isVisible()) {
   208       this.overlay.get('contentBox').query(".c-permalink").addClass('displaynone');
   208       this.overlay.get('contentBox').one(".c-permalink").addClass('displaynone');
   209     }
   209     }
   210   },  
   210   },  
   211   
   211   
   212   setWidth : function(width) {
   212   setWidth : function(width) {
   213       this.overlay.get('boundingBox').setStyle("width", width + 'px');
   213       this.overlay.get('boundingBox').setStyle("width", width + 'px');
   237       this.overlay.hide();
   237       this.overlay.hide();
   238       this.overlay.blur() ;
   238       this.overlay.blur() ;
   239     }
   239     }
   240   },
   240   },
   241   hideContent:function() {
   241   hideContent:function() {
   242     this.overlay.get('contentBox').query(".icomment-header").addClass('displaynone') ;
   242     this.overlay.get('contentBox').one(".icomment-header").addClass('displaynone') ;
   243     this.overlay.get('contentBox').query(".icomment-body").addClass('displaynone') ;
   243     this.overlay.get('contentBox').one(".icomment-body").addClass('displaynone') ;
   244   },
   244   },
   245   showContent:function() {
   245   showContent:function() {
   246     this.overlay.get('contentBox').query(".icomment-header").removeClass('displaynone') ;
   246     this.overlay.get('contentBox').one(".icomment-header").removeClass('displaynone') ;
   247     this.overlay.get('contentBox').query(".icomment-body").removeClass('displaynone') ;
   247     this.overlay.get('contentBox').one(".icomment-body").removeClass('displaynone') ;
   248   },
   248   },
   249   isVisible:function() {
   249   isVisible:function() {
   250     return this.overlay.get('visible') ;
   250     return this.overlay.get('visible') ;
   251   },
   251   },
   252   show:function() {
   252   show:function() {
   253     this.hideReadRepliesLnk() ; // for now
   253     this.hideReadRepliesLnk() ; // for now
   254     return this.overlay.show() ;
   254     return this.overlay.show() ;
   255   },
   255   },
   256   showReadRepliesLnk:function() {
   256   showReadRepliesLnk:function() {
   257     this.overlay.get('contentBox').query(".c-readreplies").removeClass('displaynone') ;
   257     this.overlay.get('contentBox').one(".c-readreplies").removeClass('displaynone') ;
   258   },
   258   },
   259   hideReadRepliesLnk:function() {
   259   hideReadRepliesLnk:function() {
   260     this.overlay.get('contentBox').query(".c-readreplies").addClass('displaynone') ;
   260     this.overlay.get('contentBox').one(".c-readreplies").addClass('displaynone') ;
   261   },
   261   },
   262   changeModeration:function(comment) {
   262   changeModeration:function(comment) {
   263     var moderationLnk = this.overlay.get('contentBox').query(".c-moderate") ;
   263     var moderationLnk = this.overlay.get('contentBox').one(".c-moderate") ;
   264     moderationLnk.set("innerHTML", gettext(comment.state)) ;
   264     moderationLnk.set("innerHTML", gettext(comment.state)) ;
   265     
   265     
   266     moderationLnk.removeClass("c-state-approved") ;
   266     moderationLnk.removeClass("c-state-approved") ;
   267     moderationLnk.removeClass("c-state-pending") ;
   267     moderationLnk.removeClass("c-state-pending") ;
   268     moderationLnk.removeClass("c-state-unapproved") ;
   268     moderationLnk.removeClass("c-state-unapproved") ;
   269     moderationLnk.addClass("c-state-" + comment.state) ;
   269     moderationLnk.addClass("c-state-" + comment.state) ;
   270 
   270 
   271     this.overlay.get('contentBox').query(".c-iactions").removeClass("displaynone") ;
   271     this.overlay.get('contentBox').one(".c-iactions").removeClass("displaynone") ;
   272     this.overlay.get('contentBox').query(".c-state-actions").addClass("displaynone") ;
   272     this.overlay.get('contentBox').one(".c-state-actions").addClass("displaynone") ;
   273   },
   273   },
   274   isfetched : function() {
   274   isfetched : function() {
   275     return (this.commentId != null) ;
   275     return (this.commentId != null) ;
   276   },
   276   },
   277   unfetch : function() {
   277   unfetch : function() {
   307     var infos = interpolate(gettext('by %(name)s, created on %(date)s'),{'name':comment.name, 'date':comment.created_user_str}, true) ;
   307     var infos = interpolate(gettext('by %(name)s, created on %(date)s'),{'name':comment.name, 'date':comment.created_user_str}, true) ;
   308     
   308     
   309     var newTitleContent = '<span class="c-header"><div class="c-header-title">' + comment.title + permalink + '</div><div class="c-infos">' + infos + '</div></span>' ;
   309     var newTitleContent = '<span class="c-header"><div class="c-header-title">' + comment.title + permalink + '</div><div class="c-infos">' + infos + '</div></span>' ;
   310     
   310     
   311     var newTitleNode = CY.Node.create(newTitleContent) ;
   311     var newTitleNode = CY.Node.create(newTitleContent) ;
   312     var prevTitleNode = boundingBoxNode.query(".c-header") ;
   312     var prevTitleNode = boundingBoxNode.one(".c-header") ;
   313     if (prevTitleNode == null) // first time, no title yet
   313     if (prevTitleNode == null) // first time, no title yet
   314       boundingBoxNode.query('.icomment-header').insertBefore(newTitleNode, boundingBoxNode.one('.c-iactions')) ;
   314       boundingBoxNode.one('.icomment-header').insertBefore(newTitleNode, boundingBoxNode.one('.c-iactions')) ;
   315     else 
   315     else 
   316       prevTitleNode.get('parentNode').replaceChild(newTitleNode, prevTitleNode) ;
   316       prevTitleNode.get('parentNode').replaceChild(newTitleNode, prevTitleNode) ;
   317 
   317 
   318     // TAG
   318     // TAG
   319     var newTagNode = CY.Node.create('<div class="c-tags"><span class="c-tags-infos">' + 'tags:' + '</span>' + comment.tags + '</div>') ;
   319     var newTagNode = CY.Node.create('<div class="c-tags"><span class="c-tags-infos">' + 'tags:' + '</span>' + comment.tags + '</div>') ;
   320     var prevTagNode = boundingBoxNode.query(".c-tags") ;
   320     var prevTagNode = boundingBoxNode.one(".c-tags") ;
   321     if (prevTagNode == null) 
   321     if (prevTagNode == null) 
   322       boundingBoxNode.query('.icomment-header').appendChild(newTagNode) ;
   322       boundingBoxNode.one('.icomment-header').appendChild(newTagNode) ;
   323     else 
   323     else 
   324       prevTagNode.get('parentNode').replaceChild(newTagNode, prevTagNode) ;
   324       prevTagNode.get('parentNode').replaceChild(newTagNode, prevTagNode) ;
   325     // NO TAG ?
   325     // NO TAG ?
   326     if (comment.tags == "")
   326     if (comment.tags == "")
   327       newTagNode.addClass('displaynone') ;
   327       newTagNode.addClass('displaynone') ;
   328 
   328 
   329     // CATEGORY
   329     // CATEGORY
   330     var newCatNode = CY.Node.create('<div class="c-cat">' + gettext("category") + ':&nbsp;<span class="c-cat-val c-cat-' + comment.category + '">' + categories[comment.category] + '</span></div>') ;
   330     var newCatNode = CY.Node.create('<div class="c-cat">' + gettext("category") + ':&nbsp;<span class="c-cat-val c-cat-' + comment.category + '">' + categories[comment.category] + '</span></div>') ;
   331     var prevCatNode = boundingBoxNode.query(".c-cat") ;
   331     var prevCatNode = boundingBoxNode.one(".c-cat") ;
   332     if (prevCatNode == null) 
   332     if (prevCatNode == null) 
   333       boundingBoxNode.query('.icomment-header').appendChild(newCatNode) ;
   333       boundingBoxNode.one('.icomment-header').appendChild(newCatNode) ;
   334     else 
   334     else 
   335       prevCatNode.get('parentNode').replaceChild(newCatNode, prevCatNode) ;
   335       prevCatNode.get('parentNode').replaceChild(newCatNode, prevCatNode) ;
   336     // NO CATEGORY ?
   336     // NO CATEGORY ?
   337     if (comment.category == 0) 
   337     if (comment.category == 0) 
   338       newCatNode.addClass('displaynone') ;
   338       newCatNode.addClass('displaynone') ;
   339 
   339 
   340     // CONTENT
   340     // CONTENT
   341     var newContentNode = CY.Node.create('<span class="c-content">' + comment.content_html + '</span>') ;
   341     var newContentNode = CY.Node.create('<span class="c-content">' + comment.content_html + '</span>') ;
   342     var prevContentNode = boundingBoxNode.query(".c-content") ;
   342     var prevContentNode = boundingBoxNode.one(".c-content") ;
   343     if (prevContentNode == null) 
   343     if (prevContentNode == null) 
   344       boundingBoxNode.query('.icomment-body').appendChild(newContentNode) ;
   344       boundingBoxNode.one('.icomment-body').appendChild(newContentNode) ;
   345     else 
   345     else 
   346       prevContentNode.get('parentNode').replaceChild(newContentNode, prevContentNode) ;
   346       prevContentNode.get('parentNode').replaceChild(newContentNode, prevContentNode) ;
   347 
   347 
   348     // PERMALINK
   348     // PERMALINK
   349     if (sv_prefix=="") {
   349     if (sv_prefix=="") {
   350       boundingBoxNode.query(".c-permalink").set("href",sv_site_url + comment.permalink) ;
   350       boundingBoxNode.one(".c-permalink").set("href",sv_site_url + comment.permalink) ;
   351     }
   351     }
   352     else {
   352     else {
   353       comment_id_delta_prefix = sv_delta != '' ? Array(parseInt(sv_delta)+1).join(',') : '';
   353       comment_id_delta_prefix = sv_delta != '' ? Array(parseInt(sv_delta)+1).join(',') : '';
   354       boundingBoxNode.query(".c-permalink").set("href", top.location.protocol + '//' + top.location.hostname + top.location.pathname + '?comment_id_key=' + comment_id_delta_prefix + comment.id_key) ;
   354       boundingBoxNode.one(".c-permalink").set("href", top.location.protocol + '//' + top.location.hostname + top.location.pathname + '?comment_id_key=' + comment_id_delta_prefix + comment.id_key) ;
   355     }
   355     }
   356 
   356 
   357     // MODERATION
   357     // MODERATION
   358     this.changeModeration(comment) ;
   358     this.changeModeration(comment) ;
   359 /* useless : use implemendted permanentlink instead
   359 /* useless : use implemendted permanentlink instead
   360  * 
   360  * 
   361     // also change link title to give users the possibility to know comment id (to be able to reference this exact comment in GET arguments) 
   361     // also change link title to give users the possibility to know comment id (to be able to reference this exact comment in GET arguments) 
   362     var moderationLnk = this.overlay.get('contentBox').query(".c-moderate") ;
   362     var moderationLnk = this.overlay.get('contentBox').one(".c-moderate") ;
   363     //var cid = (comment.reply_to_id == null) ? this.commentId : "" ;
   363     //var cid = (comment.reply_to_id == null) ? this.commentId : "" ;
   364     moderationLnk.set("title", "click to change comment ID visibility".replace(/ID/, this.commentId).replace(/  /, " ")) ;
   364     moderationLnk.set("title", "click to change comment ID visibility".replace(/ID/, this.commentId).replace(/  /, " ")) ;
   365     
   365     
   366  */   
   366  */   
   367     // open links in new window :
   367     // open links in new window :
   368     var links = boundingBoxNode.queryAll(".c-content a") ;
   368     var links = boundingBoxNode.all(".c-content a") ;
   369     if (links != null)
   369     if (links != null)
   370       links.setAttribute( "target" , "_blank" ) ;
   370       links.setAttribute( "target" , "_blank" ) ;
   371     links = boundingBoxNode.queryAll(".c-header-title a") ;
   371     links = boundingBoxNode.all(".c-header-title a") ;
   372     if (links != null)
   372     if (links != null)
   373       links.setAttribute( "target" , "_blank" ) ;
   373       links.setAttribute( "target" , "_blank" ) ;
   374     
   374     
   375     this.permAdapt(comment) ;
   375     this.permAdapt(comment) ;
   376   },
   376   },
   377 
   377 
   378   permAdapt : function(comment) {
   378   permAdapt : function(comment) {
   379     // this comment permissions 
   379     // this comment permissions 
   380     var delLnk = this.overlay.get('contentBox').query(".c-delete") ; 
   380     var delLnk = this.overlay.get('contentBox').one(".c-delete") ; 
   381     if (delLnk) { // there will be a server side check anyway
   381     if (delLnk) { // there will be a server side check anyway
   382       if (!comment.can_delete)
   382       if (!comment.can_delete)
   383         delLnk.addClass('displaynone') ;
   383         delLnk.addClass('displaynone') ;
   384       else 
   384       else 
   385         delLnk.removeClass('displaynone') ;
   385         delLnk.removeClass('displaynone') ;
   386     }
   386     }
   387 
   387 
   388     var editLnk = this.overlay.get('contentBox').query(".c-edit") ; 
   388     var editLnk = this.overlay.get('contentBox').one(".c-edit") ; 
   389     if (editLnk) {  
   389     if (editLnk) {  
   390       if (!comment.can_edit) 
   390       if (!comment.can_edit) 
   391         editLnk.addClass('displaynone') ;
   391         editLnk.addClass('displaynone') ;
   392       else 
   392       else 
   393         editLnk.removeClass('displaynone') ;
   393         editLnk.removeClass('displaynone') ;
   394     }
   394     }
   395     
   395     
   396     var replyLnk = this.overlay.get('contentBox').query(".c-reply") ;
   396     var replyLnk = this.overlay.get('contentBox').one(".c-reply") ;
   397     if (replyLnk) {
   397     if (replyLnk) {
   398       if (!hasPerm("can_create_comment"))
   398       if (!hasPerm("can_create_comment"))
   399         replyLnk.addClass('displaynone') ;
   399         replyLnk.addClass('displaynone') ;
   400       else 
   400       else 
   401         replyLnk.removeClass('displaynone') ;
   401         replyLnk.removeClass('displaynone') ;
   402     }
   402     }
   403 
   403 
   404     var moderateLnk = this.overlay.get('contentBox').query(".c-moderate") ; 
   404     var moderateLnk = this.overlay.get('contentBox').one(".c-moderate") ; 
   405     if (moderateLnk) {  
   405     if (moderateLnk) {  
   406       if (!comment.can_moderate)  
   406       if (!comment.can_moderate)  
   407         moderateLnk.addClass('displaynone') ;
   407         moderateLnk.addClass('displaynone') ;
   408       else 
   408       else 
   409         moderateLnk.removeClass('displaynone') ;
   409         moderateLnk.removeClass('displaynone') ;
   410     }
   410     }
   411   },
   411   },
   412   setThreadPad : function(pad) { // TODO review ...
   412   setThreadPad : function(pad) { // TODO review ...
   413     this.overlay.get('contentBox').query('.yui-widget-hd').setStyle('paddingLeft', pad + 'px') ;
   413     this.overlay.get('contentBox').one('.yui-widget-hd').setStyle('paddingLeft', pad + 'px') ;
   414     this.overlay.get('contentBox').query('.yui-widget-bd').setStyle('paddingLeft', pad + 'px') ;
   414     this.overlay.get('contentBox').one('.yui-widget-bd').setStyle('paddingLeft', pad + 'px') ;
   415     
   415     
   416   },
   416   },
   417   setPosition : function(xy) {
   417   setPosition : function(xy) {
   418     var boundingBoxNode = this.overlay.get('boundingBox') ;
   418     var boundingBoxNode = this.overlay.get('boundingBox') ;
   419 
   419