Added follow block.

This commit is contained in:
Pierre HUBERT 2018-07-19 14:34:19 +02:00
parent a5815272c8
commit 61a20e8708
6 changed files with 106 additions and 0 deletions

View File

@ -1286,6 +1286,13 @@ var ComunicWeb = {
posts: {
//TODO : implement
},
/**
* Follow block
*/
followBlock: {
//TODO : implement
},
},
},

View File

@ -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);
}
};

View File

@ -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
*

View File

@ -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 ?
"<i class='fa fa-check'></i> Following"
: "<i class='fa fa-newspaper-o'></i> 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);
});
};
}
};

View File

@ -156,6 +156,10 @@ ComunicWeb.pages.groups.sections.header = {
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"){

View File

@ -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