Display the list of groups of a user

This commit is contained in:
Pierre HUBERT 2018-07-10 14:35:44 +02:00
parent b67f3b055f
commit 59c917f599
3 changed files with 99 additions and 1 deletions

View File

@ -10,3 +10,21 @@
text-align: center; text-align: center;
padding-top: 50px; padding-top: 50px;
} }
.groups-main-page .group-item {
text-align: justify;
margin-top: 10px;
}
.groups-main-page .group-item .group-icon {
max-width: 50px;
margin-right: 10px;
}
.groups-main-page .group-item div {
display: inline-block;
}
.groups-main-page .group-item .group-name {
width: 180px;
}

View File

@ -22,6 +22,18 @@ ComunicWeb.components.groups.interface = {
ComunicWeb.common.api.makeAPIrequest(apiURI, params, true, callback); ComunicWeb.common.api.makeAPIrequest(apiURI, params, true, callback);
}, },
/**
* Get the list of groups of the user
*
* @param {Function} callback
*/
getListUser: function(callback){
//Perform a request over the API
var apiURI = "groups/get_my_list";
var params = {};
ComunicWeb.common.api.makeAPIrequest(apiURI, params, true, callback);
},
/** /**
* Get information about a group * Get information about a group
* *

View File

@ -31,6 +31,74 @@ ComunicWeb.pages.groups.pages.main = {
openPage("groups/create"); openPage("groups/create");
}); });
//Add loading message
var message = ComunicWeb.common.messages.createCalloutElem(
"Loading",
"Please wait while we retrieve the list of your groups...",
"info");
pageContainer.appendChild(message);
//Get the list of groups of the user
ComunicWeb.components.groups.interface.getListUser(function(list){
message.remove();
//Check for errors
if(list.error)
return pageContainer.appendChild(
ComunicWeb.common.messages.createCalloutElem(
"Error",
"An error occurred while retrieving the list of groups of the user!",
"danger"
)
);
//Display the list of the groups of the user
ComunicWeb.pages.groups.pages.main._display_list(pageContainer, list);
});
}, },
/**
* Display the list of groups of the user
*
* @param {HTMLElement} target The target for the lsit
* @param {Object} list The list to apply
*/
_display_list: function(target, list){
//Process the list of groups
list.forEach(function(group){
//Create group item
var groupItem = createElem2({
appendTo: target,
type: "div",
class: "group-item"
});
//Display group information
createElem2({
appendTo: groupItem,
type: "img",
class: "group-icon",
src: group.icon_url
});
var groupName = createElem2({
appendTo: groupItem,
type: "div",
class: "group-name a",
innerHTML: group.name
});
groupName.addEventListener("click", function(e){
openPage("groups/" + group.id);
});
//Display membership status
ComunicWeb.pages.groups.sections.membershipBlock.display(group, groupItem);
});
}
} }