src/cm/media/js/client/c_addcomment_form.js
changeset 600 fda73ac53450
parent 562 92e8e5aaacde
equal deleted inserted replaced
599:6c2ef083d89f 600:fda73ac53450
     1 gICommentForm = null ;
     1 gICommentForm = null ;
     2 
     2 
     3 instanciateICommentForm = function() {
     3 instanciateICommentForm = function() {
     4   gICommentForm = {
     4   gICommentForm = {
     5       'position':[CY.WidgetPositionExt.TL, CY.WidgetPositionExt.TL],
     5       'position':[CY.WidgetPositionAlign.TL, CY.WidgetPositionAlign.TL],
     6       'formId':CY.guid(),
     6       'formId':CY.guid(),
     7       'formTitleId':CY.guid(),
     7       'formTitleId':CY.guid(),
     8       'titleInputId':CY.guid(),
     8       'titleInputId':CY.guid(),
     9       'contentInputId':CY.guid(),
     9       'contentInputId':CY.guid(),
    10       'tagsInputId':CY.guid(),
    10       'tagsInputId':CY.guid(),
    46   
    46   
    47   // attach to DOM
    47   // attach to DOM
    48   overlay.render('#leftcolumn');
    48   overlay.render('#leftcolumn');
    49   
    49   
    50   if (!sv_loggedIn) {
    50   if (!sv_loggedIn) {
    51     CY.get("#"+gICommentForm['nameInputId']).set('value',gPrefs.get("user","name")) ;
    51     CY.one("#"+gICommentForm['nameInputId']).set('value',gPrefs.get("user","name")) ;
    52     CY.get("#"+gICommentForm['emailInputId']).set('value',gPrefs.get("user","email")) ;
    52     CY.one("#"+gICommentForm['emailInputId']).set('value',gPrefs.get("user","email")) ;
    53   }
    53   }
    54     
    54     
    55   CY.get("#"+gICommentForm['formTitleId']).set('innerHTML', gettext('New comment')) ;
    55   CY.one("#"+gICommentForm['formTitleId']).set('innerHTML', gettext('New comment')) ;
    56   CY.get("#"+gICommentForm['formatInputId']).set('value',gConf['defaultCommentFormat']) ;
    56   CY.one("#"+gICommentForm['formatInputId']).set('value',gConf['defaultCommentFormat']) ;
    57   
    57   
    58   CY.on("click", onSubmitICommentFormClick, "#"+gICommentForm['addBtnId']);
    58   CY.on("click", onSubmitICommentFormClick, "#"+gICommentForm['addBtnId']);
    59   CY.on("click", onCancelICommentFormClick, "#"+gICommentForm['cancelBtnId']);
    59   CY.on("click", onCancelICommentFormClick, "#"+gICommentForm['cancelBtnId']);
    60   CY.on("click", onCancelICommentFormClick, "#"+gICommentForm['closeBtnId']);
    60   CY.on("click", onCancelICommentFormClick, "#"+gICommentForm['closeBtnId']);
    61   
    61   
    83   
    83   
    84   changeFormFieldsWidth(gICommentForm['formId'], width) ;
    84   changeFormFieldsWidth(gICommentForm['formId'], width) ;
    85 }
    85 }
    86 
    86 
    87 cleanICommentForm = function() {
    87 cleanICommentForm = function() {
    88   CY.get("#"+gICommentForm['currentSelIdI']).set('innerHTML', gNoSelectionYet) ;
    88   CY.one("#"+gICommentForm['currentSelIdI']).set('innerHTML', gNoSelectionYet) ;
    89 
    89 
    90     var hostNode = gICommentForm['overlay'].getStdModNode(CY.WidgetStdMod.BODY) ;
    90     var hostNode = gICommentForm['overlay'].getStdModNode(CY.WidgetStdMod.BODY) ;
    91     hostNode.queryAll(".comment_input").set('value', "") ;
    91     hostNode.all(".comment_input").set('value', "") ;
    92   
    92   
    93   CY.get("#"+gICommentForm['formatInputId']).set('value',gConf['defaultCommentFormat']) ;// for now ...
    93   CY.one("#"+gICommentForm['formatInputId']).set('value',gConf['defaultCommentFormat']) ;// for now ...
    94   
    94   
    95   if (!sv_loggedIn) {
    95   if (!sv_loggedIn) {
    96     hostNode.queryAll(".user_input").set('value', "") ;
    96     hostNode.all(".user_input").set('value', "") ;
    97   }
    97   }
    98 }
    98 }
    99 
    99 
   100 onICommentFormHideAnimEnd = function() {
   100 onICommentFormHideAnimEnd = function() {
   101 //  iComment['overlay'].blur() ;
   101 //  iComment['overlay'].blur() ;
   107   gSync.resume() ;    
   107   gSync.resume() ;    
   108 }
   108 }
   109 
   109 
   110 onSubmitICommentFormClick = function() {
   110 onSubmitICommentFormClick = function() {
   111   if (!sv_loggedIn) {
   111   if (!sv_loggedIn) {
   112     var name = CY.get("#"+gICommentForm['nameInputId']).get('value') ;
   112     var name = CY.one("#"+gICommentForm['nameInputId']).get('value') ;
   113     gPrefs.persist("user", "name", name) ;  
   113     gPrefs.persist("user", "name", name) ;  
   114   
   114   
   115     var email = CY.get("#"+gICommentForm['emailInputId']).get('value') ;
   115     var email = CY.one("#"+gICommentForm['emailInputId']).get('value') ;
   116     gPrefs.persist("user", "email", email) ;
   116     gPrefs.persist("user", "email", email) ;
   117   }
   117   }
   118   gSync.saveComment(gICommentForm['formId']) ;
   118   gSync.saveComment(gICommentForm['formId']) ;
   119 }
   119 }
   120 
   120 
   122   gSync.cancelICommentForm() ;
   122   gSync.cancelICommentForm() ;
   123 }
   123 }
   124 
   124 
   125 // record selection info in hidden form fields
   125 // record selection info in hidden form fields
   126 _updateICommentFormSelection = function(ids, displayedText, csStartSelection, csEndSelection) {
   126 _updateICommentFormSelection = function(ids, displayedText, csStartSelection, csEndSelection) {
   127   var node = CY.Node.get('#'+ids['currentSelIdI']) ;
   127   var node = CY.Node.one('#'+ids['currentSelIdI']) ;
   128   if (node != null)
   128   if (node != null)
   129     node.set('innerHTML', displayedText) ;
   129     node.set('innerHTML', displayedText) ;
   130   
   130   
   131     node = CY.get('#'+ids['startWrapperInputId']) ;
   131     node = CY.one('#'+ids['startWrapperInputId']) ;
   132   if (node != null)
   132   if (node != null)
   133     node.set('value', csStartSelection['elt'].id.substring("sv_".length)) ;
   133     node.set('value', csStartSelection['elt'].id.substring("sv_".length)) ;
   134     node = CY.get('#'+ids['startOffsetInputId']) ;
   134     node = CY.one('#'+ids['startOffsetInputId']) ;
   135   if (node != null)
   135   if (node != null)
   136     node.set('value', csStartSelection['offset']) ;
   136     node.set('value', csStartSelection['offset']) ;
   137     node = CY.get('#'+ids['endWrapperInputId']) ;
   137     node = CY.one('#'+ids['endWrapperInputId']) ;
   138   if (node != null)
   138   if (node != null)
   139     node.set('value', csEndSelection['elt'].id.substring("sv_".length)) ;
   139     node.set('value', csEndSelection['elt'].id.substring("sv_".length)) ;
   140     node = CY.get('#'+ids['endOffsetInputId']) ;
   140     node = CY.one('#'+ids['endOffsetInputId']) ;
   141   if (node != null)
   141   if (node != null)
   142     node.set('value', csEndSelection['offset']) ;
   142     node.set('value', csEndSelection['offset']) ;
   143 }
   143 }
   144 
   144 
   145 updateICommentFormSelection = function(selection) {
   145 updateICommentFormSelection = function(selection) {
   165 }
   165 }
   166 
   166 
   167 showICommentForm= function () {
   167 showICommentForm= function () {
   168   removeFormErrMsg(gICommentForm['formId']) ;
   168   removeFormErrMsg(gICommentForm['formId']) ;
   169   if (!sv_loggedIn) {
   169   if (!sv_loggedIn) {
   170     if (CY.get("#"+gICommentForm['nameInputId']).get('value') == '') 
   170     if (CY.one("#"+gICommentForm['nameInputId']).get('value') == '') 
   171       CY.get("#"+gICommentForm['nameInputId']).set('value', gPrefs.get('user','name')) ;
   171       CY.one("#"+gICommentForm['nameInputId']).set('value', gPrefs.get('user','name')) ;
   172     if (CY.get("#"+gICommentForm['emailInputId']).get('value') == '') 
   172     if (CY.one("#"+gICommentForm['emailInputId']).get('value') == '') 
   173       CY.get("#"+gICommentForm['emailInputId']).set('value', gPrefs.get('user','email')) ;
   173       CY.one("#"+gICommentForm['emailInputId']).set('value', gPrefs.get('user','email')) ;
   174   }
   174   }
   175   gIComments.hide() ;
   175   gIComments.hide() ;
   176   hideToc();
   176   hideToc();
   177   positionICommentForm() ;
   177   positionICommentForm() ;
   178   gICommentForm['overlay'].show() ;
   178   gICommentForm['overlay'].show() ;
   179   CY.get("#"+gICommentForm['titleInputId']).focus() ;
   179   CY.one("#"+gICommentForm['titleInputId']).focus() ;
   180 }
   180 }
   181 
   181 
   182 isICommentFormVisible = function () {
   182 isICommentFormVisible = function () {
   183   if (gICommentForm != null)
   183   if (gICommentForm != null)
   184     return gICommentForm['overlay'].get('visible') ;
   184     return gICommentForm['overlay'].get('visible') ;
   193     var commentFormHeight = boundingBox.get('offsetHeight') ;
   193     var commentFormHeight = boundingBox.get('offsetHeight') ;
   194     var windowHeight = boundingBox.get('winHeight') ;
   194     var windowHeight = boundingBox.get('winHeight') ;
   195 
   195 
   196     var pos = gICommentForm['position'] ;
   196     var pos = gICommentForm['position'] ;
   197     if (commentFormHeight > windowHeight) // trying to have save comment visible ... :
   197     if (commentFormHeight > windowHeight) // trying to have save comment visible ... :
   198       pos = [CY.WidgetPositionExt.BL, CY.WidgetPositionExt.BL] ;
   198       pos = [CY.WidgetPositionAlign.BL, CY.WidgetPositionAlign.BL] ;
   199     
   199     
   200     overlay.set("align", {points:pos});
   200     overlay.set("align", {points:pos});
   201     if (commentFormHeight <= windowHeight)
   201     if (commentFormHeight <= windowHeight)
   202       overlay.set("y", overlay.get("y") + 30);
   202       overlay.set("y", overlay.get("y") + 30);
   203     boundingBox.setX(boundingBox.getX() + gConf['iCommentLeftPadding']);
   203     boundingBox.setX(boundingBox.getX() + gConf['iCommentLeftPadding']);