src/cm/media/js/client/c_icomment.js
author gibus
Mon, 18 Mar 2013 17:29:40 +0100
changeset 501 5cd02f32be5e
parent 410 55ce34b8d146
child 504 b2e0186daa5b
permissions -rw-r--r--
Prevents sumitting comment several time while waiting for server response.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
     1
// globals used: gConf, gPrefs, gLayout, gSync
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
     2
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
     3
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
     4
// IComment == IHM comment class 
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
     5
IComment = function() {
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
     6
  
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
     7
  this.commentId = null ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
     8
  
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
     9
  var iCommentWidth = gLayout.getTopICommentsWidth() ;  
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
    10
  var iCommentLeft = gConf['iCommentLeftPadding'] ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
    11
  
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
    12
  var changeToPending = gettext("change comment state to pending") ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
    13
  var changeToApprove = gettext("change comment state to approved") ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
    14
  var changeToUnapprove= gettext("change comment state to unapproved") ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
    15
  var cancelChange = gettext("cancel changing the state of this comment") ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
    16
  var pending = gettext("pending") ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
    17
  var approved = gettext("approved") ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
    18
  var unapproved = gettext("unapproved") ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
    19
  var cancel = gettext("cancel") ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
    20
  var showReplies = gettext("show replies") ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
    21
  var changeTo= gettext("change to:") ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
    22
  var reply = ngettext("reply","replies",1) ; // hack to get django to add 'replies' as the plural in f_text_view_frame !!
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
    23
  var editComment = gettext("edit comment") ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
    24
  var deleteComment = gettext("delete comment") ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
    25
  var edit = gettext("edit") ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
    26
  var del = gettext("delete") ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
    27
  var close = gettext("close") ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
    28
  var showScope = gettext("show scope") ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
    29
  var scopeRemoved = gettext("Comment is detached: it was created on a previous version and text it applied to has been modified or removed.") ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
    30
  
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
    31
  // no header, no body yet 
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
    32
  this.overlay = new CY.Overlay( {
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
    33
    zIndex :3,
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
    34
    shim :false, /* until we really need it, no shim */
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
    35
    visible :false,
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
    36
    width : iCommentWidth,
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
    37
    xy : [ iCommentLeft, 0 ],
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
    38
    headerContent : '<div class="icomment-header">' +
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
    39
              '<div class="c-iactions">' +  
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
    40
                '<a class="c-moderate c-action" title="">'+ "vis" +'</a>' + " " +  
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
    41
                '<a class="c-edit c-action" title="'+ editComment +'" alt="' + editComment + '">' + edit + '</a>' + " " +   
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
    42
                '<a class="c-delete c-action" title="'+ deleteComment +'" alt="' + deleteComment + '">' + del + '</a>' + " " +   
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
    43
              '</div>' +
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
    44
              '<div class="c-state-actions displaynone">' +
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
    45
                changeTo + '&nbsp;' +
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
    46
                '<a class="c-state-pending c-action" title="' + changeToPending + '" alt="' + changeToPending + '">'+ pending +'</a>' + " " +  
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
    47
                '<a class="c-state-approved c-action" title="' + changeToApprove + '" alt="' + changeToApprove + '">'+ approved +'</a>' + " " +  
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
    48
                '<a class="c-state-unapproved c-action" title="' + changeToUnapprove + '" alt="' + changeToUnapprove + '">'+ unapproved +'</a>' + " " +  
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
    49
                '<a class="c-state-cancel c-action" title="' + cancelChange + '" alt="' + cancelChange + '">' + cancel +'</a>' + " " +  
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
    50
              '</div>' + 
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
    51
              '<div class="c-no-scope-msg">' +
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
    52
                scopeRemoved +  
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
    53
              '</div>' + 
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
    54
              '<a class="c-show-scope c-action" title="'+ showScope + '" alt="' + showScope + '"><em>-</em></a>' +
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
    55
              '<a class="c-close c-action" title="'+ close + '" alt="' + close + '"><em>X</em></a>' +
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
    56
            '</div>',
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
    57
    bodyContent : '<div class="icomment-body">' +
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
    58
            '<span class="c-content"></span>' +
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
    59
            '<span class="c-ireplyactions">' +
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
    60
            '<a class="c-readreplies c-action" title="'+ showReplies +'" alt="' + showReplies + '">' + showReplies +'</a>' + " " +  
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
    61
            '<a class="c-reply c-action" title="'+ reply +'" alt="' + reply + '">' + reply +'</a>' + "&nbsp;" +  
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
    62
            '</span>' +
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
    63
            '</div>'
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
    64
  });
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
    65
  
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
    66
  this.overlay.get('contentBox').addClass("c-comment") ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
    67
  
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
    68
  // attach to DOM
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
    69
  this.overlay.render('#leftcolumn');
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
    70
  
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
    71
  this.animation = new CY.Anim({
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    72
        node: this.overlay.get('boundingBox'),
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    73
        duration: gPrefs.get('general','animduration'),
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    74
        easing: CY.Easing.easeOut
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
    75
    });   
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    76
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
    77
  // CY.on won't work 
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
    78
  this.overlay.get('contentBox').query(".c-close").on("click", this.onCloseCommentClick, this);
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
    79
  this.overlay.get('contentBox').query(".c-moderate").on("click", this.onModerateCommentClick, this);
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
    80
  this.overlay.get('contentBox').query(".c-state-pending").on("click", this.onPendingCommentClick, this);
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
    81
  this.overlay.get('contentBox').query(".c-state-approved").on("click", this.onApprovedCommentClick, this);
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
    82
  this.overlay.get('contentBox').query(".c-state-unapproved").on("click", this.onUnapprovedCommentClick, this);
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
    83
  this.overlay.get('contentBox').query(".c-state-cancel").on("click", this.onCancelStateChangeClick, this);
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
    84
  this.overlay.get('contentBox').query(".c-edit").on("click", this.onEditCommentClick, this);
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
    85
  this.overlay.get('contentBox').query(".c-delete").on("click", this.onDeleteCommentClick, this);
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
    86
  this.overlay.get('contentBox').query(".c-reply").on("click", this.onReplyCommentClick, this);
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
    87
  this.overlay.get('contentBox').query(".c-readreplies").on("click", this.onReadRepliesCommentClick, this);
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    88
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
    89
  this.overlay.get('contentBox').query(".icomment-header").on("mouseenter", this.onMouseEnterHeader, this);
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
    90
  this.overlay.get('contentBox').query(".icomment-header").on("mouseleave", this.onMouseLeaveHeader, this);
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
    91
  
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
    92
  this.overlay.get('contentBox').on("click", this.onCommentClick, this);
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    93
}
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    94
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    95
IComment.prototype = {
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
    96
  // checking readyForAction is not enough because handler could be called after animation end in the case : 
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
    97
  // close btn is clicked before animation end (so before overlay gets hidden) but handler is called after so preventClickOn is false and close is called on an invisible overlay.
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
    98
  // (whan clicking very fast on the close button while close animation is taking place).
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
    99
  // SO : SHOULD ALWAYS CHECK FOR VISIBLE OVERLAY IN HANDLERS THAT COULD BE CALLED FROM AN ANIMATED OVERLAY
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   100
  onCloseCommentClick : function (e) {
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   101
    e.halt() ; // prevent click triggered on content box
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   102
    if (readyForAction() && this.isVisible()) 
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   103
      gSync.closeComment(this) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   104
  },
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   105
  onModerateCommentClick : function (e) {
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   106
    e.halt() ; // prevent click triggered on content box
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   107
    if (readyForAction() && this.isVisible()) {
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   108
      this.overlay.get('contentBox').query(".c-iactions").addClass("displaynone") ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   109
      this.overlay.get('contentBox').query(".c-state-actions").removeClass("displaynone") ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   110
    }
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   111
  },
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   112
  onPendingCommentClick : function (e) {
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   113
    e.halt() ; // prevent click triggered on content box
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   114
    if (readyForAction() && this.isVisible()) {
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   115
      gSync.moderateComment(this, 'pending') ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   116
    }
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   117
  },
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   118
  onApprovedCommentClick : function (e) {
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   119
    e.halt() ; // prevent click triggered on content box
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   120
    if (readyForAction() && this.isVisible()) {
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   121
      gSync.moderateComment(this, 'approved') ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   122
    }
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   123
  },
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   124
  onUnapprovedCommentClick : function (e) {
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   125
    e.halt() ; // prevent click triggered on content box
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   126
    if (readyForAction() && this.isVisible()) {
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   127
      gSync.moderateComment(this, 'unapproved') ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   128
    }
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   129
  },
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   130
  onCancelStateChangeClick : function (e) {
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   131
    e.halt() ; // prevent click triggered on content box
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   132
    if (readyForAction() && this.isVisible()) {
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   133
      this.overlay.get('contentBox').query(".c-iactions").removeClass("displaynone") ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   134
      this.overlay.get('contentBox').query(".c-state-actions").addClass("displaynone") ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   135
    }
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   136
  },
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   137
  onDeleteCommentClick : function (e) {
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   138
    e.halt() ; // prevent click triggered on content box
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   139
    if (readyForAction() && this.isVisible()) {
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   140
      gSync.removeComment(this) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   141
    }
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   142
  },
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   143
  onEditCommentClick : function (e) {
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   144
    e.halt() ; // prevent click triggered on content box
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   145
    if (readyForAction() && this.isVisible()) 
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   146
      gSync.showEditForm(this) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   147
  },
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   148
  onReplyCommentClick : function (e) {
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   149
    e.halt() ; // prevent click triggered on content box
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   150
    if (readyForAction() && this.isVisible()) 
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   151
      gSync.showReplyForm(this) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   152
  },
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   153
  onReadRepliesCommentClick : function (e) {
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   154
    e.halt() ; // prevent click triggered on content box
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   155
    if (readyForAction() && this.isVisible()) 
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   156
      gSync.openComment(this) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   157
  },
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   158
  onCommentClick : function (e) {
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   159
    if (readyForAction() && this.isVisible()) {
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   160
      // first condition here is checking it's not clicked via a 'show comments'  link
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   161
      if (e.target.get("target") == "_blank") {
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   162
        var link = e.target ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   163
        var showCommentUrl = sv_site_url + sv_text_view_show_comment_url ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   164
        if (link.get('href').indexOf(showCommentUrl) == 0) { 
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   165
          var res = (new RegExp('comment_id_key=([^&]*)', "g")).exec(link.get('href')) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   166
          if (res != null) {
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   167
            // open new comment .... we'll suppose it satisfies the filter for now
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   168
            // TODO : should we reset the filter in this case ? instead of having the link open in a new window
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   169
            var id_key = res[1] ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   170
            var comment = gDb.getCommentByIdKey(id_key) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   171
            if (comment != null) {
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   172
              e.halt() ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   173
              if (!link.hasClass("c-permalink")) {// clicking on the permalink itself should do anything
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   174
                checkForOpenedDialog(null, function() {
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   175
                  gSync.showSingleComment(comment) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   176
                }) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   177
              }
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   178
            }
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   179
          }
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   180
        }
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   181
      }
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   182
      else {
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   183
        if (gShowingAllComments) {
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   184
          // next special dirty case test explained : when editing/replying to a comment with gShowingAllComments a click in the edit/reply form also is a click on the iComment, in this case we don't want to showSingleComment ....
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   185
          // should be handled via a preventDefault in some way
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   186
          if (!this._isHostingAForm()) {
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   187
            var comment = gDb.getComment(this.commentId) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   188
            checkForOpenedDialog(null, function() {
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   189
              if (comment != null) 
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   190
                gSync.showSingleComment(comment) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   191
            })
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   192
          }
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   193
        }
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   194
        else 
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   195
          gSync.activate(this) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   196
      }
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   197
    }
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   198
  },  
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   199
  
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   200
  onMouseEnterHeader : function () {
389
eecda8559c1d Allow permalink on comments even when embedfing iframe.
gibus
parents: 341
diff changeset
   201
    if (readyForAction() && this.isVisible()) {
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   202
      this.overlay.get('contentBox').query(".c-permalink").removeClass('displaynone');
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   203
    }
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   204
  },
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   205
  
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   206
  onMouseLeaveHeader : function () {
389
eecda8559c1d Allow permalink on comments even when embedfing iframe.
gibus
parents: 341
diff changeset
   207
    if (readyForAction() && this.isVisible()) {
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   208
      this.overlay.get('contentBox').query(".c-permalink").addClass('displaynone');
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   209
    }
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   210
  },  
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   211
  
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   212
  setWidth : function(width) {
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   213
      this.overlay.get('boundingBox').setStyle("width", width + 'px');
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   214
  },
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   215
  
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   216
  activate:function() {
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   217
    // debug !!
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   218
//    CY.log('activate' + this.commentId) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   219
    this.overlay.get('boundingBox').addClass('c-focus-comment') ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   220
    
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   221
  },
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   222
  
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   223
  deactivate:function() {
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   224
    // debug !!
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   225
//    CY.log('deactivate' + this.commentId) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   226
    this.overlay.get('boundingBox').removeClass('c-focus-comment') ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   227
    
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   228
  },
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   229
  hide:function() {
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   230
    // is IComment the top active one ?
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   231
    if (gIComments.isTopActive(this.commentId)) { // then try to activate next in displayed list
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   232
      if (!gIComments.activateVisibleNext())
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   233
        gIComments.deactivate() ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   234
    }
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   235
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   236
    if (this.isVisible()) {
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   237
      this.overlay.hide();
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   238
      this.overlay.blur() ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   239
    }
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   240
  },
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   241
  hideContent:function() {
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   242
    this.overlay.get('contentBox').query(".icomment-header").addClass('displaynone') ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   243
    this.overlay.get('contentBox').query(".icomment-body").addClass('displaynone') ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   244
  },
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   245
  showContent:function() {
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   246
    this.overlay.get('contentBox').query(".icomment-header").removeClass('displaynone') ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   247
    this.overlay.get('contentBox').query(".icomment-body").removeClass('displaynone') ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   248
  },
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   249
  isVisible:function() {
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   250
    return this.overlay.get('visible') ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   251
  },
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   252
  show:function() {
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   253
    this.hideReadRepliesLnk() ; // for now
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   254
    return this.overlay.show() ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   255
  },
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   256
  showReadRepliesLnk:function() {
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   257
    this.overlay.get('contentBox').query(".c-readreplies").removeClass('displaynone') ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   258
  },
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   259
  hideReadRepliesLnk:function() {
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   260
    this.overlay.get('contentBox').query(".c-readreplies").addClass('displaynone') ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   261
  },
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   262
  changeModeration:function(comment) {
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   263
    var moderationLnk = this.overlay.get('contentBox').query(".c-moderate") ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   264
    moderationLnk.set("innerHTML", gettext(comment.state)) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   265
    
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   266
    moderationLnk.removeClass("c-state-approved") ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   267
    moderationLnk.removeClass("c-state-pending") ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   268
    moderationLnk.removeClass("c-state-unapproved") ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   269
    moderationLnk.addClass("c-state-" + comment.state) ;
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   270
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   271
    this.overlay.get('contentBox').query(".c-iactions").removeClass("displaynone") ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   272
    this.overlay.get('contentBox').query(".c-state-actions").addClass("displaynone") ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   273
  },
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   274
  isfetched : function() {
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   275
    return (this.commentId != null) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   276
  },
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   277
  unfetch : function() {
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   278
    this.commentId = null ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   279
  },
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   280
  fetch : function(comment) {
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   281
    this.commentId = comment.id ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   282
    var boundingBoxNode = this.overlay.get('boundingBox') ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   283
    
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   284
    if (comment['start_wrapper'] != -1){ 
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   285
      boundingBoxNode.addClass('c-has-scope') ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   286
      boundingBoxNode.removeClass('c-has-no-scope') ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   287
    }
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   288
    else { 
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   289
      boundingBoxNode.addClass('c-has-no-scope') ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   290
      boundingBoxNode.removeClass('c-has-scope') ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   291
    }
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   292
    
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   293
    if (comment['reply_to_id'] != null){ 
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   294
      boundingBoxNode.addClass('c-is-reply') ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   295
    }
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   296
    else { 
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   297
      boundingBoxNode.removeClass('c-is-reply') ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   298
    }
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   299
    
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   300
    // TITLE
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   301
    var titleInfos = interpolate(gettext('last modified on %(date)s'),{'date':comment.modified_user_str}, true) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   302
    
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   303
    var modifDateTooltip = (comment.modified == comment.created) ? '' : '<a title="' + titleInfos + '"> * </a>' ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   304
    var permaTitle = gettext('Permalink to this comment') ;
389
eecda8559c1d Allow permalink on comments even when embedfing iframe.
gibus
parents: 341
diff changeset
   305
    var permalink = '<a class="c-permalink displaynone c-action" target="_blank" title="'+ permaTitle +'" href="" >¶&nbsp;</a>' ;
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   306
    
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   307
    var infos = interpolate(gettext('by %(name)s, created on %(date)s'),{'name':comment.name, 'date':comment.created_user_str}, true) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   308
    
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   309
    var newTitleContent = '<span class="c-header"><div class="c-header-title">' + comment.title + permalink + '</div><div class="c-infos">' + infos + '</div></span>' ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   310
    
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   311
    var newTitleNode = CY.Node.create(newTitleContent) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   312
    var prevTitleNode = boundingBoxNode.query(".c-header") ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   313
    if (prevTitleNode == null) // first time, no title yet
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   314
      boundingBoxNode.query('.icomment-header').insertBefore(newTitleNode, boundingBoxNode.one('.c-iactions')) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   315
    else 
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   316
      prevTitleNode.get('parentNode').replaceChild(newTitleNode, prevTitleNode) ;
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   317
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   318
    // TAG
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   319
    var newTagNode = CY.Node.create('<div class="c-tags"><span class="c-tags-infos">' + 'tags:' + '</span>' + comment.tags + '</div>') ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   320
    var prevTagNode = boundingBoxNode.query(".c-tags") ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   321
    if (prevTagNode == null) 
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   322
      boundingBoxNode.query('.icomment-header').appendChild(newTagNode) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   323
    else 
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   324
      prevTagNode.get('parentNode').replaceChild(newTagNode, prevTagNode) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   325
    // NO TAG ?
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   326
    if (comment.tags == "")
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   327
      newTagNode.addClass('displaynone') ;
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   328
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   329
    // CONTENT
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   330
    var newContentNode = CY.Node.create('<span class="c-content">' + comment.content_html + '</span>') ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   331
    var prevContentNode = boundingBoxNode.query(".c-content") ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   332
    if (prevContentNode == null) 
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   333
      boundingBoxNode.query('.icomment-body').appendChild(newContentNode) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   334
    else 
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   335
      prevContentNode.get('parentNode').replaceChild(newContentNode, prevContentNode) ;
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   336
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   337
    // PERMALINK
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   338
    if (sv_prefix=="") {
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   339
      boundingBoxNode.query(".c-permalink").set("href",sv_site_url + comment.permalink) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   340
    }
389
eecda8559c1d Allow permalink on comments even when embedfing iframe.
gibus
parents: 341
diff changeset
   341
    else {
410
55ce34b8d146 Allows multiple co-mentable texts to be isplayed in the same HTML page (with Drupal 7 co_ment module).
Production Moz <dev@sopinspace.com>
parents: 389
diff changeset
   342
      comment_id_delta_prefix = sv_delta != '' ? Array(parseInt(sv_delta)+1).join(',') : '';
55ce34b8d146 Allows multiple co-mentable texts to be isplayed in the same HTML page (with Drupal 7 co_ment module).
Production Moz <dev@sopinspace.com>
parents: 389
diff changeset
   343
      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) ;
389
eecda8559c1d Allow permalink on comments even when embedfing iframe.
gibus
parents: 341
diff changeset
   344
    }
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   345
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   346
    // MODERATION
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   347
    this.changeModeration(comment) ;
103
61fd17f9ab78 enh: detached comments
rbernard
parents: 11
diff changeset
   348
/* useless : use implemendted permanentlink instead
61fd17f9ab78 enh: detached comments
rbernard
parents: 11
diff changeset
   349
 * 
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   350
    // also change link title to give users the possibility to know comment id (to be able to reference this exact comment in GET arguments) 
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   351
    var moderationLnk = this.overlay.get('contentBox').query(".c-moderate") ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   352
    //var cid = (comment.reply_to_id == null) ? this.commentId : "" ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   353
    moderationLnk.set("title", "click to change comment ID visibility".replace(/ID/, this.commentId).replace(/  /, " ")) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   354
    
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   355
 */   
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   356
    // open links in new window :
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   357
    var links = boundingBoxNode.queryAll(".c-content a") ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   358
    if (links != null)
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   359
      links.setAttribute( "target" , "_blank" ) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   360
    links = boundingBoxNode.queryAll(".c-header-title a") ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   361
    if (links != null)
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   362
      links.setAttribute( "target" , "_blank" ) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   363
    
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   364
    this.permAdapt(comment) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   365
  },
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   366
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   367
  permAdapt : function(comment) {
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   368
    // this comment permissions 
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   369
    var delLnk = this.overlay.get('contentBox').query(".c-delete") ; 
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   370
    if (delLnk) { // there will be a server side check anyway
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   371
      if (!comment.can_delete)
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   372
        delLnk.addClass('displaynone') ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   373
      else 
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   374
        delLnk.removeClass('displaynone') ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   375
    }
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   376
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   377
    var editLnk = this.overlay.get('contentBox').query(".c-edit") ; 
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   378
    if (editLnk) {  
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   379
      if (!comment.can_edit) 
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   380
        editLnk.addClass('displaynone') ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   381
      else 
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   382
        editLnk.removeClass('displaynone') ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   383
    }
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   384
    
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   385
    var replyLnk = this.overlay.get('contentBox').query(".c-reply") ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   386
    if (replyLnk) {
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   387
      if (!hasPerm("can_create_comment"))
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   388
        replyLnk.addClass('displaynone') ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   389
      else 
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   390
        replyLnk.removeClass('displaynone') ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   391
    }
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   392
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   393
    var moderateLnk = this.overlay.get('contentBox').query(".c-moderate") ; 
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   394
    if (moderateLnk) {  
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   395
      if (!comment.can_moderate)  
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   396
        moderateLnk.addClass('displaynone') ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   397
      else 
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   398
        moderateLnk.removeClass('displaynone') ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   399
    }
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   400
  },
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   401
  setThreadPad : function(pad) { // TODO review ...
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   402
    this.overlay.get('contentBox').query('.yui-widget-hd').setStyle('paddingLeft', pad + 'px') ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   403
    this.overlay.get('contentBox').query('.yui-widget-bd').setStyle('paddingLeft', pad + 'px') ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   404
    
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   405
  },
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   406
  setPosition : function(xy) {
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   407
    var boundingBoxNode = this.overlay.get('boundingBox') ;
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   408
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   409
      boundingBoxNode.setStyle("opacity", 1); // TODO check this is still usefull
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   410
      boundingBoxNode.setXY(xy) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   411
  },
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   412
  getPosition : function(xy) {
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   413
    var boundingBoxNode = this.overlay.get('boundingBox') ;
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   414
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   415
      return boundingBoxNode.getXY() ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   416
  },
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   417
  onAnimationEnd : function() {
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   418
    if (!CY.Lang.isUndefined(this['animation-handle']) && !CY.Lang.isNull(this['animation-handle'])) { 
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   419
      this['animation-handle'].detach() ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   420
      this['animation-handle'] = null ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   421
//      CY.log('detached...') ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   422
    }
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   423
    gIComments.signalAnimationEnd() ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   424
    if (gIComments.animationsEnded())
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   425
      gIComments.whenAnimationsEnd() ;    
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   426
  },
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   427
  onAnimationEndFocus : function() {
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   428
    if (!CY.Lang.isUndefined(this['animation-handle']) && !CY.Lang.isNull(this['animation-handle'])) { 
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   429
      this['animation-handle'].detach() ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   430
      this['animation-handle'] = null ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   431
//      CY.log('detached...') ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   432
    }
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   433
    gIComments.signalAnimationEnd() ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   434
    if (gIComments.animationsEnded())
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   435
      gIComments.whenAnimationsEndFocus() ;   
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   436
  },
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   437
  onAnimationEndReply : function() {
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   438
    if (!CY.Lang.isUndefined(this['animation-handle']) && !CY.Lang.isNull(this['animation-handle'])) { 
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   439
      this['animation-handle'].detach() ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   440
      this['animation-handle'] = null ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   441
//      CY.log('detached...') ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   442
    }
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   443
    gIComments.signalAnimationEnd() ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   444
    if (gIComments.animationsEnded())
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   445
      gIComments.whenAnimationsEndReply() ;   
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   446
  },
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   447
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   448
  //aa = new CY.Anim({node:gIComments._c[0].overlay.get('boundingBox'), to:{xy : [0,0]}, duration:2.0})
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   449
  setAnimationToPosition : function(toXY, focus, reply) {
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   450
    var boundingBoxNode = this.overlay.get('boundingBox') ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   451
    
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   452
    // ANIMATION
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   453
      // 2 lines of optim that could be removed (0.011)
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   454
    if (gPrefs.get('general','animduration') < 0.011) 
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   455
        boundingBoxNode.setXY(toXY) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   456
    
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   457
    this.animation.set('to', { xy: toXY});
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   458
    this.animation.set('duration', gPrefs.get('general','animduration')) ; // shouldn't be here really ...
329
00df963f91fb When comment_id_key is passed as URL parameter, focus on this comment, instead of the top comment of the related thread.
gibus
parents: 294
diff changeset
   459
    if (focus)
337
614669e0e313 Add url parameter (comment_op=reply) to open automatically reply to comment form
gibus
parents: 330
diff changeset
   460
      if (reply)
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   461
        this['animation-handle'] = this.animation.on('end', this.onAnimationEndReply, this);
337
614669e0e313 Add url parameter (comment_op=reply) to open automatically reply to comment form
gibus
parents: 330
diff changeset
   462
      else
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   463
        this['animation-handle'] = this.animation.on('end', this.onAnimationEndFocus, this);
330
db7616686c57 oops forgot "else" on last commit
gibus
parents: 329
diff changeset
   464
    else
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   465
      this['animation-handle'] = this.animation.on('end', this.onAnimationEnd, this);
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   466
    
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   467
    return this.animation ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   468
  },
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   469
  getHeight : function() {
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   470
    return this.overlay.get('boundingBox').get('offsetHeight') ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   471
  },
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   472
  scrollIntoView : function() {
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   473
    //this.isVisible() && 
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   474
    if (!this.overlay.get('contentBox').inViewportRegion())
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   475
      this.overlay.get('contentBox').scrollIntoView(true) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   476
  },
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   477
  _isHostingAForm : function() {
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   478
    return (this.isVisible() && ((gNewReplyHost != null && gNewReplyHost == this) || (gEditICommentHost != null && gEditICommentHost == this)));
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   479
  }
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   480
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   481
}