src/cm/media/js/client/c_sync.js
author Yves-Marie Haussonne <ymh.work+github@gmail.com>
Fri, 09 May 2014 18:35:26 +0200
changeset 656 a84519031134
parent 600 fda73ac53450
permissions -rw-r--r--
add link to "privacy policy" in the header test
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
     1
gShowingAllComments = false ;
466
f00e34a4476b indexOf method of Array is unknown by stupid IE.
gibus
parents: 432
diff changeset
     2
// indexOf method of Array is unknown by stupid IE.
f00e34a4476b indexOf method of Array is unknown by stupid IE.
gibus
parents: 432
diff changeset
     3
if (!Array.prototype.indexOf) {
f00e34a4476b indexOf method of Array is unknown by stupid IE.
gibus
parents: 432
diff changeset
     4
  Array.prototype.indexOf = function(obj, start) {
f00e34a4476b indexOf method of Array is unknown by stupid IE.
gibus
parents: 432
diff changeset
     5
    for (var i = (start || 0), j = this.length; i < j; i++) {
f00e34a4476b indexOf method of Array is unknown by stupid IE.
gibus
parents: 432
diff changeset
     6
      if (this[i] === obj) { return i; }
f00e34a4476b indexOf method of Array is unknown by stupid IE.
gibus
parents: 432
diff changeset
     7
    }
f00e34a4476b indexOf method of Array is unknown by stupid IE.
gibus
parents: 432
diff changeset
     8
    return -1;
f00e34a4476b indexOf method of Array is unknown by stupid IE.
gibus
parents: 432
diff changeset
     9
  }
f00e34a4476b indexOf method of Array is unknown by stupid IE.
gibus
parents: 432
diff changeset
    10
}
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    11
// YUI : queue, overlay
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    12
Sync = function() {
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
    13
  // this queue handles both animations and io requests
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
    14
  this._q = null ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
    15
  
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
    16
  this._iPreventClick = false ; // oh really ?
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    17
}
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    18
558
5ba711a2bd06 Add comments, fix missing compressed js
Simon Descarpentries <sid@sopinspace.com>
parents: 556
diff changeset
    19
// SID: Are we on Safari mobile ?
556
69503659fe8f [c_selection.js] If safari_mobile, get current selection from a previously created global variable
Simon Descarpentries <sid@sopinspace.com>
parents: 553
diff changeset
    20
// made global to be used in templates/site/text_view_comments.html
69503659fe8f [c_selection.js] If safari_mobile, get current selection from a previously created global variable
Simon Descarpentries <sid@sopinspace.com>
parents: 553
diff changeset
    21
// and in media/js/site/c_text_view_comments.js
69503659fe8f [c_selection.js] If safari_mobile, get current selection from a previously created global variable
Simon Descarpentries <sid@sopinspace.com>
parents: 553
diff changeset
    22
safari_mobile = /iPhone|iPod|iPad/.test(navigator.userAgent);
553
bf26fb47a14c To allow scrolling in Safari mobile, we set the content of text_view_comments frame in a jQuery UI layout.
Simon Descarpentries <sid@sopinspace.com>
parents: 532
diff changeset
    23
// If so, we must scroll the jQuery UI pane created for Safari mobile instead of the whole document
bf26fb47a14c To allow scrolling in Safari mobile, we set the content of text_view_comments frame in a jQuery UI layout.
Simon Descarpentries <sid@sopinspace.com>
parents: 532
diff changeset
    24
var the_scrolling_part = safari_mobile ? '#maincontainer' : 'document' ;
bf26fb47a14c To allow scrolling in Safari mobile, we set the content of text_view_comments frame in a jQuery UI layout.
Simon Descarpentries <sid@sopinspace.com>
parents: 532
diff changeset
    25
bf26fb47a14c To allow scrolling in Safari mobile, we set the content of text_view_comments frame in a jQuery UI layout.
Simon Descarpentries <sid@sopinspace.com>
parents: 532
diff changeset
    26
// "Add comment" height and margin, to offset comments' display
bf26fb47a14c To allow scrolling in Safari mobile, we set the content of text_view_comments frame in a jQuery UI layout.
Simon Descarpentries <sid@sopinspace.com>
parents: 532
diff changeset
    27
var add_comment_offset = 30; // px
bf26fb47a14c To allow scrolling in Safari mobile, we set the content of text_view_comments frame in a jQuery UI layout.
Simon Descarpentries <sid@sopinspace.com>
parents: 532
diff changeset
    28
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    29
Sync.prototype = {
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
    30
  init : function (iComment) {
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
    31
  this._q = new CY.AsyncQueue() ;
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    32
// pr2 this._q = new CY.Queue() ;
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
    33
  },
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
    34
  
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
    35
  setPreventClickOn : function () {
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
    36
    CY.log("setPreventClickOn !") ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
    37
    if (gLayout.isInFrame())
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
    38
      parent.f_interfaceFreeze()    
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
    39
    this._iPreventClick = true ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
    40
  },
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    41
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
    42
  setPreventClickOff : function () {
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
    43
    CY.log("setPreventClickOff !") ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
    44
    if (gLayout.isInFrame())
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
    45
      parent.f_interfaceUnfreeze()    
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
    46
    this._iPreventClick = false ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
    47
  },
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    48
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
    49
  removeCommentRet : function(args) {
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
    50
    var successfull = args['successfull'] ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
    51
    
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
    52
    var iComment = (successfull) ? args['failure']['iComment'] : args['success']['iComment'] ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
    53
    
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
    54
    if (successfull) {
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
    55
      var filterData = args['returned']['filterData'] ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
    56
      if (gLayout.isInFrame()) {
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
    57
        parent.f_updateFilterData(filterData) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
    58
      }
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
    59
      
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
    60
      var y = gIComments.getTopPosition()[1] ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
    61
      
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
    62
      var comment = gDb.getComment(iComment.commentId) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
    63
      this._q.add(
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
    64
                function(){
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
                unpaintCommentScope(comment) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
    67
                gIComments.close(comment.id) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
    68
                gIComments.remove(comment.id) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
    69
                if (comment.reply_to_id != null)
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
    70
                  gIComments.refresh(comment.reply_to_id) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
    71
                
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
    72
                gDb.del(comment) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
    73
                
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
    74
                if (gLayout.isInFrame()) {
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
    75
                  if (gDb.comments.length == 0 && gDb.allComments.length != 0) {
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
    76
                    parent.f_enqueueMsg(gettext("no filtered comments left")) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
    77
                  parent.resetFilter() ;  
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
    78
                  }
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
    79
                  else {
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
    80
                  // just counting here ...
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
    81
                  var filterRes = gDb.computeFilterResults() ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
    82
                  updateFilterResultsCount(filterRes['nbDiscussions'], filterRes['nbComments'], filterRes['nbReplies']) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
    83
                  }
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
    84
                }
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
    85
                }
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
    86
      );
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
    87
      
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
    88
      this._animateTo(y) ;    
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
    89
    }
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
    90
    this._q.add({fn:CY.bind(this.setPreventClickOff, this)}) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
    91
    this.resume() ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
    92
  },
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
    93
  
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
    94
  moderateCommentRet : function(args) {
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
    95
    var successfull = args['successfull'] ;
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    96
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
    97
    var iComment = (successfull) ? args['failure']['iComment'] : args['success']['iComment'] ;
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    98
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
    99
    if (successfull) {
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   100
      var ret = args['returned'] ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   101
      var comment = ret['comment'] ;
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   102
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   103
      gDb.upd(comment) ;
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
      var shouldReset = gLayout.isInFrame() && !parent.f_isFrameFilterFieldsInit() ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   106
      if (shouldReset){
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   107
        parent.resetFilter() ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   108
        this._showSingleComment(comment) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   109
      }
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   110
      else 
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   111
        iComment.changeModeration(comment) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   112
    }
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   113
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   114
    this._q.add({fn:CY.bind(this.setPreventClickOff, this)}) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   115
    this.resume() ;
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
  saveCommentRet : function(args) {
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   119
    var successfull = args['successfull'] ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   120
    if (successfull) {
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   121
      var formId = args['success']['formId'] ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   122
      var ret = args['returned'] ;
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
      removeFormErrMsg(formId) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   125
    
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   126
      if ('errors' in ret) { // validation error
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   127
        var errors = ret['errors'] ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   128
        for (var eltName in errors) {
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   129
          addFormErrMsg(formId, eltName, errors[eltName]) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   130
        }
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   131
        this._animateToTop() ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   132
      }
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   133
      else {
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   134
        var isReply = function() {return (gNewReply != null) && (formId == gNewReply['ids']['formId']) ;} ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   135
        var isNewComment = function() {return (gICommentForm != null) && (formId == gICommentForm['formId']) ;} ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   136
        var isEdit = function() {return (gEdit != null) && (formId == gEdit['ids']['formId']) ;} ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   137
        
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   138
        // doing this here for the a priori moderation case
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   139
        if (isNewComment())
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   140
          this.hideICommentForm(cleanICommentForm()) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   141
        else if (isEdit())
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   142
          this._hideEditForm() ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   143
        else if (isReply())
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   144
          this._hideNewReplyForm() ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   145
        
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   146
        if ("ask_for_notification" in ret) {  
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   147
          if (ret['ask_for_notification']) {
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   148
            // TODO ask for notification ...or use AUTO_CONTRIB ?
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   149
            parent.f_yesNoDialog(gettext("Do you want to be notified of all replies in all discussions you participated in?"), gettext("Reply notification"), 
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   150
              function() { // special case : no waiting for the return, no error check, nothing !
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   151
                  var cfg = {
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   152
                  method: "POST", 
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   153
                  data: urlEncode({'fun':'ownNotify', 'key':sv_key, 'version_key':sv_version_key, 'email':ret['email'], 'active':false}) 
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   154
                } ; 
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   155
                CY.io(sv_client_url, cfg);
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   156
              }, this, null,
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   157
              function() { // special case : no waiting for the return, no error check, nothing !
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   158
                  var cfg = {
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   159
                  method: "POST", 
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   160
                  data: urlEncode({'fun':'ownNotify', 'key':sv_key, 'version_key':sv_version_key, 'email':ret['email'], 'active':true}) 
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   161
                } ; 
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   162
                CY.io(sv_client_url, cfg);
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   163
              }, this, null) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   164
          }
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   165
        }
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   166
          
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   167
        
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   168
        if ("comment" in ret) { // won't be when add with a priori moderation
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   169
          var comment = ret['comment'] ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   170
  
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   171
          gDb.upd(comment) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   172
  
490
57c1ba71f642 Do not reset filters when adding a comment.
Production Moz <dev@sopinspace.com>
parents: 466
diff changeset
   173
          var shouldReset = gLayout.isInFrame() && parent.f_isFrameFilterFieldsInit() ;
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   174
          if (shouldReset)
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   175
            parent.resetFilter() ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   176
          else { // ASSUMING filter is in init state ! (because when not // TODO $$$$$$$$$$$ this isn't true anymore .... when passing filter arguments in url !!
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   177
              // in frame for now data can't be filtered)
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   178
            if (comment.reply_to_id == null) { // not a reply
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   179
              unpaintCommentScope(comment) ; // for the edit case
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   180
              paintCommentScope(comment) ;
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
          }
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   183
  
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   184
          // UPDATE FILTER DATA // TODO move ????
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   185
          var filterData = ret['filterData'] ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   186
          if (gLayout.isInFrame()) {
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   187
            parent.f_updateFilterData(filterData) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   188
            updateResetFilterResultsCount() ;       
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   189
          }
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   190
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   191
          if (isReply()) { // add reply case
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   192
            if (!shouldReset) {
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   193
              this._insertReply(comment) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   194
            }
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   195
          }
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   196
          else { // edit (reply or comment) or add (comment) case
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   197
              this._showSingleComment(comment) ;
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
        else 
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   201
          this._animateToTop() ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   202
      }
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   203
341
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
    else { // TODO ? ALL ret-FUNCTIONS ?
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   206
      this._q.add({id:"expl", fn:function () {CY.log('in example .........') ;}}) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   207
      this._q.promote("expl") ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   208
    }
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   209
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   210
    this._q.add({fn:CY.bind(this.setPreventClickOff, this)}) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   211
    this.resume() ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   212
  },
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   213
  
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   214
  example : function () {
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   215
    CY.log('in example .........') ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   216
  },
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   217
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   218
  moderateComment : function(iComment, state) {
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   219
    var comment = gDb.getComment(iComment['commentId']) ;
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   220
        this._q.add(
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   221
              {fn:CY.bind(this.setPreventClickOn, this)},
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   222
              {autoContinue:false, fn:CY.bind(doExchange, null, "editComment", {'comment_key':comment.key, 'state':state}, null, this.moderateCommentRet, this, {'iComment':iComment}, gettext("could not save comment"))}
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   223
              ).run();
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   224
  },
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   225
  
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   226
  _saveComment : function(serverFun, formId) {
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   227
        this._q.add(
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   228
              {fn:CY.bind(this.setPreventClickOn, this)},
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   229
              {autoContinue:false, fn:CY.bind(doExchange, null, serverFun, {}, formId, this.saveCommentRet, this, {'formId':formId}, gettext("could not save comment"))}
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   230
              ).run();
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   231
  },
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   232
  
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   233
  editComment : function() {
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   234
    this._saveComment("editComment", gEdit['ids']['formId']) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   235
  },
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   236
  
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   237
  saveComment : function(formId) {
501
5cd02f32be5e Prevents sumitting comment several time while waiting for server response.
gibus
parents: 492
diff changeset
   238
    if (readyForAction())
5cd02f32be5e Prevents sumitting comment several time while waiting for server response.
gibus
parents: 492
diff changeset
   239
      this._saveComment("addComment", formId) ;
341
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
  
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   242
  removeComment : function(iComment) {
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   243
    checkForOpenedDialog(iComment, function() {
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   244
      if (gLayout.isInFrame()) {
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   245
        parent.f_yesNoDialog(gettext("Are you sure you want to delete this comment?"), gettext("Warning"), function() { this.animateToTop() ;}, this, null, function() {
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   246
          var comment = gDb.getComment(iComment.commentId) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   247
              this._q.add(
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   248
                    {fn:CY.bind(this.setPreventClickOn, this)},
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   249
                    {autoContinue:false, fn:CY.bind(doExchange, null, "removeComment", {'comment_key':comment.key}, null, this.removeCommentRet, this, {'iComment':iComment}, gettext("could not remove comment"))}
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   250
                    ).run();
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   251
        }, this, null) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   252
            
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   253
      }
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   254
//      else {
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   255
//        alert("TODO : can't yet delete comments when not embed in text_view_frame because can't 'dialog' confirmation") ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   256
//      }
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   257
    
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   258
    }, this, null) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   259
  },
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   260
  
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   261
  resume : function(commentDbIds, mouseXY) {
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   262
    this._q.run() ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   263
  },
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   264
  
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   265
  resetAutoContinue : function(callbackId) {
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   266
    this._q.getCallback(callbackId).autoContinue = true;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   267
  },
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   268
  
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   269
  hideICommentForm : function(funObj) {
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   270
//    this._q.add({fn:function() {persistICommentFormValues();}}) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   271
    this._q.add({autoContinue:false, fn:CY.bind(gICommentForm['animationHide'].run, gICommentForm['animationHide'])}) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   272
//    this._q.add({fn:function() {cleanICommentForm();}}) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   273
    if (funObj)
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   274
      this._q.add(funObj) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   275
  },
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
  /* ANIMATION DRIVEN INTERFACE CHANGES */
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   278
  
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   279
  showCommentForm : function(iComment) {
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   280
    checkForOpenedDialog(null, function() {
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   281
          this._q.add({fn:CY.bind(this.setPreventClickOn, this)});
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   282
      this._q.add({fn:function() {
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   283
                if (iComment == null) {
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   284
                  var selection = getSelectionInfo() ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   285
                  updateICommentFormSelection(selection) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   286
                }
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   287
                showICommentForm(iComment);
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   288
              }}) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   289
      this._q.add({autoContinue:false, fn:CY.bind(gICommentForm['animationShow'].run, gICommentForm['animationShow'])},
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   290
          {fn:CY.bind(this.setPreventClickOff, this)}
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   291
          ).run();
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   292
    }, this, null) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   293
  },
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   294
  
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   295
  showEditForm : function(iComment) {
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   296
    checkForOpenedDialog(null, function() {
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   297
          this._q.add({fn:CY.bind(this.setPreventClickOn, this)});
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   298
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   299
          this._q.add({fn:function() {
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   300
                  showEditForm(iComment) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   301
                }});
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   302
      this._animateToTop() ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   303
      
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   304
          this._q.add({fn:CY.bind(this.setPreventClickOff, this)});
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   305
          this._q.run() ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   306
    }, this, null) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   307
  },
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
  showReplyForm : function(iComment) {
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   310
    checkForOpenedDialog(null, function() {
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   311
          this._q.add({fn:CY.bind(this.setPreventClickOn, this)});
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   312
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   313
          this._q.add({fn:function() {
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   314
                    instanciateNewReplyForm(iComment) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   315
                    }});
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   316
      this._animateToTop() ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   317
      
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   318
          this._q.add({fn:CY.bind(this.setPreventClickOff, this)});
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   319
          this._q.run() ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   320
    }, this, null) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   321
  },
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   322
  
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   323
  cancelICommentForm : function() {
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   324
        this._q.add({fn:CY.bind(this.setPreventClickOn, this)});
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   325
        
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   326
//    this._q.add({fn:function() {cleanICommentForm();}}) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   327
      this.hideICommentForm() ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   328
      
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   329
        this._q.add({fn:CY.bind(this.setPreventClickOff, this)});
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   330
        this._q.run() ;
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   331
  },
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   332
  cancelEdit : function() {
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   333
        this._q.add({fn:CY.bind(this.setPreventClickOn, this)});
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   334
        
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   335
      this._q.add({fn:function() {cancelEditForm();}}) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   336
      this._animateToTop() ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   337
      
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   338
        this._q.add({fn:CY.bind(this.setPreventClickOff, this)});
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   339
        this._q.run() ;
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   340
  },
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   341
  cancelReply : function() {
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   342
        this._q.add({fn:CY.bind(this.setPreventClickOn, this)});
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   343
        
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   344
      this._q.add({fn:function() {cancelNewReplyForm();}}) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   345
      this._animateToTop() ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   346
      
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   347
        this._q.add({fn:CY.bind(this.setPreventClickOff, this)});
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   348
        this._q.run() ;
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   349
  },
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   350
  changeScopeFormClick : function() {
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   351
        this._q.add({fn:CY.bind(this.setPreventClickOn, this)});
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   352
        
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   353
      this._q.add({fn:function() {changeScopeFormClick();}}) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   354
      this._animateToTop() ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   355
      
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   356
        this._q.add({fn:CY.bind(this.setPreventClickOff, this)});
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   357
        this._q.run() ;
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   358
  },
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   359
  // this is invoked during queue execution
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   360
  _hideNewReplyForm : function() {
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   361
    this._q.add({fn:function() {
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   362
          cleanNewReplyForm() ; 
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   363
          cancelNewReplyForm() ;}}) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   364
  },
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   365
  // this is invoked during queue execution
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   366
  _hideEditForm : function() {
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   367
    this._q.add({fn:function() {
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   368
          cancelEditForm() ;}}) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   369
  },
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   370
  // this is invoked during queue execution
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   371
  _insertReply : function(comment) {
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   372
    this._q.add({fn:function() {
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   373
          var parentComment = gDb.getComment(comment.reply_to_id) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   374
          var parentThread = gDb.getThreads([parentComment]) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   375
          var previousComment = parentThread[parentThread.length - 2] ; // - 2 because now that comment has been added comment is parentThread[parentThread.length - 1]
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 iComment = gIComments.insertAfter(previousComment, comment) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   378
          // iComment CAN'T BE NULL ! (TODO check that there is a
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   379
          // check server side that parent exists when adding a reply
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   380
          // !)
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   381
          
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   382
          var parentPosition = gIComments.getPosition(comment.reply_to_id) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   383
          iComment.setPosition(parentPosition) ;
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
          // check if activation is necessary (will always be ?)
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   386
          var comment_path = gDb.getPath(comment) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   387
          var topComment = comment_path[comment_path.length - 1] ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   388
          if (gIComments.isTopActive(topComment.id))
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   389
            iComment.activate() ;
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   390
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   391
          iComment.show() ;}}) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   392
      this._animateToTop() ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   393
  },
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   394
  _showSingleComment : function(comment) {
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   395
    if (comment != null) {
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   396
      var path = gDb.getPath(comment) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   397
      var topAncestorComment = path[path.length - 1] ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   398
      var topY = 0 ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   399
      if (comment['start_wrapper'] != -1) 
600
fda73ac53450 Use YUI 3.10 (now that conflict with ASCIIMathML is solved).
gibus
parents: 558
diff changeset
   400
        topY = CY.one(".c-id-"+topAncestorComment.id).getY() ;
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   401
      else 
600
fda73ac53450 Use YUI 3.10 (now that conflict with ASCIIMathML is solved).
gibus
parents: 558
diff changeset
   402
        topY = CY.one(the_scrolling_part).get('scrollTop') ;
553
bf26fb47a14c To allow scrolling in Safari mobile, we set the content of text_view_comments frame in a jQuery UI layout.
Simon Descarpentries <sid@sopinspace.com>
parents: 532
diff changeset
   403
     
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   404
      this._showComments([topAncestorComment.id], topY, false) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   405
      // optim when browsing comments with no reply     
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   406
      if (topAncestorComment.replies.length > 0)
553
bf26fb47a14c To allow scrolling in Safari mobile, we set the content of text_view_comments frame in a jQuery UI layout.
Simon Descarpentries <sid@sopinspace.com>
parents: 532
diff changeset
   407
	    // SID: let topY param be null to force Y acquisition from comment that
bf26fb47a14c To allow scrolling in Safari mobile, we set the content of text_view_comments frame in a jQuery UI layout.
Simon Descarpentries <sid@sopinspace.com>
parents: 532
diff changeset
   408
	    // may have previously been set by showComments
bf26fb47a14c To allow scrolling in Safari mobile, we set the content of text_view_comments frame in a jQuery UI layout.
Simon Descarpentries <sid@sopinspace.com>
parents: 532
diff changeset
   409
        this._animateTo() ;
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   410
    }
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
  _showFocusSingleComment : function(topComment, focusComment, reply) {
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   413
    if (topComment != null) {
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   414
      var topY = 0 ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   415
      if (topComment['start_wrapper'] != -1) 
600
fda73ac53450 Use YUI 3.10 (now that conflict with ASCIIMathML is solved).
gibus
parents: 558
diff changeset
   416
        topY = CY.one(".c-id-"+topComment.id).getY() ;
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   417
      else 
600
fda73ac53450 Use YUI 3.10 (now that conflict with ASCIIMathML is solved).
gibus
parents: 558
diff changeset
   418
        topY = CY.one(the_scrolling_part).get('scrollTop') ;
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   419
      
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   420
      this._showComments([topComment.id], topY, false) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   421
      // optim when browsing comments with no reply     
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   422
      if (topComment.replies.length > 0 || reply)
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   423
        this._animateToAndFocus(topY, focusComment.id, reply) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   424
    }
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   425
  },
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   426
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   427
  showSingleComment : function(comment) {
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   428
    this._q.add({fn:CY.bind(this.setPreventClickOn, this)}) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   429
    this._showSingleComment(comment) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   430
    this._q.add({fn:CY.bind(this.setPreventClickOff, this)}) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   431
    this._q.run();
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
  
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   434
  showFocusSingleComment : function(topComment, focusComment, reply) {
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   435
    this._q.add({fn:CY.bind(this.setPreventClickOn, this)}) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   436
    this._showFocusSingleComment(topComment, focusComment, reply) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   437
    this._q.add({fn:CY.bind(this.setPreventClickOff, this)}) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   438
    this._q.run();
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   439
  },
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   440
  
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   441
  browse : function(order, whereto) { 
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   442
    var comment = gIComments.browse(order, whereto) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   443
    if (comment != null) 
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   444
      this.showSingleComment(comment) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   445
  },
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   446
  
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   447
  _showComments : function(commentDbIds, topY, atDocumentTop) {
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   448
    this._q.add(
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   449
      {fn:function() {
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   450
        gShowingAllComments = atDocumentTop ;     
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   451
        gIComments.hide() ; 
421
3ddbfa64f596 Adds a table of content.
gibus
parents: 375
diff changeset
   452
        hideToc();
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   453
        var cs = CY.Array.map(commentDbIds, function(id) { return gDb.getComment(id) ; }) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   454
        var comments = gDb.getThreads(cs) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   455
        gIComments.fetch(comments) ;
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
        if (commentDbIds.length > 0) {
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   458
          if (atDocumentTop) {
600
fda73ac53450 Use YUI 3.10 (now that conflict with ASCIIMathML is solved).
gibus
parents: 558
diff changeset
   459
            CY.one(the_scrolling_part).set('scrollTop', 0) ; 
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   460
          }
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   461
          else {
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   462
            gIComments.activate(commentDbIds[0]) ;
600
fda73ac53450 Use YUI 3.10 (now that conflict with ASCIIMathML is solved).
gibus
parents: 558
diff changeset
   463
            var scopeStart = CY.one(".c-id-"+commentDbIds[0]) ;
553
bf26fb47a14c To allow scrolling in Safari mobile, we set the content of text_view_comments frame in a jQuery UI layout.
Simon Descarpentries <sid@sopinspace.com>
parents: 532
diff changeset
   464
bf26fb47a14c To allow scrolling in Safari mobile, we set the content of text_view_comments frame in a jQuery UI layout.
Simon Descarpentries <sid@sopinspace.com>
parents: 532
diff changeset
   465
			// scopeStart could be null when comment has no scope
bf26fb47a14c To allow scrolling in Safari mobile, we set the content of text_view_comments frame in a jQuery UI layout.
Simon Descarpentries <sid@sopinspace.com>
parents: 532
diff changeset
   466
			if (scopeStart && !scopeStart.inViewportRegion()) {
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   467
              scopeStart.scrollIntoView(true) ;
553
bf26fb47a14c To allow scrolling in Safari mobile, we set the content of text_view_comments frame in a jQuery UI layout.
Simon Descarpentries <sid@sopinspace.com>
parents: 532
diff changeset
   468
491
50eeeb10e960 Since scrollIntoView scroll the embed iframe *and* the parent window, save and restore the position of the toolbar.
Production Moz <dev@sopinspace.com>
parents: 490
diff changeset
   469
              // Since scrollIntoView scroll the embed ifram *and* the parent window
50eeeb10e960 Since scrollIntoView scroll the embed iframe *and* the parent window, save and restore the position of the toolbar.
Production Moz <dev@sopinspace.com>
parents: 490
diff changeset
   470
              // restore the position of the toolbar
492
5b5245f4fe9a Since scrollIntoView scroll the embed iframe *and* the parent window, restore the position of the toolbar.
Production Moz <dev@sopinspace.com>
parents: 491
diff changeset
   471
              if (parent)
5b5245f4fe9a Since scrollIntoView scroll the embed iframe *and* the parent window, restore the position of the toolbar.
Production Moz <dev@sopinspace.com>
parents: 491
diff changeset
   472
                parent.document.getElementById('outer-north').scrollIntoView(true) ;
553
bf26fb47a14c To allow scrolling in Safari mobile, we set the content of text_view_comments frame in a jQuery UI layout.
Simon Descarpentries <sid@sopinspace.com>
parents: 532
diff changeset
   473
bf26fb47a14c To allow scrolling in Safari mobile, we set the content of text_view_comments frame in a jQuery UI layout.
Simon Descarpentries <sid@sopinspace.com>
parents: 532
diff changeset
   474
			  // SID: As we scroll via jQuery UI pane while on Safari mobile, we should base comment
bf26fb47a14c To allow scrolling in Safari mobile, we set the content of text_view_comments frame in a jQuery UI layout.
Simon Descarpentries <sid@sopinspace.com>
parents: 532
diff changeset
   475
			  // position on the result of previous scrollIntoView on the pane, so relatively to that
bf26fb47a14c To allow scrolling in Safari mobile, we set the content of text_view_comments frame in a jQuery UI layout.
Simon Descarpentries <sid@sopinspace.com>
parents: 532
diff changeset
   476
			  // new top.
bf26fb47a14c To allow scrolling in Safari mobile, we set the content of text_view_comments frame in a jQuery UI layout.
Simon Descarpentries <sid@sopinspace.com>
parents: 532
diff changeset
   477
			  // On other cases, it's the right place to add an offset on comment tops in order to
bf26fb47a14c To allow scrolling in Safari mobile, we set the content of text_view_comments frame in a jQuery UI layout.
Simon Descarpentries <sid@sopinspace.com>
parents: 532
diff changeset
   478
			  // avoid them to display under the "Add comment" button.
bf26fb47a14c To allow scrolling in Safari mobile, we set the content of text_view_comments frame in a jQuery UI layout.
Simon Descarpentries <sid@sopinspace.com>
parents: 532
diff changeset
   479
			  if (safari_mobile)
bf26fb47a14c To allow scrolling in Safari mobile, we set the content of text_view_comments frame in a jQuery UI layout.
Simon Descarpentries <sid@sopinspace.com>
parents: 532
diff changeset
   480
				  topY = add_comment_offset;
bf26fb47a14c To allow scrolling in Safari mobile, we set the content of text_view_comments frame in a jQuery UI layout.
Simon Descarpentries <sid@sopinspace.com>
parents: 532
diff changeset
   481
			  else
bf26fb47a14c To allow scrolling in Safari mobile, we set the content of text_view_comments frame in a jQuery UI layout.
Simon Descarpentries <sid@sopinspace.com>
parents: 532
diff changeset
   482
				  topY += add_comment_offset;
491
50eeeb10e960 Since scrollIntoView scroll the embed iframe *and* the parent window, save and restore the position of the toolbar.
Production Moz <dev@sopinspace.com>
parents: 490
diff changeset
   483
            }
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   484
          }
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   485
        }
553
bf26fb47a14c To allow scrolling in Safari mobile, we set the content of text_view_comments frame in a jQuery UI layout.
Simon Descarpentries <sid@sopinspace.com>
parents: 532
diff changeset
   486
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   487
        gIComments.setPosition([gConf['iCommentLeftPadding'], topY]) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   488
        gIComments.show() ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   489
      }}) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   490
  },
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   491
  
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   492
  _animateTo : function(topY) {
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   493
    this._q.add({fn:function() {
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   494
            gIComments.setAnimationToPositions(topY) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   495
            }},
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   496
          {id:"animationRun", autoContinue:false, fn:CY.bind(gIComments.runAnimations, gIComments)}
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   497
              ) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   498
  },
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   499
  
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   500
  _animateToAndFocus : function(topY, focusCommentId, reply) {
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   501
    this._q.add({fn:function() {
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   502
            gIComments.setAnimationToPositionsAndFocus(topY, focusCommentId, reply) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   503
            }},
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   504
          {id:"animationRun", autoContinue:false, fn:CY.bind(gIComments.runAnimations, gIComments)}
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   505
              ) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   506
  },
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   507
  
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   508
  _animateToTop : function() {
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   509
    var topPos = gIComments.getTopPosition() ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   510
    if (topPos != null)
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   511
      this._animateTo(topPos[1]) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   512
  },
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   513
  
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   514
  animateToTop : function() {
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   515
    this._q.add({fn:CY.bind(this.setPreventClickOn, this)}) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   516
    this._animateToTop() ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   517
    this._q.add({fn:CY.bind(this.setPreventClickOff, this)}) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   518
    this._q.run();
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   519
  },
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   520
  
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   521
  showAllComments : function() {
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   522
    checkForOpenedDialog(null, function() {
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   523
      gShowingAllComments = true ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   524
      var allTopComments = CY.Array.map(gDb.comments, function(c){return c.id;}) ;
432
aad07a378d44 Respect order by scope in show all comments or show all detached comments.
gibus
parents: 421
diff changeset
   525
      // Reorder if by scope.
aad07a378d44 Respect order by scope in show all comments or show all detached comments.
gibus
parents: 421
diff changeset
   526
      if (parent.$("#browse_by").val() == 'scope') {
aad07a378d44 Respect order by scope in show all comments or show all detached comments.
gibus
parents: 421
diff changeset
   527
        allTopComments.sort(function (a,b) {
aad07a378d44 Respect order by scope in show all comments or show all detached comments.
gibus
parents: 421
diff changeset
   528
          if (gDb.ordered_comment_ids['scope'].indexOf(a) < gDb.ordered_comment_ids['scope'].indexOf(b))
aad07a378d44 Respect order by scope in show all comments or show all detached comments.
gibus
parents: 421
diff changeset
   529
            return -1;
aad07a378d44 Respect order by scope in show all comments or show all detached comments.
gibus
parents: 421
diff changeset
   530
          if (gDb.ordered_comment_ids['scope'].indexOf(a) > gDb.ordered_comment_ids['scope'].indexOf(b))
aad07a378d44 Respect order by scope in show all comments or show all detached comments.
gibus
parents: 421
diff changeset
   531
            return 1
aad07a378d44 Respect order by scope in show all comments or show all detached comments.
gibus
parents: 421
diff changeset
   532
          return 0
aad07a378d44 Respect order by scope in show all comments or show all detached comments.
gibus
parents: 421
diff changeset
   533
		    });
aad07a378d44 Respect order by scope in show all comments or show all detached comments.
gibus
parents: 421
diff changeset
   534
      }
375
d6439b3eb2de replace 'add comment' button
gibus
parents: 341
diff changeset
   535
      // GIB: go down the 'add comment' icon
553
bf26fb47a14c To allow scrolling in Safari mobile, we set the content of text_view_comments frame in a jQuery UI layout.
Simon Descarpentries <sid@sopinspace.com>
parents: 532
diff changeset
   536
      this.showComments(allTopComments, [0, add_comment_offset], true);
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   537
    }, this, null) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   538
  },
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   539
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   540
  showScopeRemovedComments : function() {
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   541
    checkForOpenedDialog(null, function() {
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   542
      gShowingAllComments = true ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   543
      var scopeRemovedComments = CY.Array.filter(gDb.comments, function(comment) { return (comment.start_wrapper == -1) ; }) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   544
      var scopeRemovedCommentIds = CY.Array.map(scopeRemovedComments, function(c){return c.id;}) ;
432
aad07a378d44 Respect order by scope in show all comments or show all detached comments.
gibus
parents: 421
diff changeset
   545
      // Reorder if by scope.
aad07a378d44 Respect order by scope in show all comments or show all detached comments.
gibus
parents: 421
diff changeset
   546
      if (parent.$("#browse_by").val() == 'scope') {
aad07a378d44 Respect order by scope in show all comments or show all detached comments.
gibus
parents: 421
diff changeset
   547
        scopeRemovedCommentIds.sort(function (a,b) {
aad07a378d44 Respect order by scope in show all comments or show all detached comments.
gibus
parents: 421
diff changeset
   548
          if (gDb.ordered_comment_ids['scope'].indexOf(a) < gDb.ordered_comment_ids['scope'].indexOf(b))
aad07a378d44 Respect order by scope in show all comments or show all detached comments.
gibus
parents: 421
diff changeset
   549
            return -1;
aad07a378d44 Respect order by scope in show all comments or show all detached comments.
gibus
parents: 421
diff changeset
   550
          if (gDb.ordered_comment_ids['scope'].indexOf(a) > gDb.ordered_comment_ids['scope'].indexOf(b))
aad07a378d44 Respect order by scope in show all comments or show all detached comments.
gibus
parents: 421
diff changeset
   551
            return 1
aad07a378d44 Respect order by scope in show all comments or show all detached comments.
gibus
parents: 421
diff changeset
   552
          return 0
aad07a378d44 Respect order by scope in show all comments or show all detached comments.
gibus
parents: 421
diff changeset
   553
		    });
aad07a378d44 Respect order by scope in show all comments or show all detached comments.
gibus
parents: 421
diff changeset
   554
      }
375
d6439b3eb2de replace 'add comment' button
gibus
parents: 341
diff changeset
   555
      // GIB: go down the 'add comment' icon
553
bf26fb47a14c To allow scrolling in Safari mobile, we set the content of text_view_comments frame in a jQuery UI layout.
Simon Descarpentries <sid@sopinspace.com>
parents: 532
diff changeset
   556
      this.showComments(scopeRemovedCommentIds, [0, add_comment_offset], true);
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   557
      
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   558
    }, this, null) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   559
  },
103
61fd17f9ab78 enh: detached comments
rbernard
parents: 24
diff changeset
   560
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   561
  showComments : function(commentDbIds, mouseXY, atDocumentTop) {
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   562
    checkForOpenedDialog(null, function() {
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   563
      this._q.add({fn:CY.bind(this.setPreventClickOn, this)}) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   564
      this._showComments(commentDbIds, mouseXY[1], atDocumentTop) ;
553
bf26fb47a14c To allow scrolling in Safari mobile, we set the content of text_view_comments frame in a jQuery UI layout.
Simon Descarpentries <sid@sopinspace.com>
parents: 532
diff changeset
   565
	  // SID: let topY param be null to force Y acquisition from comment that
bf26fb47a14c To allow scrolling in Safari mobile, we set the content of text_view_comments frame in a jQuery UI layout.
Simon Descarpentries <sid@sopinspace.com>
parents: 532
diff changeset
   566
	  // may have previously been set by showComments
bf26fb47a14c To allow scrolling in Safari mobile, we set the content of text_view_comments frame in a jQuery UI layout.
Simon Descarpentries <sid@sopinspace.com>
parents: 532
diff changeset
   567
      this._animateTo() ;
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   568
      this._q.add({fn:CY.bind(this.setPreventClickOff, this)}) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   569
      this._q.run();
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   570
    }, this, null) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   571
  },
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   572
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   573
  openComment : function(iComment) { 
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   574
    this._q.add({fn:CY.bind(this.setPreventClickOn, this)}) ;
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   575
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   576
    var y = gIComments.getTopPosition()[1] ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   577
    this._q.add({fn:function() {
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   578
      gIComments.open(iComment.commentId) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   579
        gIComments.refresh(iComment.commentId) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   580
    }}) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   581
    this._animateTo(y) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   582
    
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   583
    this._q.add({fn:CY.bind(this.setPreventClickOff, this)}) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   584
    this._q.run();
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   585
  },
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   586
  
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   587
  closeComment : function(iComment) { 
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   588
    checkForOpenedDialog(iComment, function() {
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   589
      this._q.add({fn:CY.bind(this.setPreventClickOn, this)}) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   590
  
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   591
      var y = gIComments.getTopPosition()[1] ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   592
      this._q.add({fn:function() {
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   593
        var comment = gDb.getComment(iComment.commentId) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   594
        gIComments.close(iComment.commentId) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   595
          if (comment.reply_to_id != null)
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   596
            gIComments.refresh(comment.reply_to_id) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   597
      }}) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   598
      this._animateTo(y) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   599
  
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   600
      this._q.add({fn:CY.bind(this.setPreventClickOff, this)}) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   601
      this._q.run() ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   602
    }, this, null) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   603
  },
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   604
  
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   605
  activate : function(iComment) {
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   606
    gIComments.activate(iComment.commentId) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   607
  }
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   608
}
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   609
      
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   610
readyForAction = function () {
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 339
diff changeset
   611
  return !gSync._iPreventClick ;
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   612
};