Completed
Push — master ( 209945...41a4bc )
by Matthew
07:41 queued 03:34
created

Resources/public/js/jquery.datatable/DT_action.js   A

Complexity

Total Complexity 11
Complexity/F 1.57

Size

Lines of Code 60
Function Count 7

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 0
nc 1
dl 0
loc 60
rs 10
c 0
b 0
f 0
wmc 11
mnd 2
bc 11
fnc 7
bpm 1.5713
cpm 1.5713
noi 3

3 Functions

Rating   Name   Duplication   Size   Complexity  
A DT_action.js ➔ dtc_grid_show 0 20 1
A DT_action.js ➔ dtc_grid_refresh 0 8 2
A DT_action.js ➔ dtc_grid_delete 0 12 1
1
function dtc_grid_tablize(value) {
2
    var table = "<table class=\"table table-bordered\"><thead><th>Column</th><th>Value</th></thead></thead><tbody>";
3
    var stringifyValue = function (value) {
4
        if (typeof(value) === 'object') {
5
            return dtc_grid_tablize(value);
6
        }
7
        return $('<div />').text(value).html();
8
    }
9
10
    for (var prop in value) {
11
        if (value.hasOwnProperty(prop)) {
12
            table += "<tr><td>" + stringifyValue(prop) + "</td><td>" + stringifyValue(value[prop]) + "</td></tr>";
13
        }
14
    }
15
    table += "</tbody></table>";
16
    return table;
17
}
18
19
function dtc_grid_delete(context) {
20
    var $table = $(context).parents('table');
21
    var id = $table.attr('id');
0 ignored issues
show
Unused Code introduced by
The variable id seems to be never used. Consider removing it.
Loading history...
22
    var route = $(context).attr('data-route');
23
    $(context).find('i').removeClass('hidden');
24
    $table.find('button').attr('disabled','disabled');
25
    $.ajax({
26
        url: route
27
    }).then(function () {
28
        $table.data('datatable').ajax.reload();
29
    })
30
}
31
32
function dtc_grid_refresh(context) {
33
    var id = $(context).attr('data-id');
34
    var $table = $('#' + id);
35
    if (!$table.get(0)) {
36
        return;
37
    }
38
    $table.data('datatable').ajax.reload();
39
}
40
41
function dtc_grid_show(context) {
42
    var $table = $(context).parents('table');
43
    var id = $table.attr('id');
44
    var route = $(context).attr('data-route');
45
    var $modal = $('#' + 'modal-' + id);
46
    var identifier = $(context).attr('data-id');
47
    $modal.find('.modal-title').text('Show Id #' + identifier);
48
    $modal.modal('show');
49
    $modalBody = $modal.find('.modal-body');
0 ignored issues
show
Bug introduced by
The variable $modalBody 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.$modalBody.
Loading history...
50
    $modalBody.addClass('dtc-grid-spinner');
51
    $modalBody.html('<div style="height: 50px; width: 50px;">&nbsp;</div>');
52
53
    $.ajax({
54
        url: route
55
    }).then(function (result) {
56
        console.log(result);
0 ignored issues
show
Debugging Code introduced by
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
57
        $modalBody.removeClass('dtc-grid-spinner');
58
        $modalBody.html(dtc_grid_tablize(result));
59
    });
60
}