diff --git a/assets/js/common/functionsSchema.js b/assets/js/common/functionsSchema.js
index a59ad2fa..767a0804 100644
--- a/assets/js/common/functionsSchema.js
+++ b/assets/js/common/functionsSchema.js
@@ -1286,6 +1286,13 @@ var ComunicWeb = {
posts: {
//TODO : implement
},
+
+ /**
+ * Follow block
+ */
+ followBlock: {
+ //TODO : implement
+ },
},
},
diff --git a/assets/js/components/groups/interface.js b/assets/js/components/groups/interface.js
index c51ef92b..61596ed7 100644
--- a/assets/js/components/groups/interface.js
+++ b/assets/js/components/groups/interface.js
@@ -306,4 +306,21 @@ ComunicWeb.components.groups.interface = {
};
ComunicWeb.common.api.makeAPIrequest(apiURI, params, true, callback);
},
+
+ /**
+ * Set whether a user is following a group or not
+ *
+ * @param {Number} groupID The ID of the target group
+ * @param {Boolean} follow
+ * @param {Function} callback
+ */
+ setFollowing: function(groupID, follow, callback){
+ //Perform the request over the API
+ var apiURI = "groups/set_following";
+ var params = {
+ groupID: groupID,
+ follow: follow
+ };
+ ComunicWeb.common.api.makeAPIrequest(apiURI, params, true, callback);
+ }
};
\ No newline at end of file
diff --git a/assets/js/components/groups/utils.js b/assets/js/components/groups/utils.js
index 6afaafe6..ffdc0133 100644
--- a/assets/js/components/groups/utils.js
+++ b/assets/js/components/groups/utils.js
@@ -25,6 +25,19 @@ ComunicWeb.components.groups.utils = {
},
+ /**
+ * Check whether a user is a member (or more) of a group or not
+ *
+ * @param {Object} info Information about the target group
+ * @return {boolean} TRUE if the user is a member of the group
+ * FALSE else
+ */
+ isGroupMember: function(info){
+ return info.membership == "member"
+ || info.membership == "moderator"
+ || info.membership == "administrator";
+ },
+
/**
* Check whether a user can create posts for a group or not
*
diff --git a/assets/js/pages/groups/sections/followBlock.js b/assets/js/pages/groups/sections/followBlock.js
new file mode 100644
index 00000000..aefb7c9e
--- /dev/null
+++ b/assets/js/pages/groups/sections/followBlock.js
@@ -0,0 +1,64 @@
+/**
+ * Group follow state update block
+ *
+ * @author Pierre HUBERT
+ */
+
+ComunicWeb.pages.groups.sections.followBlock = {
+
+ /**
+ * Display the block
+ *
+ * @param {Object} info Information about the target group
+ * @param {HTMLElement} target The target for the block
+ */
+ display: function(info, target){
+ this._show_block(info.id, info.following, target);
+ },
+
+ /**
+ * Display follow block
+ *
+ * @param {Number} groupID The ID of the target group
+ * @param {boolean} following TRUE if the user is following the group / FALSE else
+ * @param {HTMLElement} target The target for the page
+ */
+ _show_block: function(groupID, following, target){
+
+ if(!target.className.includes("follow-group-btn"))
+ var followButton = createElem2({
+ appendTo: target,
+ type: "div",
+ class: "follow-group-btn a"
+ });
+
+ else {
+ emptyElem(target);
+ var followButton = target;
+ }
+
+ //Adapt follow button content
+ followButton.innerHTML = following ?
+ " Following"
+ : " Follow";
+
+
+ //Make button lives
+ followButton.onclick = function(){
+
+ //Make a request on the API
+ ComunicWeb.components.groups.interface.setFollowing(groupID, !following, function(result){
+
+ //Check for errors
+ if(result.error)
+ return notify("Could not update your following status of the group!", "danger");
+
+ //Show block with new status
+ ComunicWeb.pages.groups.sections.followBlock._show_block(groupID, !following, followButton);
+ });
+
+
+ };
+ }
+
+};
\ No newline at end of file
diff --git a/assets/js/pages/groups/sections/header.js b/assets/js/pages/groups/sections/header.js
index 0037ba48..6ca959e4 100644
--- a/assets/js/pages/groups/sections/header.js
+++ b/assets/js/pages/groups/sections/header.js
@@ -155,6 +155,10 @@ ComunicWeb.pages.groups.sections.header = {
//Display membership level
if(signed_in())
ComunicWeb.pages.groups.sections.membershipBlock.display(info, thirdColumn);
+
+ //Display follow block
+ if(signed_in() && ComunicWeb.components.groups.utils.isGroupMember(info))
+ ComunicWeb.pages.groups.sections.followBlock.display(info, thirdColumn);
//If the user is an admin, add a link to configure the page
if(signed_in() && info.membership == "administrator"){
diff --git a/system/config/dev.config.php b/system/config/dev.config.php
index 1434e7b5..f3e98fd1 100644
--- a/system/config/dev.config.php
+++ b/system/config/dev.config.php
@@ -442,6 +442,7 @@ class Dev {
"js/pages/groups/sections/header.js",
"js/pages/groups/sections/membershipBlock.js",
"js/pages/groups/sections/posts.js",
+ "js/pages/groups/sections/followBlock.js",
//User settings page