src/cm/media/js/client/c_interface_forms.js
author gibus
Mon, 01 Oct 2012 11:00:56 +0200
changeset 469 08d57b273596
parent 341 053551f213fb
child 504 b2e0186daa5b
permissions -rw-r--r--
When building toc, delete <a> elements, including when written in uppercase (<A>).
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
  
053551f213fb Coding style for js: expand tabs
gibus
parents: 11
diff changeset
    44
  html = html + gFormHtml['titleInput'].replace('###', ids['titleInputId']) + gFormHtml['contentInput'].replace('###', ids['contentInputId']) + gFormHtml['tagsInput'].replace('###', ids['tagsInputId']);
053551f213fb Coding style for js: expand tabs
gibus
parents: 11
diff changeset
    45
  html = html + gFormHtml['hidden'].replace('###', ids['formatInputId']).replace('???', 'format') ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 11
diff changeset
    46
  html = html + gFormHtml['hidden'].replace('###', ids['startWrapperInputId']).replace('???', 'start_wrapper') ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 11
diff changeset
    47
  html = html + gFormHtml['hidden'].replace('###', ids['endWrapperInputId']).replace('???', 'end_wrapper') ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 11
diff changeset
    48
  html = html + gFormHtml['hidden'].replace('###', ids['startOffsetInputId']).replace('???', 'start_offset') ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 11
diff changeset
    49
  html = html + gFormHtml['hidden'].replace('###', ids['endOffsetInputId']).replace('???', 'end_offset') ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 11
diff changeset
    50
  html = html + gFormHtml['hidden'].replace('###', ids['keyId']).replace('???', 'comment_key') ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 11
diff changeset
    51
  html = html + gFormHtml['hidden'].replace('###', ids['editCommentId']).replace('???', 'edit_comment_id') ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 11
diff changeset
    52
  html = html +  btnsHtml + gFormHtml['formEnd'] ;  
053551f213fb Coding style for js: expand tabs
gibus
parents: 11
diff changeset
    53
  ret['bodyContent'] = html ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 11
diff changeset
    54
  return ret ;
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    55
} ;
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    56
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    57
changeFormFieldsWidth = function(formId, val) {
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 11
diff changeset
    58
  var fieldWidth = (val - 20) +'px' ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 11
diff changeset
    59
  var elts = CY.all("#" + formId + " input[type='text']") ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 11
diff changeset
    60
  if (elts != null)
053551f213fb Coding style for js: expand tabs
gibus
parents: 11
diff changeset
    61
    elts.setStyle("width", fieldWidth) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 11
diff changeset
    62
  elts = CY.all("#" + formId + " textarea") ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 11
diff changeset
    63
  if (elts != null)
053551f213fb Coding style for js: expand tabs
gibus
parents: 11
diff changeset
    64
    elts.setStyle("width", fieldWidth) ;
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    65
}
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    66
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    67
addFormErrMsg = function(formId, eltName, errorString) {
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 11
diff changeset
    68
  var formElt = document.getElementById(formId) ;
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    69
    var i, e, s, ilen ;
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    70
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    71
    // Iterate over the form elements collection to construct the
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    72
    // label-value pairs.
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    73
    for (i = 0, ilen = formElt.elements.length; i < ilen; ++i) {
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    74
        e = formElt.elements[i];
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    75
        if (e.name == eltName) {
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 11
diff changeset
    76
          s = document.createElement('DIV') ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 11
diff changeset
    77
          CY.DOM.addClass(s, 'c-error') ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 11
diff changeset
    78
          s.id = e.id + '-err';
053551f213fb Coding style for js: expand tabs
gibus
parents: 11
diff changeset
    79
          s.appendChild(document.createTextNode(errorString)) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 11
diff changeset
    80
          if (e.parentNode.nextSibling)
053551f213fb Coding style for js: expand tabs
gibus
parents: 11
diff changeset
    81
            e.parentNode.parentNode.insertBefore(s, e.parentNode.nextSibling) ;
053551f213fb Coding style for js: expand tabs
gibus
parents: 11
diff changeset
    82
          else 
053551f213fb Coding style for js: expand tabs
gibus
parents: 11
diff changeset
    83
            e.parentNode.parentNode.appendChild(s) ;
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    84
        }
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    85
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    86
    }
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    87
}
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    88
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    89
// frames['text_view_frame'].removeFormErrMsg(frames['text_view_frame'].gICommentForm['formId'])
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    90
removeFormErrMsg = function(formId) {
341
053551f213fb Coding style for js: expand tabs
gibus
parents: 11
diff changeset
    91
  var nodes = CY.all('#'+formId+' .c-error');
053551f213fb Coding style for js: expand tabs
gibus
parents: 11
diff changeset
    92
  if (nodes != null)
053551f213fb Coding style for js: expand tabs
gibus
parents: 11
diff changeset
    93
    nodes.each(function (node) {node.get('parentNode').removeChild(node) ;}) ;
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    94
}
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    95