diff --git a/assets/js/common/shorcuts.js b/assets/js/common/shorcuts.js index 94ec3b4c..f8dd983a 100644 --- a/assets/js/common/shorcuts.js +++ b/assets/js/common/shorcuts.js @@ -138,7 +138,7 @@ function getMultipleUsersInfo(usersID, afterGetUserInfos, forceRequest){ * * @param {Array~Object} users The list of users to get * @param {Boolean} force - * @returns {Promise} + * @returns {Promise} */ function getUsers(users, force) { return new Promise((resolve, error) => { @@ -146,7 +146,7 @@ function getUsers(users, force) { if(result.error) error(result.error); - + else resolve(new UsersList(result)); @@ -224,6 +224,22 @@ function getInfoMultipleGroups(IDs, callback, force){ ComunicWeb.components.groups.info.getInfoMultiple(IDs, callback, force); } +/** + * Get information about multiple groups + * + * @param {Number[]} list The ID of the groups to get + * @param {Boolean} force Specify whether to force or not the request + * @return {Promise} + */ +function getGroups(list, force){ + return new Promise((resolve, reject) => { + getInfoMultipleGroups(list, result => { + if(result.error) reject(result.error); + else resolve(new GroupsList(result)); + }, force); + }); +} + /** * Get the difference of time from now to a specified * timestamp and return it as a string diff --git a/assets/js/components/groups/GroupsList.js b/assets/js/components/groups/GroupsList.js new file mode 100644 index 00000000..dd162853 --- /dev/null +++ b/assets/js/components/groups/GroupsList.js @@ -0,0 +1,51 @@ +/** + * Groups list + * + * @author Pierre HUBERT + */ + +class Group { + constructor(info){ + this.id = info.id; + this.following = info.following; + this.icon_url = info.icon_url; + this.membership = info.membership; + this.name = info.name; + this.number_members = info.number_members; + this.posts_level = info.posts_level; + this.registration_level = info.registration_level; + this.virtual_directory = info.virtual_directory; + this.visibility = info.visibility; + } +} + +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; + } + } +} \ No newline at end of file diff --git a/system/config/dev.config.php b/system/config/dev.config.php index 232ea4c4..1825f51d 100644 --- a/system/config/dev.config.php +++ b/system/config/dev.config.php @@ -440,6 +440,7 @@ class Dev { "js/components/groups/interface.js", "js/components/groups/utils.js", "js/components/groups/info.js", + "js/components/groups/GroupsList.js", //Virtual directory component "js/components/virtualDirectory/interface.js",