admin.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. import {ModalEslDetails} from "./ModalEslDetails";
  2. import * as OMGUtils from "./OMGUtils";
  3. let modalEslDetails = null;
  4. function SaveConfig() {
  5. let config = $('#config_text').val();
  6. OMGUtils.AjaxReq(`${BASEURL}/admin/config`, {
  7. method: 'POST',
  8. body: JSON.stringify({"method": "saveconfig", "value": config})
  9. })
  10. .then(json => toastr.success(json.err))
  11. .catch(err => toastr.error(err.url, `${err.status} (${err.statusText})`));
  12. }
  13. function LoadConfig() {
  14. OMGUtils.AjaxReq(`${BASEURL}/admin/config`, {
  15. method: 'POST',
  16. body: JSON.stringify({"method": "loadconfig"})
  17. })
  18. .then(json => {
  19. $('#config_text').val(json.value);
  20. toastr.success(json.err);
  21. })
  22. .catch(err => toastr.error(err.url, `${err.status} (${err.statusText})`));
  23. }
  24. function OpenESLDetails(labelID) {
  25. modalEslDetails.OpenESLDetails(labelID);
  26. }
  27. function ESLMultiOperations(method) {
  28. let selectedLabels = $('#datatable').DataTable().rows({selected: true}).data().toArray();
  29. selectedLabels.forEach(labelID => {
  30. OMGUtils.AjaxReq(`${BASEURL}/admin/config`, {
  31. method: 'POST',
  32. body: JSON.stringify({"method": method, "labelid": labelID[1]})
  33. })
  34. .then(json => {
  35. if (json.err == 0)
  36. toastr.success(json.value);
  37. else
  38. toastr.error(json.value);
  39. })
  40. .catch(err => toastr.error(err.url, `${err.status} (${err.statusText})`));
  41. });
  42. }
  43. function TemplateSelector() {
  44. $('.templateselector').on('shown.bs.modal', function () {
  45. let selectedLabels = $('#datatable').DataTable().rows({selected: true}).data().toArray();
  46. let labels = selectedLabels.map(v => [v[1], v[5]]);
  47. let listedTypes = selectedLabels.map(v => [v[5]]);
  48. console.log(listedTypes.uniq());
  49. //console.log(labels.countOccurrences(1, 31));
  50. /*
  51. OMGUtils.AjaxReq(`${BASEURL}/admin/templates/@dt/@clearcache`, {
  52. method: 'POST',
  53. body: JSON.stringify({"method": method, "labelid": labelID[1]})
  54. })
  55. .then(json => {
  56. if (json.err == 0)
  57. toastr.success(json.value);
  58. else
  59. toastr.error(json.value);
  60. })
  61. .catch(err => toastr.error(err.url, `${err.status} (${err.statusText})`));
  62. */
  63. });
  64. $('.templateselector').modal('show');
  65. }
  66. // MAIN JS
  67. document.addEventListener('DOMContentLoaded', function () {
  68. modalEslDetails = new ModalEslDetails('.statusmodal');
  69. Waves.attach('.btn', ['waves-effect', 'waves-light']);
  70. Waves.init();
  71. $.fn.dataTable.ext.order['dom-checkbox'] = function (settings, col) {
  72. return this.api().column(col, {order: 'index'}).nodes().map(function (td, i) {
  73. return $(td).closest('tr').hasClass('selected') ? '1' : '0';
  74. });
  75. };
  76. // DataTable fix
  77. $("#datatable").DataTable({
  78. paging: false,
  79. scrollY: true,
  80. responsive: true,
  81. fnInitComplete: function () {
  82. $(".dataTables_scrollBody").slimscroll({
  83. color: "#DDDDDD",
  84. railVisible: true,
  85. railColor: "black",
  86. railOpacity: .3,
  87. height: "50vh"
  88. })
  89. },
  90. columnDefs: [
  91. {
  92. targets: 0,
  93. className: 'select-checkbox',
  94. orderDataType: "dom-checkbox"
  95. },
  96. {
  97. targets: -1,
  98. orderable: false
  99. }
  100. ],
  101. select: {
  102. style: 'multi',
  103. selector: 'td:first-child',
  104. }
  105. });
  106. window.OpenESLDetails = OpenESLDetails;
  107. window.LoadConfig = LoadConfig;
  108. window.SaveConfig = SaveConfig;
  109. window.ESLMultiOperations = ESLMultiOperations;
  110. window.TemplateSelector = TemplateSelector;
  111. });