mirror of
https://github.com/pierre42100/ComunicWeb
synced 2024-11-22 20:19:21 +00:00
Added follow block.
This commit is contained in:
parent
a5815272c8
commit
61a20e8708
@ -1286,6 +1286,13 @@ var ComunicWeb = {
|
|||||||
posts: {
|
posts: {
|
||||||
//TODO : implement
|
//TODO : implement
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Follow block
|
||||||
|
*/
|
||||||
|
followBlock: {
|
||||||
|
//TODO : implement
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -306,4 +306,21 @@ ComunicWeb.components.groups.interface = {
|
|||||||
};
|
};
|
||||||
ComunicWeb.common.api.makeAPIrequest(apiURI, params, true, callback);
|
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);
|
||||||
|
}
|
||||||
};
|
};
|
@ -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
|
* Check whether a user can create posts for a group or not
|
||||||
*
|
*
|
||||||
|
64
assets/js/pages/groups/sections/followBlock.js
Normal file
64
assets/js/pages/groups/sections/followBlock.js
Normal 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);
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
@ -156,6 +156,10 @@ ComunicWeb.pages.groups.sections.header = {
|
|||||||
if(signed_in())
|
if(signed_in())
|
||||||
ComunicWeb.pages.groups.sections.membershipBlock.display(info, thirdColumn);
|
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 the user is an admin, add a link to configure the page
|
||||||
if(signed_in() && info.membership == "administrator"){
|
if(signed_in() && info.membership == "administrator"){
|
||||||
|
|
||||||
|
@ -442,6 +442,7 @@ class Dev {
|
|||||||
"js/pages/groups/sections/header.js",
|
"js/pages/groups/sections/header.js",
|
||||||
"js/pages/groups/sections/membershipBlock.js",
|
"js/pages/groups/sections/membershipBlock.js",
|
||||||
"js/pages/groups/sections/posts.js",
|
"js/pages/groups/sections/posts.js",
|
||||||
|
"js/pages/groups/sections/followBlock.js",
|
||||||
|
|
||||||
|
|
||||||
//User settings page
|
//User settings page
|
||||||
|
Loading…
Reference in New Issue
Block a user