From 1d92a5bf1c80cc4823828ac06a715d8544737528 Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Wed, 4 Jul 2018 14:07:16 +0200 Subject: [PATCH] Can send a request on the API to delete group logo. --- assets/css/pages/groups/pages/settings.css | 1 + assets/js/components/groups/interface.js | 17 +++++++++- assets/js/pages/groups/pages/settings.js | 38 ++++++++++++++++++++++ 3 files changed, 55 insertions(+), 1 deletion(-) diff --git a/assets/css/pages/groups/pages/settings.css b/assets/css/pages/groups/pages/settings.css index ffef42c6..e4d4c6e0 100644 --- a/assets/css/pages/groups/pages/settings.css +++ b/assets/css/pages/groups/pages/settings.css @@ -27,5 +27,6 @@ .group-settings-container .group-logo-settings-img { width: 150px; margin: auto; + margin-bottom: 10px; display: block; } \ No newline at end of file diff --git a/assets/js/components/groups/interface.js b/assets/js/components/groups/interface.js index 3f3b753c..ba50ae7d 100644 --- a/assets/js/components/groups/interface.js +++ b/assets/js/components/groups/interface.js @@ -95,6 +95,21 @@ ComunicWeb.components.groups.interface = { var apiURI = "groups/upload_logo"; data.append("id", id); ComunicWeb.common.api.makeFormDatarequest(apiURI, data, true, callback); - } + }, + + /** + * Delete user logo + * + * @param {Number} id The ID of the target group + * @param {Function} callback + */ + deleteLogo: function(id, callback){ + //Perform the request over the API + var apiURI = "groups/delete_logo"; + var params = { + id: id + }; + ComunicWeb.common.api.makeAPIrequest(apiURI, params, true, callback); + }, }; \ No newline at end of file diff --git a/assets/js/pages/groups/pages/settings.js b/assets/js/pages/groups/pages/settings.js index 787896fa..b9207962 100644 --- a/assets/js/pages/groups/pages/settings.js +++ b/assets/js/pages/groups/pages/settings.js @@ -192,6 +192,7 @@ ComunicWeb.pages.groups.pages.settings = { src: settings.icon_url }); + //Add a button to update the group logo var updateGroupLogoLabel = createElem2({ appendTo: groupLogoSettingsContainer, @@ -236,5 +237,42 @@ ComunicWeb.pages.groups.pages.settings = { }); }); + + + //Add a button to delete the account image + add_space(groupLogoSettingsContainer); + var deleteLogoBtn = createElem2({ + appendTo: groupLogoSettingsContainer, + type: "div", + class: "btn btn-sm btn-danger", + innerHTML: "Delete logo" + }); + deleteLogoBtn.addEventListener("click", function(e){ + + //Ask user confirmation + ComunicWeb.common.messages.confirm("Do you really want to delete group logo ? This operation can not be reverted !", function(c){ + + //Check if the user rejected the request + if(!c) return; + + //Forward the request on the server + ComunicWeb.components.groups.interface.deleteLogo(id, function(result){ + + //Check for errors + if(result.error) + return notify("An error occurred while trying to delete group logo!", "danger"); + + //Success + notify("The group logo has been successfully deleted!", "success"); + + //Apply new group logo + groupLogo.src = result.url; + + }); + + + }); + + }); }, } \ No newline at end of file