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-02 06:42:55 +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;
|
2018-07-02 06:42:55 +00:00
|
|
|
|
2021-03-15 17:04:20 +00:00
|
|
|
else if(!args.subfolder)
|
|
|
|
var page = "main";
|
|
|
|
|
2018-07-02 06:42:55 +00:00
|
|
|
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];
|
|
|
|
}
|
|
|
|
|
2018-07-02 06:42:55 +00:00
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
}
|
2018-07-02 06:42:55 +00:00
|
|
|
|
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);
|
|
|
|
}
|
2018-07-02 06:42:55 +00:00
|
|
|
|
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;
|
|
|
|
if(!args.subfolder || args.subfolder.split("/").length < 2){
|
|
|
|
page = "posts";
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
//Extract the page to open from the URL
|
|
|
|
page = args.subfolder.split("/")[1];
|
2018-07-02 06:42:55 +00:00
|
|
|
|
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)
|
|
|
|
ComunicWeb.pages.groups.pages.forbidden.open(id, 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);
|
2018-07-03 09:45:57 +00:00
|
|
|
|
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"
|
|
|
|
))
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*//Check which page to open
|
2018-07-04 04:05:14 +00:00
|
|
|
if(page == "group")
|
2018-07-03 09:45:57 +00:00
|
|
|
ComunicWeb.pages.groups.pages.group.open(groupID, target);
|
2018-07-04 04:05:14 +00:00
|
|
|
|
|
|
|
else if(page == "settings")
|
|
|
|
ComunicWeb.pages.groups.pages.settings.open(groupID, target);
|
2018-07-07 13:27:27 +00:00
|
|
|
|
|
|
|
else if(page == "members")
|
|
|
|
ComunicWeb.pages.groups.pages.members.open(groupID, target);
|
2018-07-04 04:05:14 +00:00
|
|
|
|
2018-07-03 09:45:57 +00:00
|
|
|
|
|
|
|
//Unrecognized page
|
2018-07-02 06:42:55 +00:00
|
|
|
else
|
2021-03-15 17:04:20 +00:00
|
|
|
ComunicWeb.common.error.pageNotFound(args, target);*/
|
2018-07-02 06:42:55 +00:00
|
|
|
}
|
|
|
|
|
2021-03-15 17:04:20 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
ComunicWeb.pages.groups.main = GroupsPage;
|