ComunicWeb/assets/js/pages/groups/main.js

145 lines
3.1 KiB
JavaScript
Raw Normal View History

2018-07-02 06:07:59 +00:00
/**
* Groups main script
*
* @author Pierre HUBERT
*/
2021-03-15 17:04:20 +00:00
const GroupsPage = {
2018-07-02 06:07:59 +00:00
/**
2018-07-29 15:17:54 +00:00
* Open groups page
2018-07-02 06:07:59 +00:00
*
* @param {object} args Optionnal arguments
* @param {HTMLElement} target The target for the page
*/
2021-03-15 17:04:20 +00:00
open: async function(args, target){
2018-07-02 06:07:59 +00:00
2021-03-15 17:04:20 +00:00
try {
//Determine which page / group should be opened
if(args.groupID)
page = args.groupID;
2021-03-15 17:04:20 +00:00
else if(!args.subfolder)
var page = "main";
else {
2021-03-15 17:04:20 +00:00
//Extract the name of the page from the URL
if(!args.subfolder.includes("/"))
var page = args.subfolder;
else {
var page = args.subfolder.split("/")[0];
}
}
2021-03-15 17:04:20 +00:00
//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);
}
2021-03-15 17:04:20 +00:00
//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);
}
2021-03-15 17:04:20 +00:00
//Else determine which group page to open (specified after the ID of the group)
var groupID = page;
let firstArg;
2021-03-15 17:04:20 +00:00
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];
2021-03-15 17:04:20 +00:00
//Check if there is nothing after "/"
if(page.length < 2)
page = "posts";
}
2018-07-03 09:45:57 +00:00
2021-03-15 17:04:20 +00:00
/** @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)
2021-03-17 17:33:25 +00:00
ComunicWeb.pages.groups.pages.forbidden.open(groupID, target);
2021-03-15 17:04:20 +00:00
//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);
2018-07-03 09:45:57 +00:00
2021-03-15 17:30:18 +00:00
switch(page) {
case "posts":
GroupPostsPage.display(group, target)
return;
2021-03-15 17:38:59 +00:00
case "members":
2021-03-15 18:19:58 +00:00
GroupMembersPage.display(group, target)
2021-03-15 17:38:59 +00:00
return;
2021-03-15 17:54:34 +00:00
2021-03-15 18:19:58 +00:00
case "about":
await GroupAboutPage.display(group, target);
return;
2021-03-15 17:54:34 +00:00
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;
}
2021-04-21 14:48:50 +00:00
case "presence":
if (group.is_forez_group) {
await GroupPresencePage.Show(group, target)
return;
}
2021-03-15 17:38:59 +00:00
2021-03-15 17:30:18 +00:00
default:
ComunicWeb.common.error.pageNotFound(null, target);
}
2021-03-15 17:04:20 +00:00
} catch(e) {
console.error(e);
target.appendChild(createCallout(
tr("Error"),
tr("Failed to load group page!"),
"danger"
))
}
}
2021-03-15 17:04:20 +00:00
};
ComunicWeb.pages.groups.main = GroupsPage;