From e584b3affca83af4ec6100100659d908507d6ced Mon Sep 17 00:00:00 2001 From: Pierre Date: Sat, 27 Jan 2018 18:00:59 +0100 Subject: [PATCH] Perform a request to edit comment content. --- assets/js/components/comments/editor.js | 49 ++++++++++++++++++++++ assets/js/components/comments/interface.js | 21 ++++++++++ assets/js/components/comments/ui.js | 9 +++- system/config/dev.config.php | 1 + 4 files changed, 78 insertions(+), 2 deletions(-) create mode 100644 assets/js/components/comments/editor.js diff --git a/assets/js/components/comments/editor.js b/assets/js/components/comments/editor.js new file mode 100644 index 00000000..e1f00477 --- /dev/null +++ b/assets/js/components/comments/editor.js @@ -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 + ); + + } + +} \ No newline at end of file diff --git a/assets/js/components/comments/interface.js b/assets/js/components/comments/interface.js index 9ebe23bd..47f9d985 100644 --- a/assets/js/components/comments/interface.js +++ b/assets/js/components/comments/interface.js @@ -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 * diff --git a/assets/js/components/comments/ui.js b/assets/js/components/comments/ui.js index 1b021d6e..23e8cc23 100644 --- a/assets/js/components/comments/ui.js +++ b/assets/js/components/comments/ui.js @@ -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 diff --git a/system/config/dev.config.php b/system/config/dev.config.php index 9d6218ca..fbfc1cb0 100644 --- a/system/config/dev.config.php +++ b/system/config/dev.config.php @@ -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