3
Created by Edwin van de Ven (edwin@openstudioproject.com)
8
$('input[type="checkbox"]').change(function() {
9
var $form = $(this).closest('form');
10
var data = $form.serializeArray();
11
// put the checkbox in a variable so we can use it to change the checkbox status.
12
var $checkbox = $(this);
13
// post attendance info
14
var url = '/events/ticket_customer_update_info.json';
15
var post = $.post(url, data, function(json) {
16
console.log("Posted product customer info to " + url +
17
", data: " + JSON.stringify(data));
21
post.done(function(json) {
22
$('div.w2p_flash').html(json.message + '<span id="closeflash"> × </span>');
23
$('div.w2p_flash').show();
24
setTimeout(function() {
25
$('div.w2p_flash').fadeOut();
27
if (json.status == 'fail') {
28
revert_checkbox_state();
30
console.log("Attendance update info done, result: " + JSON.stringify(json));
34
post.fail(function(data) {
35
var msg = "Uh oh... something went wrong when updating the attendance info..."
36
$('div.w2p_flash').html(msg + '<span id="closeflash"> × </span>');
37
$('div.w2p_flash').show();
38
setTimeout(function() {
39
$('div.w2p_flash').fadeOut();
41
console.log("Failed update attendance info. Status: " + data.status + " " +
42
"Status Text: " + data.statusText);
43
/* revert checkbox status to the status it had before the click that
44
initiated the failed post. */
45
revert_checkbox_state();
48
function revert_checkbox_state() {
49
checked = $checkbox.prop('checked');
50
$checkbox.prop('checked', !checked);