Passed
Push — master ( c9d535...a1a723 )
by Thierry
10:07 queued 02:14
created

templates/bootstrap/alert.js   A

Complexity

Total Complexity 14
Complexity/F 1.4

Size

Lines of Code 59
Function Count 10

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 40
c 0
b 0
f 0
dl 0
loc 59
rs 10
wmc 14
mnd 4
bc 4
fnc 10
bpm 0.4
cpm 1.4
noi 15
1
/*
2
 * Bootstrap dialogs plugin
3
 */
4
jaxon.dialogs.bootstrap = {
5
    show: function(args) {
6
        // Open modal
7
        BootstrapDialog.show({
8
            ...args.data,
9
            buttons: args.data.buttons.map(button => {
10
                return {
11
                    ...button,
12
                    action: button.action === 'close' ? function(dialog){dialog.close();} : new Function(button.action),
13
                };
14
            }),
15
        });
16
    },
17
    hide: function(args) {
18
        // Hide modal
19
        BootstrapDialog.closeAll();
20
    },
21
    alert: function(args) {
22
        var dataTypes = {
23
            success: BootstrapDialog.TYPE_SUCCESS,
24
            info: BootstrapDialog.TYPE_INFO,
25
            warning: BootstrapDialog.TYPE_WARNING,
26
            danger: BootstrapDialog.TYPE_DANGER
27
        };
28
        args.data.type = dataTypes[args.data.type];
29
        BootstrapDialog.alert(args.data);
30
    },
31
    success: function(content, title) {
32
        BootstrapDialog.alert({type: BootstrapDialog.TYPE_SUCCESS, message: content, title: title});
33
    },
34
    info: function(content, title) {
35
        BootstrapDialog.alert({type: BootstrapDialog.TYPE_INFO, message: content, title: title});
36
    },
37
    warning: function(content, title) {
38
        BootstrapDialog.alert({type: BootstrapDialog.TYPE_WARNING, message: content, title: title});
39
    },
40
    error: function(content, title) {
41
        BootstrapDialog.alert({type: BootstrapDialog.TYPE_DANGER, message: content, title: title});
42
    },
43
    confirm: function(question, title, yesCallback, noCallback) {
44
        BootstrapDialog.confirm({
45
            title: title,
46
            message: question,
47
            btnOKLabel: "<?php echo $this->yes ?>",
48
            btnCancelLabel: "<?php echo $this->no ?>",
49
            callback: function(res){
50
                if(res)
51
                    yesCallback();
52
                else if(noCallback != undefined)
53
                    noCallback();
54
            }
55
        });
56
    }
57
};
58