diff --git a/assets/js/common/functionsSchema.js b/assets/js/common/functionsSchema.js index 767a0804..e61f6a08 100644 --- a/assets/js/common/functionsSchema.js +++ b/assets/js/common/functionsSchema.js @@ -1013,6 +1013,13 @@ var ComunicWeb = { utils: { //TODO : implement }, + + /** + * Groups information + */ + info: { + //TODO : implement + }, }, /** diff --git a/assets/js/common/shorcuts.js b/assets/js/common/shorcuts.js index b581eb84..fe00b3dc 100644 --- a/assets/js/common/shorcuts.js +++ b/assets/js/common/shorcuts.js @@ -150,4 +150,24 @@ function openConversation(id){ */ function notify(message, type, duration, title){ ComunicWeb.common.notificationSystem.showNotification(message, type, duration, title) +} + +/** + * Get information about a single group + * + * @param {Number} id The ID of the group to fetch + * @param {Function} callback + */ +function getInfoGroup(id, callback){ + ComunicWeb.components.groups.info.getInfo(id, callback); +} + +/** + * Get information about multiple groups + * + * @param {Array} IDs The IDs of the groups to get information about + * @param {Function} callback Callback to call once we have information about the group + */ +function getInfoMultipleGroups(IDs, callback){ + ComunicWeb.components.groups.info.getInfoMultiple(IDs, callback); } \ No newline at end of file diff --git a/assets/js/components/groups/info.js b/assets/js/components/groups/info.js new file mode 100644 index 00000000..deb3d9ca --- /dev/null +++ b/assets/js/components/groups/info.js @@ -0,0 +1,113 @@ +/** + * Groups information management + * + * @author Pierre HUBERT + */ + +ComunicWeb.components.groups.info = { + + /** + * Group information cache + */ + _cache: {}, + + /** + * Get information about a single group + * + * @param {Number} id The ID of the target group + * @param {Function} callback + */ + getInfo: function(id, callback){ + + //First, check if the group is cached or not + if(this._cache[id]) + return callback(this._cache[id]); + + //Then query the server, if required + ComunicWeb.components.groups.interface.getInfo(id, function(result){ + + //Check for errors + if(result.error) + return callback(result); + + //Save group information + ComunicWeb.components.groups.info._cache[id] = result; + + //Call callback + callback(result); + }); + + }, + + /** + * Get information about a multiple groups + * + * @param {Array} list The list of the IDs of the group to get information about + * @param {Function} callback + */ + getInfoMultiple: function(list, callback){ + + //First, check which group are unknown in the cache + var toFetch = Array(); + + list.forEach(function(id){ + if(!ComunicWeb.components.groups.info._cache[id]) + toFetch.push(id); + }); + + if(toFetch.length == 0){ + this.getInfoMultiplePreCallback(list, callback); + return; + } + + //Perform the request over the server + ComunicWeb.components.groups.interface.getInfoMultiple(toFetch, function(result){ + + //Check for errors + if(result.error) + return notify("Could not get information about the groups!", "danger"); + + //Process the list of groups + for(i in result){ + + //Save group information in the cache + ComunicWeb.components.groups.info._cache[result[i].id] = result[i]; + + } + + //Call callback + ComunicWeb.components.groups.info.getInfoMultiplePreCallback(list, callback); + + }); + }, + + /** + * Get multiple information pre-callback + * + * @param {Array} list The list of the IDs of teh group to get information about + * @param {Function} callback + */ + getInfoMultiplePreCallback: function(list, callback){ + + var groupInfo = {}; + + list.forEach(function(id){ + groupInfo[id] = ComunicWeb.components.groups.info._cache[id]; + }); + + //Call callback + callback(groupInfo); + }, + + /** + * Clear cache + */ + clearCache: function(){ + this._cache = {}; + } + + +}; + +//Register cache cleaner +ComunicWeb.common.cacheManager.registerCacheCleaner("ComunicWeb.components.groups.info.clearCache"); \ No newline at end of file diff --git a/assets/js/components/groups/interface.js b/assets/js/components/groups/interface.js index 61596ed7..3d72a108 100644 --- a/assets/js/components/groups/interface.js +++ b/assets/js/components/groups/interface.js @@ -64,6 +64,21 @@ ComunicWeb.components.groups.interface = { ComunicWeb.common.api.makeAPIrequest(apiURI, params, true, callback); }, + /** + * Get information about multiple groups + * + * @param {Array} list The IDs of the groups to get + * @param {Function} callback + */ + getInfoMultiple: function(list, callback){ + //Perform the request over the API + var apiURI = "groups/get_multiple_info"; + var params = { + list: list + }; + ComunicWeb.common.api.makeAPIrequest(apiURI, params, true, callback); + }, + /** * Get advanced information about a group * diff --git a/system/config/dev.config.php b/system/config/dev.config.php index f3e98fd1..a4a69ac6 100644 --- a/system/config/dev.config.php +++ b/system/config/dev.config.php @@ -392,6 +392,7 @@ class Dev { //Groups component "js/components/groups/interface.js", "js/components/groups/utils.js", + "js/components/groups/info.js", //Virtual directory component "js/components/virtualDirectory/interface.js",