| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 |
- import {AjaxReq} from "./OMGUtils";
- // PRIVATE METHODS
- const COL_ID_IDX = 1;
- const COL_RESOLUTION_IDX = 7;
- // MAIN CLASS
- export class ModalTemplateSelector {
- constructor(modalClass) {
- let self = this;
- this.modalClass = modalClass;
- this.timer = null;
- this.AbortLoadTemplate = null;
- $(modalClass).on('hide.bs.modal', function () {
- self.AbortLoadTemplate();
- self.ClearModal();
- });
- }
- ClearModal() {
- $(`${this.modalClass} .modal-body`).html('Loading Templates...');
- }
- /**
- * Change display of ESL labels
- *
- * @param arrLabels
- * @param idTemplate
- */
- setTemplate(arrLabels, idTemplate) {
- AjaxReq(`${BASEURL}/admin/config`, {
- method: 'POST',
- body: JSON.stringify({
- "method": "SetDisplay",
- "labels": arrLabels,
- "id": idTemplate
- })
- }).fetchPromise()
- .then(json => {
- $(`${this.modalClass}`).modal('hide');
- toastr.success(json.err);
- })
- .catch(err => toastr.error(err.url, `${err.status} (${err.statusText})`));
- }
- Open(clearCache) {
- let self = this;
- let selectedRows = $('#datatable').DataTable().rows({selected: true}).data().toArray();
- let selectedLabels = selectedRows.map(v => v[COL_ID_IDX]);
- let resolutions = selectedRows.map(v => v[COL_RESOLUTION_IDX]);
- if (selectedRows.length === 0) {
- toastr.warning('Nessuna label selezionata');
- return;
- }
- $(`${this.modalClass}`).modal('show');
- $('#spinnerloader').removeClass('d-none');
- let req = AjaxReq(`${BASEURL}/admin/config`, {
- method: 'POST',
- body: JSON.stringify({
- "method": 'TemplateSelector',
- "clearCache": clearCache,
- "resolution": resolutions
- })
- });
- this.AbortLoadTemplate = req.abort;
- req.fetchPromise()
- .then(json => {
- if (json.err === 0) {
- $(`${self.modalClass} .modal-body`).html(json.value);
- // Add onlick event to all template thumbs
- $(`${self.modalClass} a`).on('click', function () {
- self.setTemplate(selectedLabels, this.id);
- });
- } else
- toastr.error(json.value);
- })
- .catch(err => {
- if (err.name === 'AbortError')
- return;
- if (err.url !== undefined)
- toastr.error(err.url, `${err.status} (${err.statusText})`);
- else
- toastr.error(err);
- })
- .finally(function () {
- $('#spinnerloader').addClass('d-none')
- });
- }
- }
|