src/cm/media/js/client/c_reply_form.js
author gibus
Wed, 11 Sep 2013 23:13:01 +0200
changeset 532 0bad3613f59d
parent 525 89ef5ed3c48b
child 600 fda73ac53450
permissions -rw-r--r--
Reverse to YUI 3.0.0 since with YUI.3.10.3, comment content including words 'paragraph' or 'section' do not show up on Firefox, this is weird and has to be investigated.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
     1
gNewReplyHost = null ;
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
     2
gNewReply = null
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
     3
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
     4
instanciateNewReplyForm = function(iCommentToAppendTo) {
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 338
diff changeset
     5
  
053551f213fb Coding style for js: expand tabs
gibus
parents: 338
diff changeset
     6
  if (gNewReply == null) {
053551f213fb Coding style for js: expand tabs
gibus
parents: 338
diff changeset
     7
    gNewReply = {
053551f213fb Coding style for js: expand tabs
gibus
parents: 338
diff changeset
     8
        'val': {
053551f213fb Coding style for js: expand tabs
gibus
parents: 338
diff changeset
     9
          'name':gPrefs.get('user','name'),
053551f213fb Coding style for js: expand tabs
gibus
parents: 338
diff changeset
    10
          'email':gPrefs.get('user','email'), 
053551f213fb Coding style for js: expand tabs
gibus
parents: 338
diff changeset
    11
          'title':'', 
053551f213fb Coding style for js: expand tabs
gibus
parents: 338
diff changeset
    12
          'content':'',
053551f213fb Coding style for js: expand tabs
gibus
parents: 338
diff changeset
    13
          'tags':''},
053551f213fb Coding style for js: expand tabs
gibus
parents: 338
diff changeset
    14
        'ids': {
053551f213fb Coding style for js: expand tabs
gibus
parents: 338
diff changeset
    15
          'name':gPrefs.get('user','name'),
053551f213fb Coding style for js: expand tabs
gibus
parents: 338
diff changeset
    16
          'email':gPrefs.get('user','email'), 
053551f213fb Coding style for js: expand tabs
gibus
parents: 338
diff changeset
    17
          'title':'', 
053551f213fb Coding style for js: expand tabs
gibus
parents: 338
diff changeset
    18
          'content':'',
053551f213fb Coding style for js: expand tabs
gibus
parents: 338
diff changeset
    19
          'tags':'',
053551f213fb Coding style for js: expand tabs
gibus
parents: 338
diff changeset
    20
          'formId':CY.guid(),
053551f213fb Coding style for js: expand tabs
gibus
parents: 338
diff changeset
    21
          'nameInputId':CY.guid(),
053551f213fb Coding style for js: expand tabs
gibus
parents: 338
diff changeset
    22
          'emailInputId':CY.guid(),
053551f213fb Coding style for js: expand tabs
gibus
parents: 338
diff changeset
    23
          'titleInputId':CY.guid(),
053551f213fb Coding style for js: expand tabs
gibus
parents: 338
diff changeset
    24
          'contentInputId':CY.guid(),
053551f213fb Coding style for js: expand tabs
gibus
parents: 338
diff changeset
    25
          'keyInputId':CY.guid(),
053551f213fb Coding style for js: expand tabs
gibus
parents: 338
diff changeset
    26
          'formatInputId':CY.guid(),
053551f213fb Coding style for js: expand tabs
gibus
parents: 338
diff changeset
    27
          'tagsInputId':CY.guid(),
053551f213fb Coding style for js: expand tabs
gibus
parents: 338
diff changeset
    28
          'parentCommentId':CY.guid(),
053551f213fb Coding style for js: expand tabs
gibus
parents: 338
diff changeset
    29
          'addBtnId':CY.guid(),
053551f213fb Coding style for js: expand tabs
gibus
parents: 338
diff changeset
    30
          'cancelBtnId':CY.guid()},
053551f213fb Coding style for js: expand tabs
gibus
parents: 338
diff changeset
    31
        'handlers':{}
053551f213fb Coding style for js: expand tabs
gibus
parents: 338
diff changeset
    32
        } ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 338
diff changeset
    33
  }
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    34
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 338
diff changeset
    35
  gNewReplyHost = iCommentToAppendTo ;
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    36
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 338
diff changeset
    37
  var headerHtml = '<hr/><center><div class="c-header-title">' + gettext('New reply') + '</div></center>' ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 338
diff changeset
    38
  var html = gFormHtml['formStart'].replace('###', gNewReply['ids']['formId']) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 338
diff changeset
    39
  if (!sv_loggedIn) {
053551f213fb Coding style for js: expand tabs
gibus
parents: 338
diff changeset
    40
    html = html + gFormHtml['nameInput'].replace('###', gNewReply['ids']['nameInputId']) + gFormHtml['emailInput'].replace('###', gNewReply['ids']['emailInputId']) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 338
diff changeset
    41
  }
053551f213fb Coding style for js: expand tabs
gibus
parents: 338
diff changeset
    42
  html = html + gFormHtml['titleInput'].replace('###', gNewReply['ids']['titleInputId']) + gFormHtml['contentInput'].replace('###', gNewReply['ids']['contentInputId']) + gFormHtml['tagsInput'].replace('###', gNewReply['ids']['tagsInputId']);
053551f213fb Coding style for js: expand tabs
gibus
parents: 338
diff changeset
    43
  html = html + gFormHtml['hidden'].replace('###', gNewReply['ids']['keyInputId']).replace('???', 'comment_key') ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 338
diff changeset
    44
  html = html + gFormHtml['hidden'].replace('###', gNewReply['ids']['formatInputId']).replace('???', 'format') ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 338
diff changeset
    45
  html = html + gFormHtml['hidden'].replace('###', gNewReply['ids']['parentCommentId']).replace('???', 'reply_to_id') ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 338
diff changeset
    46
  var btnsHtml =   gFormHtml['btns'].replace('###', gNewReply['ids']['addBtnId']).replace('???', gNewReply['ids']['cancelBtnId']) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 338
diff changeset
    47
  
053551f213fb Coding style for js: expand tabs
gibus
parents: 338
diff changeset
    48
  gNewReplyHost['overlay'].setStdModContent(CY.WidgetStdMod.FOOTER, headerHtml + html + btnsHtml) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 338
diff changeset
    49
  var replyNode = gNewReplyHost['overlay'].getStdModNode(CY.WidgetStdMod.FOOTER) ;
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    50
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 338
diff changeset
    51
  var comment = gDb.getComment(iCommentToAppendTo.commentId) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 338
diff changeset
    52
  var REPLYPREF = "Re: " ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 338
diff changeset
    53
  var newReplyTitle = (gNewReply['val']['title'] == "" || gNewReply['val']['title'].substring(0, REPLYPREF.length) == REPLYPREF) ? REPLYPREF + comment['title'] : gNewReply['val']['title'] ;
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    54
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 338
diff changeset
    55
  if (!sv_loggedIn) {
532
0bad3613f59d Reverse to YUI 3.0.0 since with YUI.3.10.3, comment content including words 'paragraph' or 'section' do not show up on Firefox, this is weird and has to be investigated.
gibus
parents: 525
diff changeset
    56
    replyNode.query('.n_name').set('value', gNewReply['val']['name']) ;
0bad3613f59d Reverse to YUI 3.0.0 since with YUI.3.10.3, comment content including words 'paragraph' or 'section' do not show up on Firefox, this is weird and has to be investigated.
gibus
parents: 525
diff changeset
    57
    replyNode.query('.n_email').set('value', gNewReply['val']['email']) ;
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 338
diff changeset
    58
  }
532
0bad3613f59d Reverse to YUI 3.0.0 since with YUI.3.10.3, comment content including words 'paragraph' or 'section' do not show up on Firefox, this is weird and has to be investigated.
gibus
parents: 525
diff changeset
    59
  replyNode.query('.n_title').set('value', newReplyTitle) ;
0bad3613f59d Reverse to YUI 3.0.0 since with YUI.3.10.3, comment content including words 'paragraph' or 'section' do not show up on Firefox, this is weird and has to be investigated.
gibus
parents: 525
diff changeset
    60
  replyNode.query('.n_content').set('value', gNewReply['val']['content']) ;
0bad3613f59d Reverse to YUI 3.0.0 since with YUI.3.10.3, comment content including words 'paragraph' or 'section' do not show up on Firefox, this is weird and has to be investigated.
gibus
parents: 525
diff changeset
    61
  replyNode.query('.n_tags').set('value', gNewReply['val']['tags']) ;
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 338
diff changeset
    62
  
532
0bad3613f59d Reverse to YUI 3.0.0 since with YUI.3.10.3, comment content including words 'paragraph' or 'section' do not show up on Firefox, this is weird and has to be investigated.
gibus
parents: 525
diff changeset
    63
  replyNode.query('#'+gNewReply['ids']['parentCommentId']).set('value', iCommentToAppendTo['commentId']) ;
0bad3613f59d Reverse to YUI 3.0.0 since with YUI.3.10.3, comment content including words 'paragraph' or 'section' do not show up on Firefox, this is weird and has to be investigated.
gibus
parents: 525
diff changeset
    64
  replyNode.query('#'+gNewReply['ids']['formatInputId']).set('value', gConf['defaultCommentFormat']) ;
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 338
diff changeset
    65
           
532
0bad3613f59d Reverse to YUI 3.0.0 since with YUI.3.10.3, comment content including words 'paragraph' or 'section' do not show up on Firefox, this is weird and has to be investigated.
gibus
parents: 525
diff changeset
    66
  gNewReplyHost['overlay'].get('contentBox').query(".c-reply").addClass('displaynone') ;
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    67
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 338
diff changeset
    68
  gNewReply['handlers']['addBtnId'] = CY.on("click", onAddNewReplyClick, "#"+gNewReply['ids']['addBtnId']);
053551f213fb Coding style for js: expand tabs
gibus
parents: 338
diff changeset
    69
  gNewReply['handlers']['cancelBtnId'] = CY.on("click", onCancelNewReplyClick, "#"+gNewReply['ids']['cancelBtnId']);
053551f213fb Coding style for js: expand tabs
gibus
parents: 338
diff changeset
    70
  
053551f213fb Coding style for js: expand tabs
gibus
parents: 338
diff changeset
    71
  var width = gLayout.getTopICommentsWidth() ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 338
diff changeset
    72
  changeFormFieldsWidth(gNewReply['ids']['formId'], width) ;
532
0bad3613f59d Reverse to YUI 3.0.0 since with YUI.3.10.3, comment content including words 'paragraph' or 'section' do not show up on Firefox, this is weird and has to be investigated.
gibus
parents: 525
diff changeset
    73
  CY.get("#"+gNewReply['ids']['contentInputId']).focus();
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    74
}
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    75
cleanNewReplyForm = function() {
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 338
diff changeset
    76
  if (gNewReplyHost != null) {
053551f213fb Coding style for js: expand tabs
gibus
parents: 338
diff changeset
    77
    var replyNode = gNewReplyHost['overlay'].getStdModNode(CY.WidgetStdMod.FOOTER) ;
532
0bad3613f59d Reverse to YUI 3.0.0 since with YUI.3.10.3, comment content including words 'paragraph' or 'section' do not show up on Firefox, this is weird and has to be investigated.
gibus
parents: 525
diff changeset
    78
    replyNode.queryAll('.comment_input').set('value','') ;
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 338
diff changeset
    79
  }
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    80
}
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    81
cancelNewReplyForm = function() {
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 338
diff changeset
    82
  if (gNewReplyHost != null) {
053551f213fb Coding style for js: expand tabs
gibus
parents: 338
diff changeset
    83
    
053551f213fb Coding style for js: expand tabs
gibus
parents: 338
diff changeset
    84
    // DETACH EVENT HANDLERS
053551f213fb Coding style for js: expand tabs
gibus
parents: 338
diff changeset
    85
    for (var id in gNewReply['handlers']) {
053551f213fb Coding style for js: expand tabs
gibus
parents: 338
diff changeset
    86
      if (gNewReply['handlers'][id] != null) {
053551f213fb Coding style for js: expand tabs
gibus
parents: 338
diff changeset
    87
        gNewReply['handlers'][id].detach() ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 338
diff changeset
    88
        gNewReply['handlers'][id] = null ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 338
diff changeset
    89
      }
053551f213fb Coding style for js: expand tabs
gibus
parents: 338
diff changeset
    90
    }
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    91
532
0bad3613f59d Reverse to YUI 3.0.0 since with YUI.3.10.3, comment content including words 'paragraph' or 'section' do not show up on Firefox, this is weird and has to be investigated.
gibus
parents: 525
diff changeset
    92
    gNewReplyHost['overlay'].get('contentBox').query(".c-reply").removeClass('displaynone') ;
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 338
diff changeset
    93
    
053551f213fb Coding style for js: expand tabs
gibus
parents: 338
diff changeset
    94
    var footer = gNewReplyHost['overlay'].getStdModNode(CY.WidgetStdMod.FOOTER) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 338
diff changeset
    95
    if (!sv_loggedIn) {
532
0bad3613f59d Reverse to YUI 3.0.0 since with YUI.3.10.3, comment content including words 'paragraph' or 'section' do not show up on Firefox, this is weird and has to be investigated.
gibus
parents: 525
diff changeset
    96
      gNewReply['val']['name'] = footer.query('.n_name').get('value') ;
0bad3613f59d Reverse to YUI 3.0.0 since with YUI.3.10.3, comment content including words 'paragraph' or 'section' do not show up on Firefox, this is weird and has to be investigated.
gibus
parents: 525
diff changeset
    97
      gNewReply['val']['email'] = footer.query('.n_email').get('value') ;
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 338
diff changeset
    98
    }
532
0bad3613f59d Reverse to YUI 3.0.0 since with YUI.3.10.3, comment content including words 'paragraph' or 'section' do not show up on Firefox, this is weird and has to be investigated.
gibus
parents: 525
diff changeset
    99
    gNewReply['val']['title'] = footer.query('.n_title').get('value') ;
0bad3613f59d Reverse to YUI 3.0.0 since with YUI.3.10.3, comment content including words 'paragraph' or 'section' do not show up on Firefox, this is weird and has to be investigated.
gibus
parents: 525
diff changeset
   100
    gNewReply['val']['content'] = footer.query('.n_content').get('value') ;
0bad3613f59d Reverse to YUI 3.0.0 since with YUI.3.10.3, comment content including words 'paragraph' or 'section' do not show up on Firefox, this is weird and has to be investigated.
gibus
parents: 525
diff changeset
   101
    gNewReply['val']['tags'] = footer.query('.n_tags').get('value') ;
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 338
diff changeset
   102
    
053551f213fb Coding style for js: expand tabs
gibus
parents: 338
diff changeset
   103
    footer.set('innerHTML', '') ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 338
diff changeset
   104
    
053551f213fb Coding style for js: expand tabs
gibus
parents: 338
diff changeset
   105
    gNewReplyHost = null ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 338
diff changeset
   106
  }
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   107
}
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   108
// event triggered
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   109
onAddNewReplyClick = function() {
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 338
diff changeset
   110
  if (!sv_loggedIn) {
532
0bad3613f59d Reverse to YUI 3.0.0 since with YUI.3.10.3, comment content including words 'paragraph' or 'section' do not show up on Firefox, this is weird and has to be investigated.
gibus
parents: 525
diff changeset
   111
    var name = CY.get("#"+gNewReply['ids']['nameInputId']).get('value') ;
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 338
diff changeset
   112
    gPrefs.persist("user", "name", name) ;  
053551f213fb Coding style for js: expand tabs
gibus
parents: 338
diff changeset
   113
  
532
0bad3613f59d Reverse to YUI 3.0.0 since with YUI.3.10.3, comment content including words 'paragraph' or 'section' do not show up on Firefox, this is weird and has to be investigated.
gibus
parents: 525
diff changeset
   114
    var email = CY.get("#"+gNewReply['ids']['emailInputId']).get('value') ;
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 338
diff changeset
   115
    gPrefs.persist("user", "email", email) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 338
diff changeset
   116
  }
053551f213fb Coding style for js: expand tabs
gibus
parents: 338
diff changeset
   117
  
053551f213fb Coding style for js: expand tabs
gibus
parents: 338
diff changeset
   118
  gSync.saveComment(gNewReply['ids']['formId']) ;
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   119
}
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   120
onCancelNewReplyClick = function() {
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 338
diff changeset
   121
  gSync.cancelReply() ;
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   122
}