mirror of
				https://github.com/pierre42100/ComunicWeb
				synced 2025-11-04 04:04:20 +00:00 
			
		
		
		
	Create comments form.
This commit is contained in:
		
							
								
								
									
										81
									
								
								assets/js/components/comments/form.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										81
									
								
								assets/js/components/comments/form.js
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,81 @@
 | 
			
		||||
/**
 | 
			
		||||
 * Comments form
 | 
			
		||||
 * 
 | 
			
		||||
 * @author Pierre HUBERT
 | 
			
		||||
 */
 | 
			
		||||
ComunicWeb.components.comments.form = {
 | 
			
		||||
	
 | 
			
		||||
	/**
 | 
			
		||||
	 * Display comments creation form
 | 
			
		||||
	 * 
 | 
			
		||||
	 * @param {number} postID The ID of the target post
 | 
			
		||||
	 * @param {HTMLElement} target The target for the form
 | 
			
		||||
	 */
 | 
			
		||||
	display: function(postID, target){
 | 
			
		||||
		
 | 
			
		||||
		//Create form contener
 | 
			
		||||
		var commentForm = createElem2({
 | 
			
		||||
			appendTo: target,
 | 
			
		||||
			type: "form",
 | 
			
		||||
			class: "comment-creation-form"
 | 
			
		||||
		});
 | 
			
		||||
 | 
			
		||||
		//Create input group
 | 
			
		||||
		var inputGroup = createElem2({
 | 
			
		||||
			appendTo: commentForm,
 | 
			
		||||
			type: "div",
 | 
			
		||||
			class: "input-group input-group-sm"
 | 
			
		||||
		});
 | 
			
		||||
 | 
			
		||||
		//Add text input
 | 
			
		||||
		var newCommentText = createElem2({
 | 
			
		||||
			appendTo: inputGroup,
 | 
			
		||||
			type: "input",
 | 
			
		||||
			elemType: "text",
 | 
			
		||||
			class: "form-control",
 | 
			
		||||
			placeholder: "New comment..."
 | 
			
		||||
		});
 | 
			
		||||
 | 
			
		||||
		//Add button group
 | 
			
		||||
		var buttonsGroup = createElem2({
 | 
			
		||||
			appendTo: inputGroup,
 | 
			
		||||
			type: "span",
 | 
			
		||||
			class: "input-group-btn"
 | 
			
		||||
		});
 | 
			
		||||
 | 
			
		||||
		//Add image pick button
 | 
			
		||||
		var addImageLabel = createElem2({
 | 
			
		||||
			appendTo: buttonsGroup,
 | 
			
		||||
			type: "label",
 | 
			
		||||
			class: "comment-image-select"
 | 
			
		||||
		});
 | 
			
		||||
 | 
			
		||||
		var imageFile = createElem2({
 | 
			
		||||
			appendTo: addImageLabel,
 | 
			
		||||
			type: "input",
 | 
			
		||||
			elemType: "file"
 | 
			
		||||
		});
 | 
			
		||||
 | 
			
		||||
		var imageButton = createElem2({
 | 
			
		||||
			appendTo: addImageLabel,
 | 
			
		||||
			type: "a",
 | 
			
		||||
			class: "btn btn-flat",
 | 
			
		||||
			innerHTML: "<i class='fa fa-picture-o'></i>"
 | 
			
		||||
		})
 | 
			
		||||
 | 
			
		||||
		//Add send button
 | 
			
		||||
		var sendButton = createElem2({
 | 
			
		||||
			appendTo: buttonsGroup,
 | 
			
		||||
			type: "button",
 | 
			
		||||
			class: "btn btn-default btn-flat",
 | 
			
		||||
			innerHTML: "Send"
 | 
			
		||||
		});
 | 
			
		||||
 | 
			
		||||
		//Catch form when submitted
 | 
			
		||||
		commentForm.onsubmit = function(){
 | 
			
		||||
			alert("Send !");
 | 
			
		||||
			return false;
 | 
			
		||||
		}
 | 
			
		||||
	},
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -55,6 +55,11 @@ ComunicWeb.components.comments.ui = {
 | 
			
		||||
			this._show_comment(infos[i], usersInfos['user-' + infos[i].userID], contener);
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		//Add comment creation form (if possible)
 | 
			
		||||
		if(signed_in()){
 | 
			
		||||
			ComunicWeb.components.comments.form.display(postID, contener)
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
	},
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user