mirror of
https://github.com/pierre42100/ComunicWeb
synced 2024-12-27 03:08:51 +00:00
145 lines
3.1 KiB
JavaScript
145 lines
3.1 KiB
JavaScript
/**
|
|
* Groups main script
|
|
*
|
|
* @author Pierre HUBERT
|
|
*/
|
|
|
|
const GroupsPage = {
|
|
|
|
/**
|
|
* Open groups page
|
|
*
|
|
* @param {object} args Optionnal arguments
|
|
* @param {HTMLElement} target The target for the page
|
|
*/
|
|
open: async function(args, target){
|
|
|
|
try {
|
|
|
|
//Determine which page / group should be opened
|
|
if(args.groupID)
|
|
page = args.groupID;
|
|
|
|
else if(!args.subfolder)
|
|
var page = "main";
|
|
|
|
else {
|
|
|
|
//Extract the name of the page from the URL
|
|
if(!args.subfolder.includes("/"))
|
|
var page = args.subfolder;
|
|
else {
|
|
var page = args.subfolder.split("/")[0];
|
|
}
|
|
|
|
}
|
|
|
|
//Check if the main page has to be opened
|
|
if(page == "main"){
|
|
if(!signed_in()) openPage("login");
|
|
return ComunicWeb.pages.groups.pages.main.open(target);
|
|
}
|
|
|
|
//Check if the page to create a group has to be opened
|
|
else if (page == "create"){
|
|
if(!signed_in()) openPage("login");
|
|
return ComunicWeb.pages.groups.pages.create.open(target);
|
|
}
|
|
|
|
//Else determine which group page to open (specified after the ID of the group)
|
|
var groupID = page;
|
|
let firstArg;
|
|
if(!args.subfolder || args.subfolder.split("/").length < 2){
|
|
page = "posts";
|
|
}
|
|
else {
|
|
//Extract the page to open from the URL
|
|
page = args.subfolder.split("/")[1];
|
|
|
|
if (args.subfolder.split("/").length == 3)
|
|
firstArg = args.subfolder.split("/")[2];
|
|
|
|
//Check if there is nothing after "/"
|
|
if(page.length < 2)
|
|
page = "posts";
|
|
}
|
|
|
|
/** @type {AdvancedGroupInfo} Get information about the group*/
|
|
const group = await new Promise((res, rej) => GroupsInterface.getAdvancedInfo(groupID, function(result){
|
|
|
|
//Check for errors
|
|
if(result.error){
|
|
|
|
//Check the code of the error
|
|
if(result.error.code == 401)
|
|
ComunicWeb.pages.groups.pages.forbidden.open(groupID, target);
|
|
|
|
//The group does not exists
|
|
else
|
|
|
|
ComunicWeb.common.error.pageNotFound({}, target);
|
|
return;
|
|
}
|
|
|
|
res(result);
|
|
|
|
}));
|
|
|
|
//Update page title
|
|
ComunicWeb.common.pageTitle.setTitle(group.name);
|
|
|
|
// Display the header for the group
|
|
GroupSectionHeader.display(group, target);
|
|
|
|
// Display the tabs of the group
|
|
await GroupTabs.show(group, target, page, firstArg);
|
|
|
|
switch(page) {
|
|
|
|
case "posts":
|
|
GroupPostsPage.display(group, target)
|
|
return;
|
|
|
|
case "members":
|
|
GroupMembersPage.display(group, target)
|
|
return;
|
|
|
|
case "about":
|
|
await GroupAboutPage.display(group, target);
|
|
return;
|
|
|
|
case "settings":
|
|
await GroupSettingsPage.display(group.id, target);
|
|
return;
|
|
|
|
case "conversation":
|
|
let conv = group.conversations.find(c => c.id == firstArg);
|
|
|
|
if (conv) {
|
|
GroupConversationPage.show(conv, target)
|
|
return;
|
|
}
|
|
|
|
case "presence":
|
|
if (group.is_forez_group) {
|
|
await GroupPresencePage.Show(group, target)
|
|
return;
|
|
}
|
|
|
|
default:
|
|
ComunicWeb.common.error.pageNotFound(null, target);
|
|
}
|
|
|
|
} catch(e) {
|
|
console.error(e);
|
|
target.appendChild(createCallout(
|
|
tr("Error"),
|
|
tr("Failed to load group page!"),
|
|
"danger"
|
|
))
|
|
}
|
|
}
|
|
|
|
};
|
|
|
|
ComunicWeb.pages.groups.main = GroupsPage; |