import {ModalEslDetails} from "./ModalEslDetails"; import * as OMGUtils from "./OMGUtils"; let modalEslDetails = null; function SaveConfig() { let config = $('#config_text').val(); OMGUtils.AjaxReq(`${BASEURL}/admin/config`, { method: 'POST', body: JSON.stringify({"method": "saveconfig", "value": config}) }) .then(json => toastr.success(json.err)) .catch(err => toastr.error(err.url, `${err.status} (${err.statusText})`)); } function LoadConfig() { OMGUtils.AjaxReq(`${BASEURL}/admin/config`, { method: 'POST', body: JSON.stringify({"method": "loadconfig"}) }) .then(json => { $('#config_text').val(json.value); toastr.success(json.err); }) .catch(err => toastr.error(err.url, `${err.status} (${err.statusText})`)); } function OpenESLDetails(labelID) { modalEslDetails.OpenESLDetails(labelID); } function ESLMultiOperations(method) { let selectedLabels = $('#datatable').DataTable().rows({selected: true}).data().toArray(); selectedLabels.forEach(labelID => { OMGUtils.AjaxReq(`${BASEURL}/admin/config`, { method: 'POST', body: JSON.stringify({"method": "blinklabels", "labelid": labelID[1]}) }) .then(json => { if (json.err == 0) toastr.success(json.value); else toastr.error(json.value); }) .catch(err => toastr.error(err.url, `${err.status} (${err.statusText})`)); }); } // MAIN JS document.addEventListener('DOMContentLoaded', function () { modalEslDetails = new ModalEslDetails('.statusmodal'); Waves.attach('.btn', ['waves-effect', 'waves-light']); Waves.init(); $.fn.dataTable.ext.order['dom-checkbox'] = function (settings, col) { return this.api().column(col, {order: 'index'}).nodes().map(function (td, i) { return $(td).closest('tr').hasClass('selected') ? '1' : '0'; }); }; // DataTable fix $("#datatable").DataTable({ paging: false, scrollY: true, responsive: true, fnInitComplete: function () { $(".dataTables_scrollBody").slimscroll({ color: "#DDDDDD", railVisible: true, railColor: "black", railOpacity: .3, height: "50vh" }) }, columnDefs: [ { targets: 0, className: 'select-checkbox', orderDataType: "dom-checkbox" }, { targets: -1, orderable: false } ], select: { style: 'multi', selector: 'td:first-child', } }); window.OpenESLDetails = OpenESLDetails; window.LoadConfig = LoadConfig; window.SaveConfig = SaveConfig; window.ESLMultiOperations = ESLMultiOperations; });