Block creation of new choices

This commit is contained in:
Pierre HUBERT 2020-05-17 18:43:41 +02:00
parent 9777a2a370
commit 237b40afab
3 changed files with 42 additions and 0 deletions

View File

@ -4,6 +4,10 @@
* @author Pierre HUBERT * @author Pierre HUBERT
*/ */
.txt-center {
text-align: center;
}
/** /**
* <a> elements * <a> elements
*/ */

View File

@ -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: {}, _registerCount: {},
/** /**

View File

@ -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");
}
});
}
} }
} }