Perform a request to edit comment content.

This commit is contained in:
Pierre 2018-01-27 18:00:59 +01:00
parent 45dc5ec4fc
commit e584b3affc
4 changed files with 78 additions and 2 deletions

View File

@ -0,0 +1,49 @@
/**
* Comments editor
*
* @author Pierre HUBERT
*/
ComunicWeb.components.comments.editor = {
/**
* Open the comments editor
*
* @param {Object} infos Informations about the comment to edit
* @param {HTMLElement} root Comment root element
*/
open: function(infos, root){
//Prepare input callback
var inputCallback = function(result){
//Check if edition was cancelled
if(!result)
return;
//Try to update comment content
ComunicWeb.components.comments.interface.edit(infos.ID, result, function(result){
//Check for error
if(result.error){
ComunicWeb.common.notificationSystem.showNotification("An error occured while trying to update comment content !", "danger");
return;
}
//Else perform next actions
});
}
//Prompt the user to enter the new content of the comment
ComunicWeb.common.messages.inputString(
"Edit comment content",
"Please specify the new content of the comment: ",
infos.content,
inputCallback
);
}
}

View File

@ -6,6 +6,27 @@
ComunicWeb.components.comments.interface = {
/**
* Update a comment content
*
* @param {number} commentID The ID of the comment to update
* @param {string} content The new content of the comment
* @param {function} callback
*/
edit: function(commentID, content, callback){
//Perform a request on the API
var apiURI = "comments/edit";
var params = {
commentID: commentID,
content: content
};
//Make the request
ComunicWeb.common.api.makeAPIrequest(apiURI, params, true, callback);
},
/**
* Delete a comment
*

View File

@ -121,13 +121,18 @@ ComunicWeb.components.comments.ui = {
});
createElem2({
appendTo: deleteCommentLink,
appendTo: editCommentLink,
type: "i",
class: "fa fa-edit"
});
//Make edit button lives
//Open in editor (separate file)
editCommentLink.onclick = function(){
//Open comment editor
ComunicWeb.components.comments.editor.open(infos, commentContener);
}
//Create a button to delete the comment

View File

@ -233,6 +233,7 @@ class Dev {
//Comments component
"js/components/comments/ui.js",
"js/components/comments/interface.js",
"js/components/comments/editor.js",
"js/components/comments/utils.js",
//Modern textarea handler