mirror of
https://github.com/pierre42100/ComunicWeb
synced 2024-12-24 18:08:50 +00:00
Make request to create comment.
This commit is contained in:
parent
2d883a4197
commit
cdfbbc6c59
@ -33,9 +33,11 @@ ComunicWeb.components.comments.form = {
|
||||
type: "input",
|
||||
elemType: "text",
|
||||
class: "form-control",
|
||||
placeholder: "New comment..."
|
||||
placeholder: "New comment...",
|
||||
name: "content"
|
||||
});
|
||||
|
||||
|
||||
//Add button group
|
||||
var buttonsGroup = createElem2({
|
||||
appendTo: inputGroup,
|
||||
@ -53,7 +55,8 @@ ComunicWeb.components.comments.form = {
|
||||
var imageFile = createElem2({
|
||||
appendTo: addImageLabel,
|
||||
type: "input",
|
||||
elemType: "file"
|
||||
elemType: "file",
|
||||
name: "image"
|
||||
});
|
||||
|
||||
var imageButton = createElem2({
|
||||
@ -73,7 +76,36 @@ ComunicWeb.components.comments.form = {
|
||||
|
||||
//Catch form when submitted
|
||||
commentForm.onsubmit = function(){
|
||||
alert("Send !");
|
||||
|
||||
//Check for image
|
||||
var hasImage = imageFile.files.length > 0;
|
||||
|
||||
//Check the comment
|
||||
if(!hasImage && newCommentText.value < 5){
|
||||
ComunicWeb.common.notificationSystem.showNotification("Please type a valid comment! (at least 5 characters)", "danger");
|
||||
return false;
|
||||
}
|
||||
|
||||
//Lock send button
|
||||
sendButton.disabled = true;
|
||||
|
||||
//Try to create the comment
|
||||
var formData = new FormData(commentForm);
|
||||
ComunicWeb.components.comments.interface.create(postID, formData, function(result){
|
||||
|
||||
//Unlock send button
|
||||
sendButton.disabled = false;
|
||||
|
||||
//Check for errors
|
||||
if(result.error){
|
||||
ComunicWeb.common.notificationSystem.showNotification("Couldn't create comment! (check its content)", "danger");
|
||||
return;
|
||||
}
|
||||
|
||||
//Perform next actions
|
||||
});
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
},
|
||||
|
@ -6,6 +6,24 @@
|
||||
|
||||
ComunicWeb.components.comments.interface = {
|
||||
|
||||
/**
|
||||
* Create a new comment
|
||||
*
|
||||
* @param {number} postID The ID of the target post
|
||||
* @param {FormData} data The data of the new comment
|
||||
* @param {function} callback
|
||||
*/
|
||||
create: function(postID, data, callback){
|
||||
|
||||
//Prepare the request
|
||||
var apiURI = "comments/create";
|
||||
data.append("postID", postID);
|
||||
|
||||
//Make it
|
||||
ComunicWeb.common.api.makeFormDatarequest(apiURI, data, true, callback);
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Get informations about a single comment
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user