src/cm/media/js/client/c_interface_forms.js
author gibus
Wed, 11 Sep 2013 23:13:01 +0200
changeset 532 0bad3613f59d
parent 504 b2e0186daa5b
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
gNoSelectionYet = gettext("No selection yet") ;
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
     2
gFormHtml = {
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 11
diff changeset
     3
    'formStart'   :'<form id="###" onsubmit="return false;">',
053551f213fb Coding style for js: expand tabs
gibus
parents: 11
diff changeset
     4
    'nameInput'   :gettext('Username:') + '<center><input id="###" name="name" class="n_name user_input" style="padding:1px;" type="text"></input></center>',
053551f213fb Coding style for js: expand tabs
gibus
parents: 11
diff changeset
     5
    'emailInput'  :gettext('E-mail address:') + '<center><input id="###" name="email" class="n_email user_input" style="padding:1px;" type="text"></input></center>',
053551f213fb Coding style for js: expand tabs
gibus
parents: 11
diff changeset
     6
    'titleInput'  :gettext('Title:') + '<center><input id="###" name="title" class="n_title comment_input" style="padding:1px;" type="text"></input></center>',
053551f213fb Coding style for js: expand tabs
gibus
parents: 11
diff changeset
     7
    'contentInput'  :gettext("Content:") + '<center><textarea id="###" name="content" class="n_content comment_input" rows="10" style="padding:1px;"></textarea></center>',
053551f213fb Coding style for js: expand tabs
gibus
parents: 11
diff changeset
     8
    'tagsInput'   :gettext("Tag:") + '<center><input id="###" name="tags" class="n_tags comment_input" style="padding:1px;" type="text"></input></center>',
053551f213fb Coding style for js: expand tabs
gibus
parents: 11
diff changeset
     9
    'hidden'    :'<input id="###" class="comment_input" name="???" type="hidden" value=""></input>',
053551f213fb Coding style for js: expand tabs
gibus
parents: 11
diff changeset
    10
    'formEnd'     :'</form>',
053551f213fb Coding style for js: expand tabs
gibus
parents: 11
diff changeset
    11
    'changeScope'   :'<div id="###">' + gettext("Modify comment's scope:") + '<input type="checkbox" name="change_scope"></input></div>',
053551f213fb Coding style for js: expand tabs
gibus
parents: 11
diff changeset
    12
    'headerTitle' :'<center><div id="###" class="c-header-title"></div></center>',
053551f213fb Coding style for js: expand tabs
gibus
parents: 11
diff changeset
    13
    'currentSel'  :'<div id="###">' + gettext('Comment will apply to this selection:') + '<br/><div class="current_sel"><div id="???" class="current_sel_ins">' + gNoSelectionYet + '</div></div>#hiddeninput#</div>',
053551f213fb Coding style for js: expand tabs
gibus
parents: 11
diff changeset
    14
    'btns'      :'<center><input id="###" type="button" value="' + gettext('Save') + '" /><input id="???" type="button" value="' + gettext('Cancel') + '" /></center>',
053551f213fb Coding style for js: expand tabs
gibus
parents: 11
diff changeset
    15
    'closeIcon'   :'<a id="###" class="c-close" title="' + gettext('close') + '"><em>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</em></a>'
053551f213fb Coding style for js: expand tabs
gibus
parents: 11
diff changeset
    16
    } ;
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
// returns {'headerContent':headerHtml, 'bodyContent':bodyHtml}
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    19
getHtml = function(ids) {
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 11
diff changeset
    20
  ret = {} ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 11
diff changeset
    21
  ret['headerContent'] = '' ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 11
diff changeset
    22
  
053551f213fb Coding style for js: expand tabs
gibus
parents: 11
diff changeset
    23
  if ('closeBtnId' in ids)
053551f213fb Coding style for js: expand tabs
gibus
parents: 11
diff changeset
    24
    ret['headerContent'] += gFormHtml['closeIcon'].replace('###', ids['closeBtnId']) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 11
diff changeset
    25
  
053551f213fb Coding style for js: expand tabs
gibus
parents: 11
diff changeset
    26
  ret['headerContent'] += gFormHtml['headerTitle'].replace('###', ids['formTitleId']) ;
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    27
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 11
diff changeset
    28
  var selEditChkBoxHtml = "" ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 11
diff changeset
    29
  if ('changeScopeInputId' in ids)
053551f213fb Coding style for js: expand tabs
gibus
parents: 11
diff changeset
    30
    selEditChkBoxHtml = gFormHtml['changeScope'].replace('###', ids['changeScopeInputId']) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 11
diff changeset
    31
  
053551f213fb Coding style for js: expand tabs
gibus
parents: 11
diff changeset
    32
  var hiddenInput = '<center>'+gFormHtml['hidden'].replace('###', ids['selectionPlaceId']).replace('???', 'selection_place')+'</center>' ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 11
diff changeset
    33
  var selectionTitleHtml = gFormHtml['currentSel'].replace('###', ids['currentSelId']).replace('???', ids['currentSelIdI']).replace('#hiddeninput#', hiddenInput) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 11
diff changeset
    34
  
053551f213fb Coding style for js: expand tabs
gibus
parents: 11
diff changeset
    35
  var btnsHtml =   gFormHtml['btns'].replace('###', ids['addBtnId']).replace('???', ids['cancelBtnId']) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 11
diff changeset
    36
  
053551f213fb Coding style for js: expand tabs
gibus
parents: 11
diff changeset
    37
  var html = gFormHtml['formStart'].replace('###', ids['formId']) + selEditChkBoxHtml + selectionTitleHtml ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 11
diff changeset
    38
  
053551f213fb Coding style for js: expand tabs
gibus
parents: 11
diff changeset
    39
  if ('nameInputId' in ids)
053551f213fb Coding style for js: expand tabs
gibus
parents: 11
diff changeset
    40
    html = html + gFormHtml['nameInput'].replace('###', ids['nameInputId'])  ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 11
diff changeset
    41
  if ('emailInputId' in ids)
053551f213fb Coding style for js: expand tabs
gibus
parents: 11
diff changeset
    42
    html = html + gFormHtml['emailInput'].replace('###', ids['emailInputId']) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 11
diff changeset
    43
  
504
b2e0186daa5b Adds a category to comments, painted with colored vertical bar.
gibus
parents: 341
diff changeset
    44
  html = html + gFormHtml['titleInput'].replace('###', ids['titleInputId']) + gFormHtml['contentInput'].replace('###', ids['contentInputId']);
b2e0186daa5b Adds a category to comments, painted with colored vertical bar.
gibus
parents: 341
diff changeset
    45
b2e0186daa5b Adds a category to comments, painted with colored vertical bar.
gibus
parents: 341
diff changeset
    46
  categories = CY.JSON.parse(sv_categories);
b2e0186daa5b Adds a category to comments, painted with colored vertical bar.
gibus
parents: 341
diff changeset
    47
  if (categories.hasOwnProperty('0')) {
b2e0186daa5b Adds a category to comments, painted with colored vertical bar.
gibus
parents: 341
diff changeset
    48
    category_options = '';
b2e0186daa5b Adds a category to comments, painted with colored vertical bar.
gibus
parents: 341
diff changeset
    49
    for (c in categories) {
b2e0186daa5b Adds a category to comments, painted with colored vertical bar.
gibus
parents: 341
diff changeset
    50
      category_options += '<option value="' + c + '">' + categories[c] + '</option>';
b2e0186daa5b Adds a category to comments, painted with colored vertical bar.
gibus
parents: 341
diff changeset
    51
    }
b2e0186daa5b Adds a category to comments, painted with colored vertical bar.
gibus
parents: 341
diff changeset
    52
    gFormHtml['categoryInput'] = gettext("Category:") + '&nbsp;<select id="###" name="category" class="n_category comment_input" style="padding:1px;" type="text">' + category_options + '</select>';
b2e0186daa5b Adds a category to comments, painted with colored vertical bar.
gibus
parents: 341
diff changeset
    53
    html = html + '<span class="n_category_input">' + gFormHtml['categoryInput'].replace('###', ids['categoryInputId']) + '<br /></span>';
b2e0186daa5b Adds a category to comments, painted with colored vertical bar.
gibus
parents: 341
diff changeset
    54
  }
b2e0186daa5b Adds a category to comments, painted with colored vertical bar.
gibus
parents: 341
diff changeset
    55
b2e0186daa5b Adds a category to comments, painted with colored vertical bar.
gibus
parents: 341
diff changeset
    56
  html = html + gFormHtml['tagsInput'].replace('###', ids['tagsInputId']);
b2e0186daa5b Adds a category to comments, painted with colored vertical bar.
gibus
parents: 341
diff changeset
    57
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 11
diff changeset
    58
  html = html + gFormHtml['hidden'].replace('###', ids['formatInputId']).replace('???', 'format') ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 11
diff changeset
    59
  html = html + gFormHtml['hidden'].replace('###', ids['startWrapperInputId']).replace('???', 'start_wrapper') ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 11
diff changeset
    60
  html = html + gFormHtml['hidden'].replace('###', ids['endWrapperInputId']).replace('???', 'end_wrapper') ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 11
diff changeset
    61
  html = html + gFormHtml['hidden'].replace('###', ids['startOffsetInputId']).replace('???', 'start_offset') ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 11
diff changeset
    62
  html = html + gFormHtml['hidden'].replace('###', ids['endOffsetInputId']).replace('???', 'end_offset') ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 11
diff changeset
    63
  html = html + gFormHtml['hidden'].replace('###', ids['keyId']).replace('???', 'comment_key') ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 11
diff changeset
    64
  html = html + gFormHtml['hidden'].replace('###', ids['editCommentId']).replace('???', 'edit_comment_id') ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 11
diff changeset
    65
  html = html +  btnsHtml + gFormHtml['formEnd'] ;  
053551f213fb Coding style for js: expand tabs
gibus
parents: 11
diff changeset
    66
  ret['bodyContent'] = html ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 11
diff changeset
    67
  return ret ;
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    68
} ;
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    69
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    70
changeFormFieldsWidth = function(formId, val) {
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 11
diff changeset
    71
  var fieldWidth = (val - 20) +'px' ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 11
diff changeset
    72
  var elts = CY.all("#" + formId + " input[type='text']") ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 11
diff changeset
    73
  if (elts != null)
053551f213fb Coding style for js: expand tabs
gibus
parents: 11
diff changeset
    74
    elts.setStyle("width", fieldWidth) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 11
diff changeset
    75
  elts = CY.all("#" + formId + " textarea") ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 11
diff changeset
    76
  if (elts != null)
053551f213fb Coding style for js: expand tabs
gibus
parents: 11
diff changeset
    77
    elts.setStyle("width", fieldWidth) ;
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    78
}
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    79
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    80
addFormErrMsg = function(formId, eltName, errorString) {
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 11
diff changeset
    81
  var formElt = document.getElementById(formId) ;
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    82
    var i, e, s, ilen ;
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    83
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    84
    // Iterate over the form elements collection to construct the
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    85
    // label-value pairs.
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    86
    for (i = 0, ilen = formElt.elements.length; i < ilen; ++i) {
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    87
        e = formElt.elements[i];
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    88
        if (e.name == eltName) {
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 11
diff changeset
    89
          s = document.createElement('DIV') ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 11
diff changeset
    90
          CY.DOM.addClass(s, 'c-error') ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 11
diff changeset
    91
          s.id = e.id + '-err';
053551f213fb Coding style for js: expand tabs
gibus
parents: 11
diff changeset
    92
          s.appendChild(document.createTextNode(errorString)) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 11
diff changeset
    93
          if (e.parentNode.nextSibling)
053551f213fb Coding style for js: expand tabs
gibus
parents: 11
diff changeset
    94
            e.parentNode.parentNode.insertBefore(s, e.parentNode.nextSibling) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 11
diff changeset
    95
          else 
053551f213fb Coding style for js: expand tabs
gibus
parents: 11
diff changeset
    96
            e.parentNode.parentNode.appendChild(s) ;
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
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    99
    }
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   100
}
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   101
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   102
// frames['text_view_frame'].removeFormErrMsg(frames['text_view_frame'].gICommentForm['formId'])
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   103
removeFormErrMsg = function(formId) {
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 11
diff changeset
   104
  var nodes = CY.all('#'+formId+' .c-error');
053551f213fb Coding style for js: expand tabs
gibus
parents: 11
diff changeset
   105
  if (nodes != null)
053551f213fb Coding style for js: expand tabs
gibus
parents: 11
diff changeset
   106
    nodes.each(function (node) {node.get('parentNode').removeChild(node) ;}) ;
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