Send group membreship requests to the server.

This commit is contained in:
Pierre HUBERT 2018-07-06 18:48:49 +02:00
parent f90dc5d9ae
commit d32c1428cf
2 changed files with 49 additions and 1 deletions

View File

@ -143,6 +143,21 @@ ComunicWeb.components.groups.interface = {
id: id id: id
}; };
ComunicWeb.common.api.makeAPIrequest(apiURI, params, true, callback); ComunicWeb.common.api.makeAPIrequest(apiURI, params, true, callback);
} },
/**
* Send a request to join a group
*
* @param {Number} id The ID of the target group
* @param {Function} callback
*/
sendRequest: function(id, callback){
//Perform the request over the API
var apiURI = "groups/send_request";
var params = {
id: id
};
ComunicWeb.common.api.makeAPIrequest(apiURI, params, true, callback);
},
}; };

View File

@ -163,6 +163,39 @@ ComunicWeb.pages.groups.sections.membershipBlock = {
}) })
} }
//Check if the user is only a simple visitor
if(info.membership == "visitor"){
//Check if the registration is closed
if(info.registration_level == "closed"){
add_p(container, "Only a moderator can invite you to join this group.");
return;
}
//Offer the user to join the group
var joinGroup = createElem2({
appendTo: container,
type: "span",
class: "a",
innerHTML: "Join this group"
});
joinGroup.addEventListener("click", function(e){
ComunicWeb.components.groups.interface.sendRequest(info.id, function(result){
//Check for errors
if(result.error)
notify("An error occurred while trying to send a membership request to the server!", "danger");
//Refresh current page
ComunicWeb.common.page.refresh_current_page();
});
});
}
} }
}; };