~edwinvandeven/openstudio/2018.1

« back to all changes in this revision

Viewing changes to static/plugin_os-js/events/tickets_list_customers_event_info.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
<!--
 
2
 
 
3
    Created by Edwin van de Ven (edwin@openstudioproject.com)
 
4
    License: GPLv2 or v3
 
5
 
 
6
-->
 
7
<script>
 
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)); 
 
18
                        }, "json");
 
19
 
 
20
                        // Success
 
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();   
 
26
                                }, 2500 );
 
27
                                if (json.status == 'fail') {
 
28
                                        revert_checkbox_state();
 
29
                                }
 
30
                                console.log("Attendance update info done, result: " + JSON.stringify(json));
 
31
                        });
 
32
                
 
33
                        // fail
 
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();   
 
40
                                }, 2500 );
 
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();
 
46
                        });
 
47
                
 
48
                        function revert_checkbox_state() {
 
49
                                checked = $checkbox.prop('checked');
 
50
                                $checkbox.prop('checked', !checked);
 
51
                        }
 
52
                });
 
53
</script>