Make a request on the server to cancel survey response.

This commit is contained in:
Pierre 2018-01-16 19:08:45 +01:00
parent b24cf9682a
commit c19d935c5e
3 changed files with 84 additions and 0 deletions

View File

@ -73,6 +73,10 @@
padding: 10px;
}
/**
* Survey specific rules
*/
.post .post-survey-question {
text-align: center;
}
@ -80,3 +84,7 @@
.post .post-survey-chart-contener {
margin-bottom: 10px;
}
.post .survey-given-response {
text-align: center;
}

View File

@ -127,4 +127,23 @@ ComunicWeb.components.posts.interface = {
},
/**
* Cancel a response to a survey
*
* @param {int} postID The ID of the target post
* @param {function} callback This function is called once we got a response
*/
cancel_survey_response: function(postID, callback){
//Prepare an API request
apiURI = "surveys/cancel_response";
params = {
postID: postID
};
//Perform the request
ComunicWeb.common.api.makeAPIrequest(apiURI, params, true, callback);
}
}

View File

@ -439,6 +439,12 @@ ComunicWeb.components.posts.ui = {
class: "post-survey-question"
});
//Answer contener
var surveyResponse = createElem2({
appendTo: postRoot,
type: "div",
});
//Create row
var row = createElem2({
appendTo: postRoot,
@ -574,6 +580,57 @@ ComunicWeb.components.posts.ui = {
}
//Display survey response options if the user is signed in
if(signed_in()){
//Check if the user gave a response to the survey
if(infos.data_survey.user_choice != 0){
//Create a text to display user choice
var choosedResponseElem = createElem2({
appendTo: surveyResponse,
class: "survey-given-response",
type: "p",
innerHTML: "Your response: " + infos.data_survey.choices[infos.data_survey.user_choice].name + " "
});
//Offer the user to cancel his choice
var cancelReponseLink = createElem2({
appendTo: choosedResponseElem,
type: "a",
innerHTML: "Cancel"
});
//Make cancel button lives
cancelReponseLink.onclick = function(){
ComunicWeb.common.messages.confirm("Do you really want to cancel your response to the survey ?", function(confirm){
//Check if the user cancelled
if(!confirm)
return;
//Make a request on the server
ComunicWeb.components.posts.interface.cancel_survey_response(infos.ID, function(response){
//Check for errors
if(response.error){
ComunicWeb.common.notificationSystem.showNotification("Could not cancel response to survey !", "danger");
return;
}
//Reload post
ComunicWeb.components.posts.actions.reload_post(infos.ID, postRoot);
});
});
}
}
}
}
//If the kind of post was not implemented