mirror of
https://github.com/pierre42100/ComunicWeb
synced 2024-12-24 01:48:50 +00:00
Perform a request to edit comment content.
This commit is contained in:
parent
45dc5ec4fc
commit
e584b3affc
49
assets/js/components/comments/editor.js
Normal file
49
assets/js/components/comments/editor.js
Normal 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
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -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
|
||||
*
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user