Completed
Push — master ( 2817bb...6f8d46 )
by
unknown
03:26
created

assets/js/gameBettingSubmit.js   A

Size

Lines of Code 1

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 1
rs 10
c 0
b 0
f 0
noi 3
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
3
    $.notify({
4
        icon: "nc-icon "+icon,
5
        message: message
6
7
    }, {
8
        type: color,
9
        delay: 100,
10
        placement: {
11
            from: 'top',
12
            align: 'center'
13
        }
14
    });
15
};
16
17
$.fn.serializeObject = function()
18
{
19
    let o = {};
20
    let a = this.serializeArray();
21
    $.each(a, function() {
22
        if (o[this.name] !== undefined) {
23
            if (!o[this.name].push) {
24
                o[this.name] = [o[this.name]];
25
            }
26
            o[this.name].push(this.value || '');
27
        } else {
28
            o[this.name] = this.value || '';
29
        }
30
    });
31
    return o;
32
};
33
34
$(document).on("click", ".save-bet-button", function(event){
35
    event.preventDefault();
36
    let $_target = $(event.target);
37
    let bettingWrapperSelector = $('.betting-wrapper');
38
    let bettingFormSelector = $('.user-betting-form');
39
    let firstTeamResultSelector = $('.first-team-result');
0 ignored issues
show
Unused Code introduced by
The variable firstTeamResultSelector seems to be never used. Consider removing it.
Loading history...
40
    let secondTeamResultSelector = $('.second-team-result');
0 ignored issues
show
Unused Code introduced by
The variable secondTeamResultSelector seems to be never used. Consider removing it.
Loading history...
41
42
    let data = $_target.closest(bettingWrapperSelector).find(bettingFormSelector).serializeObject();
43
44
    $.ajax({
45
        url: '/savebet',
46
        type: 'POST',
47
        dataType: 'json',
48
        data: data,
49
        success:function(data){
50
            if(data.status ){
51
                
52
                showNotification("Tipp erfolgreich gespeichert!", 'success', 'nc-check-2')
53
            } else {
54
                showNotification("Fehler! 🙁", 'danger', 'nc-simple-remove')
55
56
            }
57
        }
58
    });
59
60
});