2
$(document).ready(function() {
4
This function adds an handler to the checkboxes. When they are clicked
5
the data is serialized and sent to "activity_update_attendance.json".
6
After the data is sent, a message is shown with the message returned by
10
$('input[type="checkbox"]').change(function() {
11
var $form = $(this).closest('form');
12
var data = $form.serializeArray();
13
// put the checkbox in a variable so we can use it to change the checkbox status.
14
var $checkbox = $(this);
15
// post attendance info
16
var url = '/workshops/activity_update_attendance.json';
17
var post = $.post(url, data, function(json) {
18
console.log("Posted product attendance info to " + url +
19
", data: " + JSON.stringify(data));
23
post.done(function(json) {
24
$('div.w2p_flash').html(json.message + '<span id="closeflash"> × </span>');
25
$('div.w2p_flash').show();
26
setTimeout(function() {
27
$('div.w2p_flash').fadeOut();
29
if (json.status == 'fail') {
30
revert_checkbox_state();
32
console.log("Attendance update info done, result: " + JSON.stringify(json));
36
post.fail(function(data) {
37
var msg = "{{=T('Uh oh... something went wrong when updating the attendance info...')}}";
38
$('div.w2p_flash').html(msg + '<span id="closeflash"> × </span>');
39
$('div.w2p_flash').show();
40
setTimeout(function() {
41
$('div.w2p_flash').fadeOut();
43
console.log("Failed update attendance info. Status: " + data.status + " " +
44
"Status Text: " + data.statusText);
45
/* revert checkbox status to the status it had before the click that
46
initiated the failed post. */
47
revert_checkbox_state();
50
function revert_checkbox_state() {
51
checked = $checkbox.prop('checked');
52
$checkbox.prop('checked', !checked);
55
}); // end document ready