mirror of
https://github.com/pierre42100/ComunicWeb
synced 2024-12-24 18:08:50 +00:00
Make a request on the server to cancel survey response.
This commit is contained in:
parent
b24cf9682a
commit
c19d935c5e
@ -73,10 +73,18 @@
|
|||||||
padding: 10px;
|
padding: 10px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Survey specific rules
|
||||||
|
*/
|
||||||
.post .post-survey-question {
|
.post .post-survey-question {
|
||||||
text-align: center;
|
text-align: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
.post .post-survey-chart-contener {
|
.post .post-survey-chart-contener {
|
||||||
margin-bottom: 10px;
|
margin-bottom: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.post .survey-given-response {
|
||||||
|
text-align: center;
|
||||||
}
|
}
|
@ -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);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -439,6 +439,12 @@ ComunicWeb.components.posts.ui = {
|
|||||||
class: "post-survey-question"
|
class: "post-survey-question"
|
||||||
});
|
});
|
||||||
|
|
||||||
|
//Answer contener
|
||||||
|
var surveyResponse = createElem2({
|
||||||
|
appendTo: postRoot,
|
||||||
|
type: "div",
|
||||||
|
});
|
||||||
|
|
||||||
//Create row
|
//Create row
|
||||||
var row = createElem2({
|
var row = createElem2({
|
||||||
appendTo: postRoot,
|
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
|
//If the kind of post was not implemented
|
||||||
|
Loading…
Reference in New Issue
Block a user