Passed
Push — v5.x ( 0160d0 )
by Thierry
09:10
created

templates/jqueryconfirm/alert.js   A

Complexity

Total Complexity 14
Complexity/F 1.56

Size

Lines of Code 62
Function Count 9

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 43
c 0
b 0
f 0
dl 0
loc 62
rs 10
wmc 14
mnd 5
bc 5
fnc 9
bpm 0.5555
cpm 1.5555
noi 10
1
jaxon.dialogs.jconfirm = {
2
    dialog: null,
3
    show: (args) => {
4
        // Add buttons
5
        for(key in args.data.buttons)
6
        {
7
            button = args.data.buttons[key];
8
            button.action = button.action !== 'close' ? new Function(button.action) :
9
                () => jaxon.dialogs.jconfirm.dialog.close();
10
        }
11
        args.data.closeIcon = true;
12
        if((jaxon.dialogs.jconfirm.dialog))
13
        {
14
            jaxon.dialogs.jconfirm.dialog.close();
15
        }
16
        jaxon.dialogs.jconfirm.dialog = $.confirm(args.data);
17
    },
18
    hide: (args) => {
19
        if((jaxon.dialogs.jconfirm.dialog))
20
        {
21
            jaxon.dialogs.jconfirm.dialog.close();
22
        }
23
        jaxon.dialogs.jconfirm.dialog = null;
24
    },
25
    success: (content, title) => $.alert({content: content, title: title, type: 'green', icon: 'fa fa-success'}),
26
    info: (content, title) => $.alert({content: content, title: title, type: 'blue', icon: 'fa fa-info'}),
27
    warning: (content, title) => $.alert({content: content, title: title, type: 'orange', icon: 'fa fa-warning'}),
28
    error: (content, title) => $.alert({content: content, title: title, type: 'red', icon: 'fa fa-error'}),
29
    confirm: (question, title, yesCallback, noCallback) => $.confirm({
30
        title: title,
31
        content: question,
32
        buttons: {
33
            yes: {
34
                btnClass: "btn-blue",
35
                text: "<?php echo $this->yes ?>",
36
                action: yesCallback
37
            },
38
            no: {
39
                text: "<?php echo $this->no ?>",
40
                action: noCallback ?? (() => {}),
41
            }
42
        }
43
    }),
44
};
45