Passed
Push — master ( 727ee7...df80f0 )
by
unknown
03:33
created

assets/js/ajaxFormSubmit.js   A

Size

Lines of Code 1

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 1
rs 10
noi 1
1
showNotification = function (message, color, icon) {
0 ignored issues
show
Bug introduced by
The variable showNotification seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.showNotification.
Loading history...
2
    $.notify({
3
        icon: "nc-icon " + icon,
4
        message: message
5
6
    }, {
7
        type: color,
8
        delay: 100,
9
        placement: {
10
            from: 'top',
11
            align: 'center'
12
        }
13
    });
14
};
15
16
$.fn.serializeObject = function () {
17
    let o = {};
18
    let a = this.serializeArray();
19
    $.each(a, function () {
20
        if (o[this.name] !== undefined) {
21
            if (!o[this.name].push) {
22
                o[this.name] = [o[this.name]];
23
            }
24
            o[this.name].push(this.value || '');
25
        } else {
26
            o[this.name] = this.value || '';
27
        }
28
    });
29
    return o;
30
};
31
32
$(document).on("click", ".save-bet-button", function (event) {
33
    event.preventDefault();
34
    let $_target = $(event.target);
35
    let bettingWrapperSelector = $('.betting-wrapper');
36
    let bettingFormSelector = $('.user-betting-form');
37
    let submitSelector = $('.save-bet-button');
38
39
    submitSelector.prop('disabled', true);
40
    let data = $_target.closest(bettingWrapperSelector).find(bettingFormSelector).serializeObject();
41
42
    $.ajax({
43
        url: '/savebet',
44
        type: 'POST',
45
        dataType: 'json',
46
        data: data,
47
        success: function (data) {
48
            if (data.status) {
49
                showNotification("Tipp erfolgreich gespeichert!", 'success', 'nc-check-2')
50
            } else {
51
                showNotification("Fehler! 🙁", 'danger', 'nc-simple-remove')
52
53
            }
54
        },
55
        complete: function () {
56
            submitSelector.prop('disabled', false);
57
        }
58
    });
59
60
});
61
62
$(document).on("click", ".extra-bet-submit", function (event) {
63
    event.preventDefault();
64
    let $_target = $(event.target);
65
    let bettingWrapperSelector = $('.extra-bet-wrapper');
66
    let bettingFormSelector = $('.extra-bet-form');
67
    let submitSelector = $('.extra-bet-submit');
68
69
    submitSelector.prop('disabled', true);
70
71
    let data = $_target.closest(bettingWrapperSelector).find(bettingFormSelector).serializeObject();
72
73
    $.ajax({
74
        url: '/saveextrabet',
75
        type: 'POST',
76
        dataType: 'json',
77
        data: data,
78
        success: function (data) {
79
            if (data.status) {
80
                showNotification("Tipp erfolgreich gespeichert!", 'success', 'nc-check-2')
81
            } else {
82
                showNotification("Fehler! 🙁", 'danger', 'nc-simple-remove')
83
84
            }
85
        },
86
        complete: function () {
87
            submitSelector.prop('disabled', false);
88
        }
89
    });
90
91
});
92
93