~edwinvandeven/openstudio/2018.1

« back to all changes in this revision

Viewing changes to static/plugin_os-js/events/activity_list_customers.html

  • Committer: Edwin van de Ven
  • Date: 2018-03-07 13:05:45 UTC
  • Revision ID: edwinvandeven@home.nl-20180307130545-qiz8jeyxl81dz3qk
Added a few static files to versioning system

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<script>
 
2
        $(document).ready(function() {
 
3
                /* 
 
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
 
7
                        web2py.
 
8
                */
 
9
        
 
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)); 
 
20
                        }, "json");
 
21
 
 
22
                        // Success
 
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();   
 
28
                                }, 2500 );
 
29
                                if (json.status == 'fail') {
 
30
                                        revert_checkbox_state();
 
31
                                }
 
32
                                console.log("Attendance update info done, result: " + JSON.stringify(json));
 
33
                        });
 
34
                
 
35
                        // fail
 
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();   
 
42
                                }, 2500 );
 
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();
 
48
                        });
 
49
                
 
50
                        function revert_checkbox_state() {
 
51
                                checked = $checkbox.prop('checked');
 
52
                                $checkbox.prop('checked', !checked);
 
53
                        }
 
54
                });
 
55
        }); // end document ready
 
56
</script>
 
57