diff --git a/src/includes/head.pug b/src/includes/head.pug index 907cc5fc4ad7e7f01b96f182cc4888633a610f1e..4dde5b02fa9e6f2dd396635c529f0b512a30fe16 100644 --- a/src/includes/head.pug +++ b/src/includes/head.pug @@ -2,11 +2,13 @@ head title CoopStarter meta(charset="utf-8") script(src="https://unpkg.com/@webcomponents/webcomponentsjs@1.2.7/webcomponents-loader.js") - script(type="module" src="https://unpkg.com/@startinblox/core@0.8") + script(type="module" src="https://unpkg.com/@startinblox/core") script(type="module" src="https://unpkg.com/@startinblox/router") script(type="module" src="https://unpkg.com/@startinblox/oidc") script(type="module" src="https://unpkg.com/@startinblox/component-conversation") + script(type="module" src="../../sib-like/sib-like.js") script(src="https://kit.fontawesome.com/48014d2af3.js") script(src="https://code.jquery.com/jquery-3.3.1.min.js" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" crossorigin="anonymous") script(src="/scripts/coopstarter.js") link(rel="stylesheet" href="/styles/index.css") + link(rel="stylesheet" href="../../sib-like/css/main.css") diff --git a/src/includes/mentor/components/header.pug b/src/includes/mentor/components/header.pug index 3e7b4a4612af679e9baa3adf62b7dda7673e2774..7ee39240cd66335a4b072266df11b4c29dfebbcf 100644 --- a/src/includes/mentor/components/header.pug +++ b/src/includes/mentor/components/header.pug @@ -18,7 +18,7 @@ ) .dropdownWrapper - sib-display#mentor-account-picture.dropdownLabel( + sib-display#user-account-picture.dropdownLabel( bind-user fields='account.picture', widget-account.picture='cs-account-picture' diff --git a/src/includes/mentor/resources/detail.pug b/src/includes/mentor/resources/detail.pug index cf20f6a78515dd973cbcb056b19221595ccf3042..ca54360b8e6af7b2c76788dc2024a882ad77fd1a 100644 --- a/src/includes/mentor/resources/detail.pug +++ b/src/includes/mentor/resources/detail.pug @@ -74,24 +74,8 @@ include ../../components/widgets action-broken='resource-report-broken-link-mentor' ) - //TODO: implement likes here - //- <div class="like"> - //- <p class="backlink"><i class='far fa-thumbs-up'></i>18</p> - //- <p class="backlink"><i class='far fa-thumbs-down'></i>3</p> - //- </div> - - sib-display( - bind-resources - fields="" - nested-field="likes" - counter-template="<p><i class='fas fa-thumbs-up'></i>${counter}</p>" - ) - - sib-display( - bind-resources - fields="" - nested-field="dislikes" - counter-template="<p><i class='fas fa-thumbs-down'></i>${counter}</p>" + sib-like( + bind-resources, ) sib-display( diff --git a/src/scripts/coopstarter.js b/src/scripts/coopstarter.js index 0312cf457fad3984efc34ca292f5e3d7e70e53c7..4ce908d9b91ad0827a10ab65d69d2df80944ba91 100644 --- a/src/scripts/coopstarter.js +++ b/src/scripts/coopstarter.js @@ -343,6 +343,24 @@ function initFileUpload(){ } } +/** + * Manage the like sender hidden form + * @param {*} event + * @param {*} userWhoSubmitLike + * @param {*} formSenderLike + */ +function fillSenderLike(userWhoSubmitLike, formSenderLike, currentResource) { + console.log("userWhoSubmitLike", userWhoSubmitLike) + console.log("formSenderLike", formSenderLike) + formSenderLike.querySelector( + "input[name='sender']" + ).value = JSON.stringify({ "@id": userWhoSubmitLike }); + formSenderLike.querySelector( + "input[name='receiver_object_id']" + ).value = JSON.stringify({ "@id": currentResource }); + receiver_object_id +} + /** * For entrepreneur dashboard only : * As we cannot have multiple imbricated filtering with the native sib-display, we manage it manually. @@ -545,6 +563,8 @@ jQuery(document).ready(function($) { linkDatasetToField(userAccountDataSrc, "improvement-dialog-form", "reviewer"); linkDatasetToField(userAccountDataSrc, "refusal-dialog-form", "reviewer"); linkDatasetToField(userAccountDataSrc, "change_status_request", "reviewer"); + // linkDatasetToField(userAccountDataSrc, "add-like", "sender"); + // linkDatasetToField(userAccountDataSrc, "add-dislike", "sender"); //On form submission, we sometime have to refresh a list. refreshList("resource-creation-form", "resources-history"); @@ -600,6 +620,34 @@ jQuery(document).ready(function($) { var userWhoSubmitReport = userAccountDataSrc.dataset.src var formBrokenLink = document.getElementById("report-broken-link-mentor"); fillReportBrokenLinkForm(event, userWhoSubmitReport, formBrokenLink); + + // Fill the hidden like-form + document.querySelector('sib-auth').getUser().then(data=> { + let targetFormLike = document.getElementById('add-like'); + targetFormLike.addEventListener("populate", event => { + let resourceField = targetFormLike.querySelector(`input[name="sender"]`); + if (resourceField) { + resourceField.value = JSON.stringify(data); + resourceField.setAttribute( + "value", + JSON.stringify(data) + ); + } + }); + let targetFormDislike = document.getElementById('add-dislike'); + targetFormDislike.addEventListener("populate", event => { + let resourceField = targetFormDislike.querySelector(`input[name="sender"]`); + if (resourceField) { + resourceField.value = JSON.stringify(data); + resourceField.setAttribute( + "value", + JSON.stringify(data) + ); + } + }); + + }) + }); //Init the form file behaviour