src/cm/media/js/client/c_edit_form.js
changeset 341 053551f213fb
parent 113 cf99f4e14534
child 504 b2e0186daa5b
equal deleted inserted replaced
340:9e2b9e568e42 341:053551f213fb
     1 gEditICommentHost = null ;
     1 gEditICommentHost = null ;
     2 gEdit = null ;
     2 gEdit = null ;
     3 
     3 
     4 dbgc = null ;
     4 dbgc = null ;
     5 showEditForm = function(iCommentHost) {
     5 showEditForm = function(iCommentHost) {
     6 	
     6   
     7 	if (gEdit == null) {
     7   if (gEdit == null) {
     8 		gEdit = {
     8     gEdit = {
     9 				'ids':{
     9         'ids':{
    10 					'formId':CY.guid(),
    10           'formId':CY.guid(),
    11 					'formTitleId':CY.guid(),
    11           'formTitleId':CY.guid(),
    12 					'nameInputId':CY.guid(),
    12           'nameInputId':CY.guid(),
    13 					'emailInputId':CY.guid(),
    13           'emailInputId':CY.guid(),
    14 					'titleInputId':CY.guid(),
    14           'titleInputId':CY.guid(),
    15 					'contentInputId':CY.guid(),
    15           'contentInputId':CY.guid(),
    16 					'tagsInputId':CY.guid(),
    16           'tagsInputId':CY.guid(),
    17 					'formatInputId':CY.guid(),
    17           'formatInputId':CY.guid(),
    18 					'startWrapperInputId':CY.guid(),
    18           'startWrapperInputId':CY.guid(),
    19 					'endWrapperInputId':CY.guid(),
    19           'endWrapperInputId':CY.guid(),
    20 					'startOffsetInputId':CY.guid(),
    20           'startOffsetInputId':CY.guid(),
    21 					'endOffsetInputId':CY.guid(),
    21           'endOffsetInputId':CY.guid(),
    22 					'changeScopeInputId':CY.guid(),
    22           'changeScopeInputId':CY.guid(),
    23 					'changeScopeInputWrapper':CY.guid(),
    23           'changeScopeInputWrapper':CY.guid(),
    24 					'selectionPlaceId':CY.guid(),
    24           'selectionPlaceId':CY.guid(),
    25 					'keyId':CY.guid(),
    25           'keyId':CY.guid(),
    26 					'editCommentId':CY.guid(),
    26           'editCommentId':CY.guid(),
    27 					'currentSelId':CY.guid(),
    27           'currentSelId':CY.guid(),
    28 					'currentSelIdI':CY.guid(),
    28           'currentSelIdI':CY.guid(),
    29 					'addBtnId':CY.guid(),
    29           'addBtnId':CY.guid(),
    30 					'cancelBtnId':CY.guid()
    30           'cancelBtnId':CY.guid()
    31 					},
    31           },
    32 				'handlers':{}
    32         'handlers':{}
    33 		} ;
    33     } ;
    34 	}
    34   }
    35 	
    35   
    36 	gEditICommentHost = iCommentHost ;
    36   gEditICommentHost = iCommentHost ;
    37 
    37 
    38 	gEditICommentHost.hideContent() ;
    38   gEditICommentHost.hideContent() ;
    39 
    39 
    40 // FORM HTML 	
    40 // FORM HTML  
    41 	var overlayHtml = getHtml(gEdit['ids']) ;
    41   var overlayHtml = getHtml(gEdit['ids']) ;
    42 	var editHeader = '<div class="icomment-edit-header">' + overlayHtml['headerContent'] + '</div>' ;
    42   var editHeader = '<div class="icomment-edit-header">' + overlayHtml['headerContent'] + '</div>' ;
    43 	var editBody = '<div class="icomment-edit-body">' + overlayHtml['bodyContent'] + '</div>' ;
    43   var editBody = '<div class="icomment-edit-body">' + overlayHtml['bodyContent'] + '</div>' ;
    44 	
    44   
    45 //	cf. http://yuilibrary.com/projects/yui3/ticket/2528319 
    45 //  cf. http://yuilibrary.com/projects/yui3/ticket/2528319 
    46 	gEditICommentHost['overlay'].setStdModContent(CY.WidgetStdMod.HEADER,CY.Node.create(editHeader),CY.WidgetStdMod.AFTER); 	
    46   gEditICommentHost['overlay'].setStdModContent(CY.WidgetStdMod.HEADER,CY.Node.create(editHeader),CY.WidgetStdMod.AFTER);   
    47 	gEditICommentHost['overlay'].setStdModContent(CY.WidgetStdMod.BODY,CY.Node.create(editBody),CY.WidgetStdMod.AFTER);
    47   gEditICommentHost['overlay'].setStdModContent(CY.WidgetStdMod.BODY,CY.Node.create(editBody),CY.WidgetStdMod.AFTER);
    48 	
    48   
    49 // FORM TITLE 	
    49 // FORM TITLE   
    50 	CY.get("#"+gEdit['ids']['formTitleId']).set('innerHTML', gettext("Edit comment")) ;
    50   CY.get("#"+gEdit['ids']['formTitleId']).set('innerHTML', gettext("Edit comment")) ;
    51 
    51 
    52 // FETCH FORM VALUES FROM COMMENT
    52 // FETCH FORM VALUES FROM COMMENT
    53 	
    53   
    54 	var comment = gDb.getComment(gEditICommentHost.commentId) ;
    54   var comment = gDb.getComment(gEditICommentHost.commentId) ;
    55 	CY.get("#"+gEdit['ids']['editCommentId']).set('value', comment.id) ;
    55   CY.get("#"+gEdit['ids']['editCommentId']).set('value', comment.id) ;
    56 	CY.get("#"+gEdit['ids']['keyId']).set('value', comment.key) ;
    56   CY.get("#"+gEdit['ids']['keyId']).set('value', comment.key) ;
    57 
    57 
    58 	CY.get("#"+gEdit['ids']['changeScopeInputId']+" input").set('checked', false) ;
    58   CY.get("#"+gEdit['ids']['changeScopeInputId']+" input").set('checked', false) ;
    59 	if (comment.reply_to_id != null) 
    59   if (comment.reply_to_id != null) 
    60 		CY.get("#"+gEdit['ids']['changeScopeInputId']).addClass('displaynone')
    60     CY.get("#"+gEdit['ids']['changeScopeInputId']).addClass('displaynone')
    61 	changeScopeFormClick() ; // to adapt
    61   changeScopeFormClick() ; // to adapt
    62 
    62 
    63 	CY.get("#"+gEdit['ids']['nameInputId']).set('value', comment.name) ; 
    63   CY.get("#"+gEdit['ids']['nameInputId']).set('value', comment.name) ; 
    64 	CY.get("#"+gEdit['ids']['emailInputId']).set('value', comment.email) ; 
    64   CY.get("#"+gEdit['ids']['emailInputId']).set('value', comment.email) ; 
    65 
    65 
    66 	if (comment.logged_author) {
    66   if (comment.logged_author) {
    67 		CY.get("#"+gEdit['ids']['nameInputId']).setAttribute("disabled", true); 
    67     CY.get("#"+gEdit['ids']['nameInputId']).setAttribute("disabled", true); 
    68 		CY.get("#"+gEdit['ids']['emailInputId']).setAttribute("disabled", true);
    68     CY.get("#"+gEdit['ids']['emailInputId']).setAttribute("disabled", true);
    69 	}
    69   }
    70 	
    70   
    71 // FORM VALUES
    71 // FORM VALUES
    72 	CY.get("#"+gEdit['ids']['titleInputId']).set('value', comment['title']) ;
    72   CY.get("#"+gEdit['ids']['titleInputId']).set('value', comment['title']) ;
    73 	CY.get("#"+gEdit['ids']['contentInputId']).set('value', comment['content']) ;
    73   CY.get("#"+gEdit['ids']['contentInputId']).set('value', comment['content']) ;
    74 	CY.get("#"+gEdit['ids']['tagsInputId']).set('value', comment['tags']) ;
    74   CY.get("#"+gEdit['ids']['tagsInputId']).set('value', comment['tags']) ;
    75 	
    75   
    76 	CY.get("#"+gEdit['ids']['formatInputId']).set('value',gConf['defaultCommentFormat']) ;// for now ...
    76   CY.get("#"+gEdit['ids']['formatInputId']).set('value',gConf['defaultCommentFormat']) ;// for now ...
    77 	
    77   
    78 // WIDTH 	
    78 // WIDTH  
    79 	var width = gLayout.getTopICommentsWidth() ;
    79   var width = gLayout.getTopICommentsWidth() ;
    80 	changeFormFieldsWidth(gEdit['ids']['formId'], width) ;
    80   changeFormFieldsWidth(gEdit['ids']['formId'], width) ;
    81 	
    81   
    82 // ATTACH EVENT HANDLERS
    82 // ATTACH EVENT HANDLERS
    83 	gEdit['handlers']['addBtnId'] = CY.on("click", onEditSaveClick, "#"+gEdit['ids']['addBtnId']);
    83   gEdit['handlers']['addBtnId'] = CY.on("click", onEditSaveClick, "#"+gEdit['ids']['addBtnId']);
    84 	gEdit['handlers']['cancelBtnId'] = CY.on("click", onEditCancelClick, "#"+gEdit['ids']['cancelBtnId']);
    84   gEdit['handlers']['cancelBtnId'] = CY.on("click", onEditCancelClick, "#"+gEdit['ids']['cancelBtnId']);
    85 	gEdit['handlers']['changeScope'] = CY.on("click", onChangeScopeClick, "#"+gEdit['ids']['changeScopeInputId']);
    85   gEdit['handlers']['changeScope'] = CY.on("click", onChangeScopeClick, "#"+gEdit['ids']['changeScopeInputId']);
    86 	
    86   
    87 }
    87 }
    88 onEditSaveClick = function(iCommentHost) {
    88 onEditSaveClick = function(iCommentHost) {
    89 	if (readyForAction())
    89   if (readyForAction())
    90 		gSync.editComment() ;
    90     gSync.editComment() ;
    91 }
    91 }
    92 onEditCancelClick = function(iCommentHost) {
    92 onEditCancelClick = function(iCommentHost) {
    93 	if (readyForAction())
    93   if (readyForAction())
    94 		gSync.cancelEdit() ;
    94     gSync.cancelEdit() ;
    95 }
    95 }
    96 onChangeScopeClick = function() {
    96 onChangeScopeClick = function() {
    97 	if (readyForAction())
    97   if (readyForAction())
    98 		gSync.changeScopeFormClick() ;
    98     gSync.changeScopeFormClick() ;
    99 	else {// (onChangeScopeClick triggers an animation : checking for readyForAction does not prevent the checkbox change ...)
    99   else {// (onChangeScopeClick triggers an animation : checking for readyForAction does not prevent the checkbox change ...)
   100 		var chckCtrl = CY.get("#"+gEdit['ids']['changeScopeInputId']+" input") ;
   100     var chckCtrl = CY.get("#"+gEdit['ids']['changeScopeInputId']+" input") ;
   101 		var chck = chckCtrl.get('checked') ;
   101     var chck = chckCtrl.get('checked') ;
   102 		chckCtrl.set('checked', !chck) ; // set it back 
   102     chckCtrl.set('checked', !chck) ; // set it back 
   103 	}
   103   }
   104 }
   104 }
   105 changeScopeFormClick = function() {
   105 changeScopeFormClick = function() {
   106 	var node = CY.get("#"+gEdit['ids']['currentSelId']) ;
   106   var node = CY.get("#"+gEdit['ids']['currentSelId']) ;
   107 	if (CY.get("#"+gEdit['ids']['changeScopeInputId']+" input").get('checked'))
   107   if (CY.get("#"+gEdit['ids']['changeScopeInputId']+" input").get('checked'))
   108 		node.removeClass('displaynone') ;
   108     node.removeClass('displaynone') ;
   109 	else
   109   else
   110 		node.addClass('displaynone') ;
   110     node.addClass('displaynone') ;
   111 }
   111 }
   112 cancelEditForm = function() {
   112 cancelEditForm = function() {
   113 	if (gEditICommentHost != null) {
   113   if (gEditICommentHost != null) {
   114 // DETACH EVENT HANDLERS
   114 // DETACH EVENT HANDLERS
   115 		for (var id in gEdit['handlers']) {
   115     for (var id in gEdit['handlers']) {
   116 			if (gEdit['handlers'][id] != null) {
   116       if (gEdit['handlers'][id] != null) {
   117 				gEdit['handlers'][id].detach() ;
   117         gEdit['handlers'][id].detach() ;
   118 				gEdit['handlers'][id] = null ;
   118         gEdit['handlers'][id] = null ;
   119 			}
   119       }
   120 		}
   120     }
   121 
   121 
   122 // REMOVE EDIT FORM NODES FROM ICOMMENT OVERLAY
   122 // REMOVE EDIT FORM NODES FROM ICOMMENT OVERLAY
   123 		var node = gEditICommentHost['overlay'].get('contentBox').query(".icomment-edit-body") ;
   123     var node = gEditICommentHost['overlay'].get('contentBox').query(".icomment-edit-body") ;
   124 		node.get('parentNode').removeChild(node) ;
   124     node.get('parentNode').removeChild(node) ;
   125 		node = gEditICommentHost['overlay'].get('contentBox').query(".icomment-edit-header") ;
   125     node = gEditICommentHost['overlay'].get('contentBox').query(".icomment-edit-header") ;
   126 		node.get('parentNode').removeChild(node) ;
   126     node.get('parentNode').removeChild(node) ;
   127 
   127 
   128 // SHOW ICOMMENT OVERLAY
   128 // SHOW ICOMMENT OVERLAY
   129 		gEditICommentHost.showContent() ;
   129     gEditICommentHost.showContent() ;
   130 		
   130     
   131 		gEditICommentHost = null ;
   131     gEditICommentHost = null ;
   132 	}
   132   }
   133 }
   133 }