From 237b40afab3c9eb1d625763121babefc1bb39b2e Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Sun, 17 May 2020 18:43:41 +0200 Subject: [PATCH] Block creation of new choices --- assets/css/common/global.css | 4 ++++ assets/js/components/posts/interface.js | 11 ++++++++++ assets/js/components/posts/ui.js | 27 +++++++++++++++++++++++++ 3 files changed, 42 insertions(+) diff --git a/assets/css/common/global.css b/assets/css/common/global.css index 58c5b32e..0a532c93 100644 --- a/assets/css/common/global.css +++ b/assets/css/common/global.css @@ -4,6 +4,10 @@ * @author Pierre HUBERT */ +.txt-center { + text-align: center; +} + /** * elements */ diff --git a/assets/js/components/posts/interface.js b/assets/js/components/posts/interface.js index 8c95377c..750d5765 100644 --- a/assets/js/components/posts/interface.js +++ b/assets/js/components/posts/interface.js @@ -229,6 +229,17 @@ const PostsInterface = { }, + /** + * Prevent new choices from being created + * + * @param {number} postID The ID of the target post + */ + blockNewSurveyChoices: async function(postID) { + await api("survey/block_new_choices_creation", { + postID: postID + }, true); + }, + _registerCount: {}, /** diff --git a/assets/js/components/posts/ui.js b/assets/js/components/posts/ui.js index 6c8c0bf4..2f8ddaea 100644 --- a/assets/js/components/posts/ui.js +++ b/assets/js/components/posts/ui.js @@ -880,6 +880,33 @@ ComunicWeb.components.posts.ui = { } } + + // If the user is the owner of the survey, offer him to close it + if(info.data_survey.userID == userID() && info.data_survey.allowNewChoices) { + + const link = createElem2({ + appendTo: surveyResponse, + type: "div", + class: "a txt-center", + innerHTML: tr("Block creation of new choices") + }); + + link.addEventListener("click", async () => { + + try { + if(!await showConfirmDialog(tr("Do you want to prevent new choices from being created? This can not be reverted!"))) + return; + + await PostsInterface.blockNewSurveyChoices(info.ID); + + //Reload post + ComunicWeb.components.posts.actions.reload_post(info.ID, postRoot); + + } catch(e) { + notify(tr("Could not block new choices from being created!"), "danger"); + } + }); + } } }