Completed
Push — master ( 14ccf3...48d6ba )
by Matthew
03:35
created

DT_action.js ➔ ... ➔ $table.data.ajax.reload   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
nop 0
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
    $(context).find('i').removeClass('hidden');
39
    $(context).attr('disabled','disabled');
40
    $table.find('button').attr('disabled','disabled');
41
    $table.data('datatable').ajax.reload(function () {
42
      $(context).find('i').addClass('hidden');
43
      $(context).attr('disabled',false);
44
    });
45
}
46
47
function dtc_grid_show(context) {
48
    var $table = $(context).parents('table');
49
    var id = $table.attr('id');
50
    var route = $(context).attr('data-route');
51
    var $modal = $('#' + 'modal-' + id);
52
    var identifier = $(context).attr('data-id');
53
    $modal.find('.modal-title').text('Show Id #' + identifier);
54
    $modal.modal('show');
55
    $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...
56
    $modalBody.addClass('dtc-grid-spinner');
57
    $modalBody.html('<div style="height: 50px; width: 50px;">&nbsp;</div>');
58
59
    $.ajax({
60
        url: route
61
    }).then(function (result) {
62
        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...
63
        $modalBody.removeClass('dtc-grid-spinner');
64
        $modalBody.html(dtc_grid_tablize(result));
65
    });
66
}