From b67f3b055f02e0cce0c01c2851b3b5039f0305c7 Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Tue, 10 Jul 2018 08:15:44 +0200 Subject: [PATCH] Can request membership level update. --- assets/js/components/groups/interface.js | 19 +++++++ assets/js/pages/groups/pages/members.js | 66 +++++++++++++++++++++++- 2 files changed, 84 insertions(+), 1 deletion(-) diff --git a/assets/js/components/groups/interface.js b/assets/js/components/groups/interface.js index 39024f08..48ad8ce5 100644 --- a/assets/js/components/groups/interface.js +++ b/assets/js/components/groups/interface.js @@ -243,4 +243,23 @@ ComunicWeb.components.groups.interface = { }; ComunicWeb.common.api.makeAPIrequest(apiURI, params, true, callback); }, + + /** + * Update the membership of a user + * + * @param {Number} groupID The ID of the target group + * @param {Number} userID The ID of the target user + * @param {String} level The new membership level for the user + * @param {Function} callback + */ + updateMembership: function(groupID, userID, level, callback){ + //Perform the request over the API + var apiURI = "groups/update_membership_level"; + var params = { + groupID: groupID, + userID: userID, + level: level + }; + ComunicWeb.common.api.makeAPIrequest(apiURI, params, true, callback); + }, }; \ No newline at end of file diff --git a/assets/js/pages/groups/pages/members.js b/assets/js/pages/groups/pages/members.js index e9da877a..d7993b36 100644 --- a/assets/js/pages/groups/pages/members.js +++ b/assets/js/pages/groups/pages/members.js @@ -225,8 +225,13 @@ ComunicWeb.pages.groups.pages.members = { invited: "Invited", pending: "Requested" }; - var membershipLevelButton = createElem2({ + var membershipChooseContainer = createElem2({ appendTo: memberContainer, + type: "div", + class: "btn-group" + }); + var membershipLevelButton = createElem2({ + appendTo: membershipChooseContainer, type: "button", class: "btn btn-default dropdown-toggle btn-membership-level", type: "button", @@ -338,5 +343,64 @@ ComunicWeb.pages.groups.pages.members = { }); } + //Manage other levels + else if(info.membership == "administrator" && userID() != userInfo.userID) { + + //Add dropdown attribute to the button + membershipLevelButton.setAttribute("data-toggle", "dropdown"); + + var membershipDropdown = createElem2({ + appendTo: membershipChooseContainer, + type: "ul", + class: "dropdown-menu" + }); + + /** + * Add an option to membership dropdown menu + * + * @param {String} name The name of the option to add + */ + var addOption = function(name){ + + //Create element + var elemLi = createElem2({ + appendTo: membershipDropdown, + type: "li" + }); + + //Add link + var elemLink = createElem2({ + appendTo: elemLi, + type: "a" + }); + + //Add option name + createElem2({ + appendTo: elemLink, + type: "span", + innerHTML: membershipLevels[name] + }); + + //Make the option lives + elemLi.addEventListener("click", function(e){ + + //Perform a request over the API + ComunicWeb.components.groups.interface.updateMembership(info.id, userInfo.userID, name, function(result){ + + //Check for error + if(result.error) + return notify("An error occurred while trying to update the membership of this user!", "danger"); + + //Display new membership + membershipLevelButton.innerHTML = membershipLevels[name]; + }); + + }); + }; + + addOption("administrator"); + addOption("moderator"); + addOption("member"); + } } } \ No newline at end of file