diff --git a/assets/js/components/groups/interface.js b/assets/js/components/groups/interface.js index 65234a6c..b63381d1 100644 --- a/assets/js/components/groups/interface.js +++ b/assets/js/components/groups/interface.js @@ -143,6 +143,21 @@ ComunicWeb.components.groups.interface = { id: id }; 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); + }, }; \ No newline at end of file diff --git a/assets/js/pages/groups/sections/membershipBlock.js b/assets/js/pages/groups/sections/membershipBlock.js index 19395482..8951fea1 100644 --- a/assets/js/pages/groups/sections/membershipBlock.js +++ b/assets/js/pages/groups/sections/membershipBlock.js @@ -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(); + + }); + + }); + } + } }; \ No newline at end of file