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": method, "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})`)); }); } /** * Load html for template selector * * @param bool clearCache true clear cache */ function TemplateSelector(clearCache) { $('.templateselector').on('hide.bs.modal', function () { $('.templateselector .modal-body').html(''); }); $('.templateselector').on('show.bs.modal', function (e) { let selectedRows = $('#datatable').DataTable().rows({selected: true}).data().toArray(); let dt_columns = selectedRows.map(v => v[5]); let jsonData = JSON.stringify(dt_columns); console.log(selectedRows.length); if (selectedRows.length == 0) { toastr.warning('Nessuna label selezionata'); e.preventDefault(); e.stopImmediatePropagation(); return true; } $('#spinnerloader').removeClass('d-none'); OMGUtils.AjaxReq(`${BASEURL}/admin/commands`, { method: 'POST', body: JSON.stringify({"method": 'TemplateSelector', "clearCache": clearCache, "dt": jsonData}) }) .then(json => { if (json.err == 0) $('.templateselector .modal-body').html(json.value); else toastr.error(json.value); }) .catch(err => toastr.error(err.url, `${err.status} (${err.statusText})`)) .finally(() => $('#spinnerloader').addClass('d-none')); }); $('.templateselector').modal('show'); } // 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; window.TemplateSelector = TemplateSelector; });