src/cm/media/js/client/c_edit_form.js
author gibus
Tue, 15 Oct 2013 12:12:50 +0200
changeset 552 ee0c833d1969
parent 532 0bad3613f59d
child 600 fda73ac53450
permissions -rw-r--r--
Fix bug in edition of a reply when no category are defined.
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')
552
ee0c833d1969 Fix bug in edition of a reply when no category are defined.
gibus
parents: 532
diff changeset
    64
    if (CY.get("#"+gEdit['ids']['categoryInputId'])) {
ee0c833d1969 Fix bug in edition of a reply when no category are defined.
gibus
parents: 532
diff changeset
    65
      CY.get("#"+gEdit['ids']['categoryInputId']).addClass('displaynone')
ee0c833d1969 Fix bug in edition of a reply when no category are defined.
gibus
parents: 532
diff changeset
    66
      CY.get("#"+gEdit['ids']['categoryInputId']).ancestor().addClass('displaynone')
ee0c833d1969 Fix bug in edition of a reply when no category are defined.
gibus
parents: 532
diff changeset
    67
    }
504
b2e0186daa5b Adds a category to comments, painted with colored vertical bar.
gibus
parents: 341
diff changeset
    68
  }
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 113
diff changeset
    69
  changeScopeFormClick() ; // to adapt
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    70
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
    71
  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
    72
  CY.get("#"+gEdit['ids']['emailInputId']).set('value', comment.email) ; 
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    73
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 113
diff changeset
    74
  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
    75
    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
    76
    CY.get("#"+gEdit['ids']['emailInputId']).setAttribute("disabled", true);
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 113
diff changeset
    77
  }
053551f213fb Coding style for js: expand tabs
gibus
parents: 113
diff changeset
    78
  
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    79
// 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
    80
  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
    81
  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
    82
  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
    83
  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
    84
    CY.get("#"+gEdit['ids']['categoryInputId']).set('value', comment['category']) ;
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 113
diff changeset
    85
  
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
    86
  CY.get("#"+gEdit['ids']['formatInputId']).set('value',gConf['defaultCommentFormat']) ;// for now ...
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 113
diff changeset
    87
  
053551f213fb Coding style for js: expand tabs
gibus
parents: 113
diff changeset
    88
// WIDTH  
053551f213fb Coding style for js: expand tabs
gibus
parents: 113
diff changeset
    89
  var width = gLayout.getTopICommentsWidth() ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 113
diff changeset
    90
  changeFormFieldsWidth(gEdit['ids']['formId'], width) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 113
diff changeset
    91
  
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    92
// ATTACH EVENT HANDLERS
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 113
diff changeset
    93
  gEdit['handlers']['addBtnId'] = CY.on("click", onEditSaveClick, "#"+gEdit['ids']['addBtnId']);
053551f213fb Coding style for js: expand tabs
gibus
parents: 113
diff changeset
    94
  gEdit['handlers']['cancelBtnId'] = CY.on("click", onEditCancelClick, "#"+gEdit['ids']['cancelBtnId']);
053551f213fb Coding style for js: expand tabs
gibus
parents: 113
diff changeset
    95
  gEdit['handlers']['changeScope'] = CY.on("click", onChangeScopeClick, "#"+gEdit['ids']['changeScopeInputId']);
053551f213fb Coding style for js: expand tabs
gibus
parents: 113
diff changeset
    96
  
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    97
}
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    98
onEditSaveClick = function(iCommentHost) {
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 113
diff changeset
    99
  if (readyForAction())
053551f213fb Coding style for js: expand tabs
gibus
parents: 113
diff changeset
   100
    gSync.editComment() ;
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   101
}
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   102
onEditCancelClick = function(iCommentHost) {
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 113
diff changeset
   103
  if (readyForAction())
053551f213fb Coding style for js: expand tabs
gibus
parents: 113
diff changeset
   104
    gSync.cancelEdit() ;
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   105
}
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   106
onChangeScopeClick = function() {
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 113
diff changeset
   107
  if (readyForAction())
053551f213fb Coding style for js: expand tabs
gibus
parents: 113
diff changeset
   108
    gSync.changeScopeFormClick() ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 113
diff changeset
   109
  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
   110
    var chckCtrl = CY.get("#"+gEdit['ids']['changeScopeInputId']+" input") ;
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 113
diff changeset
   111
    var chck = chckCtrl.get('checked') ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 113
diff changeset
   112
    chckCtrl.set('checked', !chck) ; // set it back 
053551f213fb Coding style for js: expand tabs
gibus
parents: 113
diff changeset
   113
  }
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   114
}
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   115
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
   116
  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
   117
  if (CY.get("#"+gEdit['ids']['changeScopeInputId']+" input").get('checked'))
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 113
diff changeset
   118
    node.removeClass('displaynone') ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 113
diff changeset
   119
  else
053551f213fb Coding style for js: expand tabs
gibus
parents: 113
diff changeset
   120
    node.addClass('displaynone') ;
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   121
}
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   122
cancelEditForm = function() {
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 113
diff changeset
   123
  if (gEditICommentHost != null) {
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   124
// DETACH EVENT HANDLERS
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 113
diff changeset
   125
    for (var id in gEdit['handlers']) {
053551f213fb Coding style for js: expand tabs
gibus
parents: 113
diff changeset
   126
      if (gEdit['handlers'][id] != null) {
053551f213fb Coding style for js: expand tabs
gibus
parents: 113
diff changeset
   127
        gEdit['handlers'][id].detach() ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 113
diff changeset
   128
        gEdit['handlers'][id] = null ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 113
diff changeset
   129
      }
053551f213fb Coding style for js: expand tabs
gibus
parents: 113
diff changeset
   130
    }
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   131
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   132
// 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
   133
    var node = gEditICommentHost['overlay'].get('contentBox').query(".icomment-edit-body") ;
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 113
diff changeset
   134
    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
   135
    node = gEditICommentHost['overlay'].get('contentBox').query(".icomment-edit-header") ;
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 113
diff changeset
   136
    node.get('parentNode').removeChild(node) ;
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   137
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   138
// SHOW ICOMMENT OVERLAY
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 113
diff changeset
   139
    gEditICommentHost.showContent() ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 113
diff changeset
   140
    
053551f213fb Coding style for js: expand tabs
gibus
parents: 113
diff changeset
   141
    gEditICommentHost = null ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 113
diff changeset
   142
  }
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   143
}