| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146 |
- 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;
- });
|