diff --git a/assets/js/common/functionsSchema.js b/assets/js/common/functionsSchema.js index b90b1480..20678868 100644 --- a/assets/js/common/functionsSchema.js +++ b/assets/js/common/functionsSchema.js @@ -613,6 +613,20 @@ var ComunicWeb = { }, + /** + * Likes handling + */ + like:{ + + /** + * Like buttons + */ + button: { + //TODO : implement + }, + + }, + /** * Modern textarea handler */ @@ -715,7 +729,14 @@ var ComunicWeb = { */ profileInfos: { //TODO : implement - } + }, + + /** + * Display user posts + */ + posts: { + //TODO : implement + }, }, diff --git a/assets/js/components/like/button.js b/assets/js/components/like/button.js new file mode 100644 index 00000000..7d1fec92 --- /dev/null +++ b/assets/js/components/like/button.js @@ -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); + + } + + } + + }, + +}; \ No newline at end of file diff --git a/assets/js/pages/userPage/main.js b/assets/js/pages/userPage/main.js index 7dd88c86..07483e8d 100644 --- a/assets/js/pages/userPage/main.js +++ b/assets/js/pages/userPage/main.js @@ -115,7 +115,7 @@ ComunicWeb.pages.userPage.main = { * Display a user page * * @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 */ displayUserPage: function(infos, params, target){ @@ -146,6 +146,16 @@ ComunicWeb.pages.userPage.main = { //Display profile informations 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); } } \ No newline at end of file diff --git a/assets/js/pages/userPage/posts.js b/assets/js/pages/userPage/posts.js new file mode 100644 index 00000000..f2466b52 --- /dev/null +++ b/assets/js/pages/userPage/posts.js @@ -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 + + } + + + +}; \ No newline at end of file diff --git a/assets/js/pages/userPage/profileInfos.js b/assets/js/pages/userPage/profileInfos.js index 587c75e8..73b352e3 100644 --- a/assets/js/pages/userPage/profileInfos.js +++ b/assets/js/pages/userPage/profileInfos.js @@ -63,6 +63,28 @@ ComunicWeb.pages.userPage.profileInfos = { 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 var listInfos = createElem2({ appendTo: boxBody, diff --git a/corePage/config/dev.config.php b/corePage/config/dev.config.php index 12a9a30b..51e40e75 100644 --- a/corePage/config/dev.config.php +++ b/corePage/config/dev.config.php @@ -158,6 +158,9 @@ $config['JSfiles'] = array( "%PATH_ASSETS%js/components/emoji/parser.js", "%PATH_ASSETS%js/components/emoji/list.js", + //Like button + "%PATH_ASSETS%js/components/like/button.js", + //Modern textarea handler "%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/friendshipStatus.js", "%PATH_ASSETS%js/pages/userPage/profileInfos.js", + "%PATH_ASSETS%js/pages/userPage/posts.js", //Login page "%PATH_ASSETS%js/pages/login.js",