Display like button

This commit is contained in:
Pierre 2017-12-29 08:58:22 +01:00
parent 2bdcf71809
commit 697482c071
6 changed files with 192 additions and 2 deletions

View File

@ -613,6 +613,20 @@ var ComunicWeb = {
}, },
/**
* Likes handling
*/
like:{
/**
* Like buttons
*/
button: {
//TODO : implement
},
},
/** /**
* Modern textarea handler * Modern textarea handler
*/ */
@ -715,7 +729,14 @@ var ComunicWeb = {
*/ */
profileInfos: { profileInfos: {
//TODO : implement //TODO : implement
} },
/**
* Display user posts
*/
posts: {
//TODO : implement
},
}, },

View File

@ -0,0 +1,101 @@
/**
* Like button
*
* @author Pierre HUBERT
*/
ComunicWeb.components.like.button = {
/**
* Display like button
*
* @param {String} kind The kind of like component
* @param {int} id The ID of the component
* @param {int} count The current number of likes
* @param {Boolean} liking Specify wether user is liking the content or not
* @param {HTMLElement} target The target for the button
*/
display: function(kind, id, count, liking, target){
//Empty target
emptyElem(target);
//Display like button
var likeRoot = createElem2({
type: "div",
appendTo: target,
});
var likeLink = createElem2({
appendTo: likeRoot,
type: "a",
class: "link-black text-sm"
});
createElem2({
appendTo: likeLink,
type: "i",
class: "fa fa-thumbs-o-up margin-r-5"
});
var likeMsg = createElem2({
appendTo: likeLink,
type: "span",
});
//Check if user can like or not the component
if(!signed_in()){
//Remove link effect
likeLink.style.cursor = "default";
if(count == 0){
//Hide like component
likeRoot.style.visibility = "hidden";
}
else {
//Update message
if(count == 1){
likeMsg.innerHTML = "1 like";
}
else
likeMsg.innerHTML = count + " likes";
}
}
else {
//Update the message
if(liking == true){
likeMsg.innerHTML = "Liking"
}
else {
likeMsg.innerHTML = "Like";
}
//Add total count if possible
if(count > 0)
likeMsg.innerHTML += " (" + count + ")";
//Set onclick behaviour
likeLink.onclick = function(){
//Get the new status
var newliking = liking == true ? false : true;
count = newliking ? count + 1 : count - 1;
//Update liking status on the API
//Display liking element again
ComunicWeb.components.like.button.display(kind, id, count, newliking, target);
}
}
},
};

View File

@ -115,7 +115,7 @@ ComunicWeb.pages.userPage.main = {
* Display a user page * Display a user page
* *
* @param {Object} infos Informations about the user to display * @param {Object} infos Informations about the user to display
* @param {Object} params Parametres required to open the page * @param {Object} params Parameters required to open the page
* @param {HTMLElement} target Target of the user page * @param {HTMLElement} target Target of the user page
*/ */
displayUserPage: function(infos, params, target){ displayUserPage: function(infos, params, target){
@ -146,6 +146,16 @@ ComunicWeb.pages.userPage.main = {
//Display profile informations //Display profile informations
ComunicWeb.pages.userPage.profileInfos.display(infos, leftColumn); ComunicWeb.pages.userPage.profileInfos.display(infos, leftColumn);
//Create right column
var rightColumn = createElem2({
appendTo: row,
type: "div",
class: "col-md-9"
});
//Display text
ComunicWeb.pages.userPage.posts.display(infos, params, rightColumn);
} }
} }

View File

@ -0,0 +1,32 @@
/**
* Posts function
*
* @author Pierre HUBERT
*/
ComunicWeb.pages.userPage.posts = {
/**
* Display the posts
*
* @param {Object} userInfos Informations about the user
* @param {Object} params Additionnal parametres passed with the request
* @param {HTMLElement} target The target where the posts will be applied
*/
display: function(userInfos, params, target){
//Create posts blocks
var postsBlock = createElem2({
appendTo: target,
type: "div",
class: "box box-primary"
});
//Check whether a precise post has to be opened or not
//TODO implement
}
};

View File

@ -63,6 +63,28 @@ ComunicWeb.pages.userPage.profileInfos = {
innerHTML: infos.firstName + " " + infos.lastName innerHTML: infos.firstName + " " + infos.lastName
}); });
//Show user likes
var userLikesTarget = createElem2({
appendTo: boxBody,
type: "div"
});
userLikesTarget.style.textAlign = "center";
//Check wether user is linking or not
var userLiking = null;
if(signed_in()){
userLiking = infos.user_like_page;
}
//Call component
ComunicWeb.components.like.button.display(
"user",
infos.userID,
infos.pageLikes,
userLiking,
userLikesTarget,
);
//Add list of informations about user //Add list of informations about user
var listInfos = createElem2({ var listInfos = createElem2({
appendTo: boxBody, appendTo: boxBody,

View File

@ -158,6 +158,9 @@ $config['JSfiles'] = array(
"%PATH_ASSETS%js/components/emoji/parser.js", "%PATH_ASSETS%js/components/emoji/parser.js",
"%PATH_ASSETS%js/components/emoji/list.js", "%PATH_ASSETS%js/components/emoji/list.js",
//Like button
"%PATH_ASSETS%js/components/like/button.js",
//Modern textarea handler //Modern textarea handler
"%PATH_ASSETS%js/components/textarea.js", "%PATH_ASSETS%js/components/textarea.js",
@ -177,6 +180,7 @@ $config['JSfiles'] = array(
"%PATH_ASSETS%js/pages/userPage/accessForbidden.js", "%PATH_ASSETS%js/pages/userPage/accessForbidden.js",
"%PATH_ASSETS%js/pages/userPage/friendshipStatus.js", "%PATH_ASSETS%js/pages/userPage/friendshipStatus.js",
"%PATH_ASSETS%js/pages/userPage/profileInfos.js", "%PATH_ASSETS%js/pages/userPage/profileInfos.js",
"%PATH_ASSETS%js/pages/userPage/posts.js",
//Login page //Login page
"%PATH_ASSETS%js/pages/login.js", "%PATH_ASSETS%js/pages/login.js",