Completed
Push — master ( 90f9d4...062d56 )
by Dimas
10:08
created

etc/superuser/theme/meta/index.js   A

Complexity

Total Complexity 9
Complexity/F 3

Size

Lines of Code 99
Function Count 3

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 9
eloc 64
mnd 6
bc 6
fnc 3
dl 0
loc 99
rs 10
bpm 2
cpm 3
noi 3
c 0
b 0
f 0
1
formsaver();
2
// datatables instance
3
var table;
4
// global data for searching datatables
5
var table_search_data = "";
6
// disable alert
7
$.fn.dataTable.ext.errMode = "none";
8
table = $("#meta").DataTable({
9
  destroy: true,
10
  dom: "Bfrtip",
11
  processing: false,
12
  serverSide: false,
13
  stateSave: false,
14
  autoWidth: false,
15
  responsive: true,
16
  deferRender: true,
17
  paging: true,
18
  lengthMenu: [5, 10, 15, 20, 25, 30, 100, 200, 300, 400, 500, "All"],
19
  ajax: {
20
    url: location.href,
21
    headers: {
22
      Accept: "application/json",
23
    },
24
    method: "POST",
25
    data: {
26
      data: "",
27
      fetch: "",
28
    },
29
    dataSrc: function (res) {
30
      var data_records = [];
0 ignored issues
show
Unused Code introduced by
The assignment to variable data_records seems to be never used. Consider removing it.
Loading history...
31
32
      if (!Array.isArray(res)) {
33
        data_records = [res];
34
      } else {
35
        data_records = res;
36
      }
37
      data_records.forEach(
38
        /**
39
         *
40
         * @param {Object} v
41
         * @param {Object} v.content
42
         * @param {string} v.content.title
43
         * @param {string} v.content.desc
44
         * @param {boolean} v.content.theme
45
         * @param {Number} i
46
         */
47
        function (v, i) {
48
          if (!v.hasOwnProperty("data")) {
49
            // delete data_records[i];
50
            console.log(data_records[i]);
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...
51
            return;
52
          }
53
          v.index = i;
54
          for (const key in v.data) {
55
            if (v.data.hasOwnProperty(key)) {
56
              if (key == "published" || key == "modified") {
57
                typeInput = "datetime-local";
0 ignored issues
show
Bug introduced by
The variable typeInput 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.typeInput.
Loading history...
58
                v.data[key] = new Date(v.data[key]).toJSON().slice(0, 19);
59
              } else if (key == "desc" && typeof v.data[key] == "string") {
60
                v.data[key] = v.data[key].truncate(15);
61
              }
62
              v[key] = v.data[key];
63
            }
64
          }
65
          v.path = v.path.replace(/\\/g, "/");
66
          //console.log(v);
67
        }
68
      );
69
      //console.log(data_records);
70
      return data_records;
71
    },
72
  },
73
  columns: [
74
    {
75
      title: "Title",
76
      data: "title",
77
    },
78
    {
79
      title: "Desc",
80
      data: "desc",
81
    },
82
    {
83
      title: "Published",
84
      data: "published",
85
    },
86
    {
87
      title: "Modified",
88
      data: "modified",
89
    },
90
    {
91
      title: "Actions",
92
      data: "path",
93
      render: function (data, type, row, meta) {
94
        var form = `<form><input type='hidden' name='config' value='${data}'><button type='submit' class='btn btn-primary'><i class='fas fa-pen'></i></button></form>`;
95
        return form;
96
      },
97
    },
98
  ],
99
});
100