From 5a62f6206f481afe382d3efe488daa6b136a6b90 Mon Sep 17 00:00:00 2001 From: Pierre Date: Sat, 27 Jan 2018 18:49:05 +0100 Subject: [PATCH] Can reload a single comment --- assets/js/common/functionsSchema.js | 7 ++++ assets/js/components/comments/actions.js | 40 ++++++++++++++++++++ assets/js/components/comments/editor.js | 3 +- assets/js/components/comments/ui.js | 47 +++++++++++++++++++++--- system/config/dev.config.php | 1 + 5 files changed, 91 insertions(+), 7 deletions(-) create mode 100644 assets/js/components/comments/actions.js diff --git a/assets/js/common/functionsSchema.js b/assets/js/common/functionsSchema.js index 548ea415..31edf830 100644 --- a/assets/js/common/functionsSchema.js +++ b/assets/js/common/functionsSchema.js @@ -717,6 +717,13 @@ var ComunicWeb = { //TODO : implement }, + /** + * Comment actions + */ + actions: { + //TODO : implement + }, + /** * Comments interface */ diff --git a/assets/js/components/comments/actions.js b/assets/js/components/comments/actions.js new file mode 100644 index 00000000..a7b3aa3c --- /dev/null +++ b/assets/js/components/comments/actions.js @@ -0,0 +1,40 @@ +/** + * Comments actions + * + * @author Pierre HUBERT + */ + +ComunicWeb.components.comments.actions = { + + /** + * Reload a single comment + * + * @param {number} commentID The ID of the comment to reload + * @param {HTMLElement} target The target of the reloaded comment + */ + reload: function(commentID, target){ + + //Hide the comment to reload + target.style.visibility = "hidden"; + + //Get informations about the comment on the API server + ComunicWeb.components.comments.interface.get_single(commentID, function(result){ + + //Display again the comment to update + target.style.visibility = "visible"; + + //Check for errors + if(result.error){ + ComunicWeb.common.notificationSystem.showNotification("Couldn't get informations about a comment !", "danger"); + return; + } + + //Apply new informations about the comment + //Display new comment informations + ComunicWeb.components.comments.ui.display_comment(result, target); + + }); + + } + +}; \ No newline at end of file diff --git a/assets/js/components/comments/editor.js b/assets/js/components/comments/editor.js index e1f00477..915c6bbe 100644 --- a/assets/js/components/comments/editor.js +++ b/assets/js/components/comments/editor.js @@ -31,7 +31,8 @@ ComunicWeb.components.comments.editor = { } //Else perform next actions - + //Reload the comment + ComunicWeb.components.comments.actions.reload(infos.ID, root); }); } diff --git a/assets/js/components/comments/ui.js b/assets/js/components/comments/ui.js index 23e8cc23..38d34d06 100644 --- a/assets/js/components/comments/ui.js +++ b/assets/js/components/comments/ui.js @@ -57,6 +57,30 @@ ComunicWeb.components.comments.ui = { }, + /** + * Display a single comment + * + * @param {Object} infos Informations about the comment to display + * @param {HTMLElement} target The target for the comment + */ + display_comment: function(infos, target){ + + //Get informations about the user + ComunicWeb.user.userInfos.getUserInfos(infos.userID, function(result){ + + //Check for errors + if(result.error){ + ComunicWeb.common.notificationSystem.showNotification("Couldn't get informations about a user!", "danger"); + return; + } + + //Display the comment + ComunicWeb.components.comments.ui._show_comment(infos, result, target); + + }); + + }, + /** * Show a comment * @@ -66,12 +90,23 @@ ComunicWeb.components.comments.ui = { */ _show_comment: function(infos, user, target){ - //Create comment contener - var commentContener = createElem2({ - appendTo: target, - type: "div", - class: "box-comment" - }); + //Create comment contener (if required) + if(target.className != "box-comment"){ + + var commentContener = createElem2({ + appendTo: target, + type: "div", + class: "box-comment" + }); + + } + + //Empty comment contener + else { + emptyElem(target); + var commentContener = target; + } + //Add user image createElem2({ diff --git a/system/config/dev.config.php b/system/config/dev.config.php index fbfc1cb0..8e66219d 100644 --- a/system/config/dev.config.php +++ b/system/config/dev.config.php @@ -232,6 +232,7 @@ class Dev { //Comments component "js/components/comments/ui.js", + "js/components/comments/actions.js", "js/components/comments/interface.js", "js/components/comments/editor.js", "js/components/comments/utils.js",