ComunicWeb/assets/js/components/groups/GroupsList.js

75 lines
1.4 KiB
JavaScript
Raw Permalink Normal View History

/**
* Groups list
*
* @author Pierre HUBERT
*/
class Group {
constructor(info){
2021-03-16 15:57:15 +00:00
/** @type {Number} */
this.id = info.id;
2021-03-16 15:57:15 +00:00
/** @type {Boolean} */
this.following = info.following;
2021-03-16 15:57:15 +00:00
/** @type {String} */
this.icon_url = info.icon_url;
2021-03-16 15:57:15 +00:00
/** @type {"administrator"|"moderator"|"member"|"invited"|"pending"|"visitor"} */
this.membership = info.membership;
2021-03-16 15:57:15 +00:00
/** @type {String} */
this.name = info.name;
2021-03-16 15:57:15 +00:00
/** @type {Number} */
this.number_members = info.number_members;
2021-03-16 15:57:15 +00:00
/** @type {"moderators"|"members"} */
this.posts_level = info.posts_level;
2021-03-16 15:57:15 +00:00
/** @type {"open"|"moderated"|"closed"} */
this.registration_level = info.registration_level;
2021-03-16 15:57:15 +00:00
/** @type {String} */
this.virtual_directory = info.virtual_directory;
2021-03-16 15:57:15 +00:00
/** @type {"open"|"private"|"secrete"} */
this.visibility = info.visibility;
}
get hasVirtualDirectory() {
return this.virtual_directory;
}
}
class GroupsList {
constructor(list){
/**
* @type {Group[]}
*/
this.list = [];
// Initialize the list of groups
for (const key in list) {
if (list.hasOwnProperty(key))
this.list.push(new Group(list[key]));
}
}
/**
* Get a group specified by its ID
*
* @param {Number} id The ID of the target group
* @return {Group} information about the target group
*/
get(id){
for (let index = 0; index < this.list.length; index++) {
const group = this.list[index];
if(group.id == id)
return group;
}
}
}