diff --git a/assets/css/pages/groups/pages/settings.css b/assets/css/pages/groups/pages/settings.css index 7574d8fa..46dd9f1e 100644 --- a/assets/css/pages/groups/pages/settings.css +++ b/assets/css/pages/groups/pages/settings.css @@ -7,12 +7,6 @@ .group-settings-container { float: none; margin: auto; - margin-top: 40px; -} - -.group-settings-container .title { - text-align: center; - margin-bottom: 15px; } .group-settings-container .separated-block { diff --git a/assets/js/components/groups/interface.js b/assets/js/components/groups/interface.js index 7ca30c31..7f3c87f5 100644 --- a/assets/js/components/groups/interface.js +++ b/assets/js/components/groups/interface.js @@ -98,15 +98,10 @@ const GroupsInterface = { * Get the settings of a group * * @param {Number} id The ID of the target group - * @param {Function} callback + * @return {Promise} */ - getSettings: function(id, callback){ - //Perform the request over the API - var apiURI = "groups/get_settings"; - var params = { - id: id - }; - ComunicWeb.common.api.makeAPIrequest(apiURI, params, true, callback); + getSettings: async function(id){ + return await api("groups/get_settings", {id: id}, true); }, /** diff --git a/assets/js/pages/groups/main.js b/assets/js/pages/groups/main.js index 79d93129..3cf805fa 100644 --- a/assets/js/pages/groups/main.js +++ b/assets/js/pages/groups/main.js @@ -99,6 +99,10 @@ const GroupsPage = { case "members": GroupMembersSection.display(group, target) return; + + case "settings": + await GroupSettingsPage.display(group.id, target); + return; default: ComunicWeb.common.error.pageNotFound(null, target); diff --git a/assets/js/pages/groups/pages/settings.js b/assets/js/pages/groups/pages/settings.js index fbbfb532..168258fb 100644 --- a/assets/js/pages/groups/pages/settings.js +++ b/assets/js/pages/groups/pages/settings.js @@ -4,99 +4,45 @@ * @author Pierre HUBERT */ -ComunicWeb.pages.groups.pages.settings = { - - /** - * Open group settings page - * - * @param {Number} id The ID of the settings page - * @param {HTMLElement} target The target of the page - */ - open: function(id, target){ - - //Create settings container - var settingsContainer = createElem2({ - appendTo: target, - type: "div", - class: "group-settings-container col-md-6" - }); - - //Add backward link - var backwardLink = createElem2({ - appendTo: settingsContainer, - type: "div", - class: "a", - innerHTML: " Go back to the group" - }); - backwardLink.addEventListener("click", function(e){ - openPage("groups/" + id); - }); - - //Add title - createElem2({ - appendTo: settingsContainer, - type: "h2", - class: "title", - innerHTML: "Group settings" - }); - - //Display loading message - var loadingMsg = ComunicWeb.common.messages.createCalloutElem( - "Loading", - "Please wait while we retrieve the settings of the page...", - "info"); - settingsContainer.appendChild(loadingMsg); - - //Get the settings of the page - ComunicWeb.components.groups.interface.getSettings(id, function(result){ - - //Remove loading message - loadingMsg.remove(); - - //Check for error - if(result.error){ - - //Check if the user is not authorized to access the page - if(result.error.code == 401){ - //The user is not authorized to see this page - settingsContainer.appendChild(ComunicWeb.common.messages.createCalloutElem( - "Access forbidden", - "You are not authorized to access these information !", - "danger" - )); - } - - //Else the page was not found - else { - settingsContainer.remove(); - ComunicWeb.common.error.pageNotFound({}, target); - } - - } - - else { - //Display settings pages - ComunicWeb.pages.groups.pages.settings.display(id, result, settingsContainer); - } - - }); - - }, +const GroupSettingsPage = { /** * Display page settings * * @param {Number} id The ID of the target page - * @param {Object} settings The settings of the page * @param {HTMLElement} target The target of the page */ - display: function(id, settings, target){ + display: async function(id, target){ + + + //Create settings container + const settingsPage = createElem2({ + appendTo: target, + type: "div", + class: "group-settings-container col-md-6", + innerHTML: "

"+tr("Group settings")+"

" + }) + + const settingsBox = settingsPage.querySelector(".box-body"); + + //Display loading message + var loadingMsg = ComunicWeb.common.messages.createCalloutElem( + tr("Loading"), + tr("Please wait while we retrieve the settings of the page..."), + "info" + ); + settingsBox.appendChild(loadingMsg); + + //Get the settings of the page + const settings = await GroupsInterface.getSettings(id); + + loadingMsg.remove(); ComunicWeb.common.pageTitle.setTitle(settings.name + " - Settings"); //Create form container var formContainer = createElem2({ - appendTo: target, + appendTo: settingsBox, type: "div", class: "group-settings-form" }); @@ -575,4 +521,6 @@ ComunicWeb.pages.groups.pages.settings = { }); } -} \ No newline at end of file +} + +ComunicWeb.pages.groups.pages.settings = GroupSettingsPage; \ No newline at end of file diff --git a/assets/js/typings/Group.d.ts b/assets/js/typings/Group.d.ts index 6960294e..a248f000 100644 --- a/assets/js/typings/Group.d.ts +++ b/assets/js/typings/Group.d.ts @@ -23,4 +23,6 @@ declare interface AdvancedGroupInfo extends Group { url: String, number_likes: Number, is_liking: Boolean -} \ No newline at end of file +} + +declare interface GroupSettings extends AdvancedGroupInfo {} \ No newline at end of file diff --git a/assets/templates/pages/groups/sections/GroupTabs.html b/assets/templates/pages/groups/sections/GroupTabs.html index 770ba1ba..abf43ebb 100644 --- a/assets/templates/pages/groups/sections/GroupTabs.html +++ b/assets/templates/pages/groups/sections/GroupTabs.html @@ -7,7 +7,7 @@
  • tr("Posts")
  • tr("Members")
  • tr("About")
  • -
  • +
  • \ No newline at end of file