mirror of
https://github.com/pierre42100/ComunicWeb
synced 2024-12-24 01:48:50 +00:00
Can request membership level update.
This commit is contained in:
parent
1d88b8ea69
commit
b67f3b055f
@ -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);
|
||||
},
|
||||
};
|
@ -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");
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user