mirror of
https://github.com/pierre42100/ComunicWeb
synced 2024-11-22 20:19:21 +00:00
Can respond to membership requests
This commit is contained in:
parent
c9d0a597f5
commit
d541506820
@ -45,3 +45,11 @@
|
|||||||
.group-members-page .member .delete-link:active {
|
.group-members-page .member .delete-link:active {
|
||||||
color: #3c8dbc;
|
color: #3c8dbc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.group-members-page .member .delete-link {
|
||||||
|
width: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.group-members-page .member .btn-membership-level {
|
||||||
|
width: 130px;;
|
||||||
|
}
|
@ -175,6 +175,23 @@ ComunicWeb.components.groups.interface = {
|
|||||||
ComunicWeb.common.api.makeAPIrequest(apiURI, params, true, callback);
|
ComunicWeb.common.api.makeAPIrequest(apiURI, params, true, callback);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get information about a single user membership
|
||||||
|
*
|
||||||
|
* @param {Number} userID The ID of the target user
|
||||||
|
* @param {Number} groupID The ID of the target group
|
||||||
|
* @param {Function} callback The result
|
||||||
|
*/
|
||||||
|
getMembership: function(userID, groupID, callback){
|
||||||
|
//Perform the request over the API
|
||||||
|
var apiURI = "groups/get_membership";
|
||||||
|
var params = {
|
||||||
|
groupID: groupID,
|
||||||
|
userID: userID
|
||||||
|
};
|
||||||
|
ComunicWeb.common.api.makeAPIrequest(apiURI, params, true, callback);
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove (delete) a member from the group
|
* Remove (delete) a member from the group
|
||||||
*
|
*
|
||||||
@ -190,5 +207,23 @@ ComunicWeb.components.groups.interface = {
|
|||||||
userID: userID
|
userID: userID
|
||||||
};
|
};
|
||||||
ComunicWeb.common.api.makeAPIrequest(apiURI, params, true, callback);
|
ComunicWeb.common.api.makeAPIrequest(apiURI, params, true, callback);
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Respond to a membership request
|
||||||
|
*
|
||||||
|
* @param {Number} groupID The ID of the target group
|
||||||
|
* @param {Number} userID The ID of the target user
|
||||||
|
* @param {Boolean} accept Specify whether the request is accepted or not
|
||||||
|
*/
|
||||||
|
respondRequest: function(groupID, userID, accept, callback){
|
||||||
|
//Perform the request over the API
|
||||||
|
var apiURI = "groups/respond_request";
|
||||||
|
var params = {
|
||||||
|
groupID: groupID,
|
||||||
|
userID: userID,
|
||||||
|
accept: accept
|
||||||
|
};
|
||||||
|
ComunicWeb.common.api.makeAPIrequest(apiURI, params, true, callback);
|
||||||
}
|
}
|
||||||
};
|
};
|
@ -131,17 +131,36 @@ ComunicWeb.pages.groups.pages.members = {
|
|||||||
class: "members-list"
|
class: "members-list"
|
||||||
});
|
});
|
||||||
|
|
||||||
|
//Process the list of members
|
||||||
list.forEach(function(member){
|
list.forEach(function(member){
|
||||||
|
ComunicWeb.pages.groups.pages.members._display_member(info, member, users, membersList);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Display a single membership information
|
||||||
|
*
|
||||||
|
* @param {Object} info Information about the group
|
||||||
|
* @param {Object} member Information about the membership
|
||||||
|
* @param {Object} users The list of users of the group
|
||||||
|
* @param {HTMLElement} target The target for the list
|
||||||
|
*/
|
||||||
|
_display_member: function(info, member, users, target){
|
||||||
|
|
||||||
//Fetch user information
|
//Fetch user information
|
||||||
var userInfo = users["user-" + member.user_id];
|
var userInfo = users["user-" + member.user_id];
|
||||||
|
|
||||||
//Create member container
|
//Create member container (if required)
|
||||||
|
if(target.className != "member")
|
||||||
var memberContainer = createElem2({
|
var memberContainer = createElem2({
|
||||||
appendTo: membersList,
|
appendTo: target,
|
||||||
type: "div",
|
type: "div",
|
||||||
class: "member"
|
class: "member"
|
||||||
});
|
});
|
||||||
|
else {
|
||||||
|
emptyElem(target);
|
||||||
|
var memberContainer = target;
|
||||||
|
}
|
||||||
|
|
||||||
//User account image and name
|
//User account image and name
|
||||||
createElem2({
|
createElem2({
|
||||||
@ -159,8 +178,6 @@ ComunicWeb.pages.groups.pages.members = {
|
|||||||
});
|
});
|
||||||
|
|
||||||
//Add an option to delete the member
|
//Add an option to delete the member
|
||||||
if(userID() != userInfo.userID){
|
|
||||||
|
|
||||||
//Delete user button
|
//Delete user button
|
||||||
var deleteUserButton = createElem2({
|
var deleteUserButton = createElem2({
|
||||||
appendTo: memberContainer,
|
appendTo: memberContainer,
|
||||||
@ -168,6 +185,7 @@ ComunicWeb.pages.groups.pages.members = {
|
|||||||
class: "delete-link",
|
class: "delete-link",
|
||||||
innerHTML: "<i class='fa fa-trash'></i>"
|
innerHTML: "<i class='fa fa-trash'></i>"
|
||||||
});
|
});
|
||||||
|
if(userID() != userInfo.userID){
|
||||||
|
|
||||||
deleteUserButton.addEventListener("click", function(e){
|
deleteUserButton.addEventListener("click", function(e){
|
||||||
|
|
||||||
@ -196,6 +214,95 @@ ComunicWeb.pages.groups.pages.members = {
|
|||||||
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
deleteUserButton.style.visibility = "hidden";
|
||||||
|
|
||||||
|
//Display user membership level
|
||||||
|
var membershipLevels = {
|
||||||
|
administrator: "Administrator",
|
||||||
|
moderator: "Moderator",
|
||||||
|
member: "Member",
|
||||||
|
invited: "Invited",
|
||||||
|
pending: "Requested"
|
||||||
|
};
|
||||||
|
var membershipLevelButton = createElem2({
|
||||||
|
appendTo: memberContainer,
|
||||||
|
type: "button",
|
||||||
|
class: "btn btn-default dropdown-toggle btn-membership-level",
|
||||||
|
type: "button",
|
||||||
|
innerHTML: membershipLevels[member.level]
|
||||||
|
});
|
||||||
|
add_space(memberContainer);
|
||||||
|
|
||||||
|
//Check if the user is pending
|
||||||
|
if(member.level == "pending"){
|
||||||
|
|
||||||
|
//Disable membership level button
|
||||||
|
membershipLevelButton.style.display = true;
|
||||||
|
|
||||||
|
//Create container
|
||||||
|
var responseContainer = createElem2({
|
||||||
|
appendTo: memberContainer,
|
||||||
|
type: "div"
|
||||||
|
});
|
||||||
|
|
||||||
|
//Offer the moderator to accept or not the request
|
||||||
|
var acceptRequest = createElem2({
|
||||||
|
appendTo: responseContainer,
|
||||||
|
type: "div",
|
||||||
|
class: "btn btn-success",
|
||||||
|
innerHTML: "Accept"
|
||||||
|
});
|
||||||
|
add_space(responseContainer);
|
||||||
|
var rejectRequest = createElem2({
|
||||||
|
appendTo: responseContainer,
|
||||||
|
type: "div",
|
||||||
|
class: "btn btn-danger",
|
||||||
|
innerHTML: "Reject"
|
||||||
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Respond to user request
|
||||||
|
*
|
||||||
|
* @param {Boolean} accept Specify whether the request was accepted or not
|
||||||
|
*/
|
||||||
|
var respondRequest = function(accept){
|
||||||
|
|
||||||
|
//Hide response area
|
||||||
|
responseContainer.style.visibility = "hidden";
|
||||||
|
|
||||||
|
//Perform the request on the API
|
||||||
|
ComunicWeb.components.groups.interface.respondRequest(info.id, userInfo.userID, accept, function(result){
|
||||||
|
|
||||||
|
//Check for errors
|
||||||
|
if(result.error){
|
||||||
|
responseContainer.style.visibility = "visible";
|
||||||
|
return notify("An error occurred while trying to respond to the request!", "danger");
|
||||||
|
}
|
||||||
|
|
||||||
|
//If the response was to reject the request, remove the user from the list
|
||||||
|
if(!accept)
|
||||||
|
memberContainer.remove();
|
||||||
|
else {
|
||||||
|
|
||||||
|
ComunicWeb.components.groups.interface.getMembership(userInfo.userID, info.id, function(member){
|
||||||
|
|
||||||
|
//Check for errors
|
||||||
|
if(member.error)
|
||||||
|
return notify("Could not refresh membership information!", "danger");
|
||||||
|
|
||||||
|
//Apply new membership information
|
||||||
|
ComunicWeb.pages.groups.pages.members._display_member(info, member, users, memberContainer);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//Make the buttons lives
|
||||||
|
acceptRequest.addEventListener("click", function(e){respondRequest(true)});
|
||||||
|
rejectRequest.addEventListener("click", function(e){respondRequest(false)});
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user