src/cm/media/js/client/c_edit_form.js
author gibus
Wed, 11 Sep 2013 23:13:01 +0200
changeset 532 0bad3613f59d
parent 525 89ef5ed3c48b
child 552 ee0c833d1969
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
gEditICommentHost = null ;
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
     2
gEdit = 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
dbgc = null ;
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
     5
showEditForm = function(iCommentHost) {
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 113
diff changeset
     6
  
053551f213fb Coding style for js: expand tabs
gibus
parents: 113
diff changeset
     7
  if (gEdit == null) {
053551f213fb Coding style for js: expand tabs
gibus
parents: 113
diff changeset
     8
    gEdit = {
053551f213fb Coding style for js: expand tabs
gibus
parents: 113
diff changeset
     9
        'ids':{
053551f213fb Coding style for js: expand tabs
gibus
parents: 113
diff changeset
    10
          'formId':CY.guid(),
053551f213fb Coding style for js: expand tabs
gibus
parents: 113
diff changeset
    11
          'formTitleId':CY.guid(),
053551f213fb Coding style for js: expand tabs
gibus
parents: 113
diff changeset
    12
          'nameInputId':CY.guid(),
053551f213fb Coding style for js: expand tabs
gibus
parents: 113
diff changeset
    13
          'emailInputId':CY.guid(),
053551f213fb Coding style for js: expand tabs
gibus
parents: 113
diff changeset
    14
          'titleInputId':CY.guid(),
053551f213fb Coding style for js: expand tabs
gibus
parents: 113
diff changeset
    15
          'contentInputId':CY.guid(),
053551f213fb Coding style for js: expand tabs
gibus
parents: 113
diff changeset
    16
          'tagsInputId':CY.guid(),
504
b2e0186daa5b Adds a category to comments, painted with colored vertical bar.
gibus
parents: 341
diff changeset
    17
          'categoryInputId':CY.guid(),
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 113
diff changeset
    18
          'formatInputId':CY.guid(),
053551f213fb Coding style for js: expand tabs
gibus
parents: 113
diff changeset
    19
          'startWrapperInputId':CY.guid(),
053551f213fb Coding style for js: expand tabs
gibus
parents: 113
diff changeset
    20
          'endWrapperInputId':CY.guid(),
053551f213fb Coding style for js: expand tabs
gibus
parents: 113
diff changeset
    21
          'startOffsetInputId':CY.guid(),
053551f213fb Coding style for js: expand tabs
gibus
parents: 113
diff changeset
    22
          'endOffsetInputId':CY.guid(),
053551f213fb Coding style for js: expand tabs
gibus
parents: 113
diff changeset
    23
          'changeScopeInputId':CY.guid(),
053551f213fb Coding style for js: expand tabs
gibus
parents: 113
diff changeset
    24
          'changeScopeInputWrapper':CY.guid(),
053551f213fb Coding style for js: expand tabs
gibus
parents: 113
diff changeset
    25
          'selectionPlaceId':CY.guid(),
053551f213fb Coding style for js: expand tabs
gibus
parents: 113
diff changeset
    26
          'keyId':CY.guid(),
053551f213fb Coding style for js: expand tabs
gibus
parents: 113
diff changeset
    27
          'editCommentId':CY.guid(),
053551f213fb Coding style for js: expand tabs
gibus
parents: 113
diff changeset
    28
          'currentSelId':CY.guid(),
053551f213fb Coding style for js: expand tabs
gibus
parents: 113
diff changeset
    29
          'currentSelIdI':CY.guid(),
053551f213fb Coding style for js: expand tabs
gibus
parents: 113
diff changeset
    30
          'addBtnId':CY.guid(),
053551f213fb Coding style for js: expand tabs
gibus
parents: 113
diff changeset
    31
          'cancelBtnId':CY.guid()
053551f213fb Coding style for js: expand tabs
gibus
parents: 113
diff changeset
    32
          },
053551f213fb Coding style for js: expand tabs
gibus
parents: 113
diff changeset
    33
        'handlers':{}
053551f213fb Coding style for js: expand tabs
gibus
parents: 113
diff changeset
    34
    } ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 113
diff changeset
    35
  }
053551f213fb Coding style for js: expand tabs
gibus
parents: 113
diff changeset
    36
  
053551f213fb Coding style for js: expand tabs
gibus
parents: 113
diff changeset
    37
  gEditICommentHost = iCommentHost ;
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    38
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 113
diff changeset
    39
  gEditICommentHost.hideContent() ;
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    40
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 113
diff changeset
    41
// FORM HTML  
053551f213fb Coding style for js: expand tabs
gibus
parents: 113
diff changeset
    42
  var overlayHtml = getHtml(gEdit['ids']) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 113
diff changeset
    43
  var editHeader = '<div class="icomment-edit-header">' + overlayHtml['headerContent'] + '</div>' ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 113
diff changeset
    44
  var editBody = '<div class="icomment-edit-body">' + overlayHtml['bodyContent'] + '</div>' ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 113
diff changeset
    45
  
053551f213fb Coding style for js: expand tabs
gibus
parents: 113
diff changeset
    46
//  cf. http://yuilibrary.com/projects/yui3/ticket/2528319 
053551f213fb Coding style for js: expand tabs
gibus
parents: 113
diff changeset
    47
  gEditICommentHost['overlay'].setStdModContent(CY.WidgetStdMod.HEADER,CY.Node.create(editHeader),CY.WidgetStdMod.AFTER);   
053551f213fb Coding style for js: expand tabs
gibus
parents: 113
diff changeset
    48
  gEditICommentHost['overlay'].setStdModContent(CY.WidgetStdMod.BODY,CY.Node.create(editBody),CY.WidgetStdMod.AFTER);
053551f213fb Coding style for js: expand tabs
gibus
parents: 113
diff changeset
    49
  
053551f213fb Coding style for js: expand tabs
gibus
parents: 113
diff changeset
    50
// FORM TITLE   
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
    51
  CY.get("#"+gEdit['ids']['formTitleId']).set('innerHTML', gettext("Edit comment")) ;
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    52
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    53
// FETCH FORM VALUES FROM COMMENT
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 113
diff changeset
    54
  
053551f213fb Coding style for js: expand tabs
gibus
parents: 113
diff changeset
    55
  var comment = gDb.getComment(gEditICommentHost.commentId) ;
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
  CY.get("#"+gEdit['ids']['editCommentId']).set('value', comment.id) ;
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
  CY.get("#"+gEdit['ids']['keyId']).set('value', comment.key) ;
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
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
  CY.get("#"+gEdit['ids']['changeScopeInputId']+" input").set('checked', false) ;
504
b2e0186daa5b Adds a category to comments, painted with colored vertical bar.
gibus
parents: 341
diff changeset
    60
  // Edit scope and category just for the first comment in a thread
b2e0186daa5b Adds a category to comments, painted with colored vertical bar.
gibus
parents: 341
diff changeset
    61
  // => hides these inputs for a reply.
b2e0186daa5b Adds a category to comments, painted with colored vertical bar.
gibus
parents: 341
diff changeset
    62
  if (comment.reply_to_id != null) {
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
    CY.get("#"+gEdit['ids']['changeScopeInputId']).addClass('displaynone')
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
    CY.get("#"+gEdit['ids']['categoryInputId']).addClass('displaynone')
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
    65
    CY.get("#"+gEdit['ids']['categoryInputId']).ancestor().addClass('displaynone')
504
b2e0186daa5b Adds a category to comments, painted with colored vertical bar.
gibus
parents: 341
diff changeset
    66
  }
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 113
diff changeset
    67
  changeScopeFormClick() ; // to adapt
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    68
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
    69
  CY.get("#"+gEdit['ids']['nameInputId']).set('value', comment.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
    70
  CY.get("#"+gEdit['ids']['emailInputId']).set('value', comment.email) ; 
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    71
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 113
diff changeset
    72
  if (comment.logged_author) {
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("#"+gEdit['ids']['nameInputId']).setAttribute("disabled", true); 
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
    74
    CY.get("#"+gEdit['ids']['emailInputId']).setAttribute("disabled", true);
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 113
diff changeset
    75
  }
053551f213fb Coding style for js: expand tabs
gibus
parents: 113
diff changeset
    76
  
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    77
// FORM VALUES
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
  CY.get("#"+gEdit['ids']['titleInputId']).set('value', comment['title']) ;
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
    79
  CY.get("#"+gEdit['ids']['contentInputId']).set('value', comment['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
    80
  CY.get("#"+gEdit['ids']['tagsInputId']).set('value', comment['tags']) ;
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
    81
  if ( CY.get("#"+gEdit['ids']['categoryInputId']))
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
    82
    CY.get("#"+gEdit['ids']['categoryInputId']).set('value', comment['category']) ;
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 113
diff changeset
    83
  
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
    84
  CY.get("#"+gEdit['ids']['formatInputId']).set('value',gConf['defaultCommentFormat']) ;// for now ...
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 113
diff changeset
    85
  
053551f213fb Coding style for js: expand tabs
gibus
parents: 113
diff changeset
    86
// WIDTH  
053551f213fb Coding style for js: expand tabs
gibus
parents: 113
diff changeset
    87
  var width = gLayout.getTopICommentsWidth() ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 113
diff changeset
    88
  changeFormFieldsWidth(gEdit['ids']['formId'], width) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 113
diff changeset
    89
  
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    90
// ATTACH EVENT HANDLERS
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 113
diff changeset
    91
  gEdit['handlers']['addBtnId'] = CY.on("click", onEditSaveClick, "#"+gEdit['ids']['addBtnId']);
053551f213fb Coding style for js: expand tabs
gibus
parents: 113
diff changeset
    92
  gEdit['handlers']['cancelBtnId'] = CY.on("click", onEditCancelClick, "#"+gEdit['ids']['cancelBtnId']);
053551f213fb Coding style for js: expand tabs
gibus
parents: 113
diff changeset
    93
  gEdit['handlers']['changeScope'] = CY.on("click", onChangeScopeClick, "#"+gEdit['ids']['changeScopeInputId']);
053551f213fb Coding style for js: expand tabs
gibus
parents: 113
diff changeset
    94
  
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    95
}
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    96
onEditSaveClick = function(iCommentHost) {
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 113
diff changeset
    97
  if (readyForAction())
053551f213fb Coding style for js: expand tabs
gibus
parents: 113
diff changeset
    98
    gSync.editComment() ;
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    99
}
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   100
onEditCancelClick = function(iCommentHost) {
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 113
diff changeset
   101
  if (readyForAction())
053551f213fb Coding style for js: expand tabs
gibus
parents: 113
diff changeset
   102
    gSync.cancelEdit() ;
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   103
}
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   104
onChangeScopeClick = function() {
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 113
diff changeset
   105
  if (readyForAction())
053551f213fb Coding style for js: expand tabs
gibus
parents: 113
diff changeset
   106
    gSync.changeScopeFormClick() ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 113
diff changeset
   107
  else {// (onChangeScopeClick triggers an animation : checking for readyForAction does not prevent the checkbox change ...)
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
   108
    var chckCtrl = CY.get("#"+gEdit['ids']['changeScopeInputId']+" input") ;
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 113
diff changeset
   109
    var chck = chckCtrl.get('checked') ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 113
diff changeset
   110
    chckCtrl.set('checked', !chck) ; // set it back 
053551f213fb Coding style for js: expand tabs
gibus
parents: 113
diff changeset
   111
  }
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   112
}
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   113
changeScopeFormClick = function() {
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 node = CY.get("#"+gEdit['ids']['currentSelId']) ;
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
   115
  if (CY.get("#"+gEdit['ids']['changeScopeInputId']+" input").get('checked'))
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 113
diff changeset
   116
    node.removeClass('displaynone') ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 113
diff changeset
   117
  else
053551f213fb Coding style for js: expand tabs
gibus
parents: 113
diff changeset
   118
    node.addClass('displaynone') ;
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
cancelEditForm = function() {
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 113
diff changeset
   121
  if (gEditICommentHost != null) {
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   122
// DETACH EVENT HANDLERS
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 113
diff changeset
   123
    for (var id in gEdit['handlers']) {
053551f213fb Coding style for js: expand tabs
gibus
parents: 113
diff changeset
   124
      if (gEdit['handlers'][id] != null) {
053551f213fb Coding style for js: expand tabs
gibus
parents: 113
diff changeset
   125
        gEdit['handlers'][id].detach() ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 113
diff changeset
   126
        gEdit['handlers'][id] = null ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 113
diff changeset
   127
      }
053551f213fb Coding style for js: expand tabs
gibus
parents: 113
diff changeset
   128
    }
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   129
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   130
// REMOVE EDIT FORM NODES FROM ICOMMENT OVERLAY
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
   131
    var node = gEditICommentHost['overlay'].get('contentBox').query(".icomment-edit-body") ;
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 113
diff changeset
   132
    node.get('parentNode').removeChild(node) ;
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
   133
    node = gEditICommentHost['overlay'].get('contentBox').query(".icomment-edit-header") ;
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 113
diff changeset
   134
    node.get('parentNode').removeChild(node) ;
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   135
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   136
// SHOW ICOMMENT OVERLAY
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 113
diff changeset
   137
    gEditICommentHost.showContent() ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 113
diff changeset
   138
    
053551f213fb Coding style for js: expand tabs
gibus
parents: 113
diff changeset
   139
    gEditICommentHost = null ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 113
diff changeset
   140
  }
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   141
}