mirror of
https://github.com/pierre42100/ComunicWeb
synced 2025-02-17 03:12:43 +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 = {
|
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
|
* Delete a comment
|
||||||
*
|
*
|
||||||
|
@ -121,13 +121,18 @@ ComunicWeb.components.comments.ui = {
|
|||||||
});
|
});
|
||||||
|
|
||||||
createElem2({
|
createElem2({
|
||||||
appendTo: deleteCommentLink,
|
appendTo: editCommentLink,
|
||||||
type: "i",
|
type: "i",
|
||||||
class: "fa fa-edit"
|
class: "fa fa-edit"
|
||||||
});
|
});
|
||||||
|
|
||||||
//Make edit button lives
|
//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
|
//Create a button to delete the comment
|
||||||
|
@ -233,6 +233,7 @@ class Dev {
|
|||||||
//Comments component
|
//Comments component
|
||||||
"js/components/comments/ui.js",
|
"js/components/comments/ui.js",
|
||||||
"js/components/comments/interface.js",
|
"js/components/comments/interface.js",
|
||||||
|
"js/components/comments/editor.js",
|
||||||
"js/components/comments/utils.js",
|
"js/components/comments/utils.js",
|
||||||
|
|
||||||
//Modern textarea handler
|
//Modern textarea handler
|
||||||
|
Loading…
x
Reference in New Issue
Block a user