|
|
@@ -1,56 +1,64 @@
|
|
|
import {AjaxReq} from "./OMGUtils";
|
|
|
|
|
|
-// Private Methods
|
|
|
-
|
|
|
-/**
|
|
|
- * Change display of ESL labels
|
|
|
- *
|
|
|
- * @param arrLabels
|
|
|
- * @param idTemplate
|
|
|
- */
|
|
|
-function SetTemplate(arrLabels, idTemplate) {
|
|
|
- AjaxReq(`${BASEURL}/admin/config`, {
|
|
|
- method: 'POST',
|
|
|
- body: JSON.stringify({
|
|
|
- "method": "SetDisplay",
|
|
|
- "labels": arrLabels,
|
|
|
- "id": idTemplate
|
|
|
- })
|
|
|
- }).fetchPromise()
|
|
|
- .then(json => {
|
|
|
- $('.templateselector').modal('hide');
|
|
|
- toastr.success(json.err);
|
|
|
- })
|
|
|
- .catch(err => toastr.error(err.url, `${err.status} (${err.statusText})`));
|
|
|
-}
|
|
|
+// 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();
|
|
|
+ });
|
|
|
+ }
|
|
|
|
|
|
-/**
|
|
|
- * Load html for template selector
|
|
|
- *
|
|
|
- * @param bool clearCache true clear cache
|
|
|
- */
|
|
|
-function TemplateSelector(clearCache) {
|
|
|
+ ClearModal() {
|
|
|
+ $(`${this.modalClass} .modal-body`).html('Loading Templates...');
|
|
|
+ }
|
|
|
|
|
|
- let AbortLoadTemplate;
|
|
|
+ /**
|
|
|
+ * 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})`));
|
|
|
+ }
|
|
|
|
|
|
- $('.templateselector').on('hide.bs.modal', function () {
|
|
|
- $('#spinnerloader').addClass('d-none');
|
|
|
- AbortLoadTemplate();
|
|
|
- $('.templateselector .modal-body').html('');
|
|
|
- });
|
|
|
+ Open(clearCache) {
|
|
|
+ let self = this;
|
|
|
|
|
|
- $('.templateselector').on('show.bs.modal', function (e) {
|
|
|
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) {
|
|
|
+ if (selectedRows.length === 0) {
|
|
|
toastr.warning('Nessuna label selezionata');
|
|
|
- e.preventDefault();
|
|
|
- e.stopImmediatePropagation();
|
|
|
- return true;
|
|
|
+ return;
|
|
|
}
|
|
|
|
|
|
+ $(`${this.modalClass}`).modal('show');
|
|
|
+
|
|
|
$('#spinnerloader').removeClass('d-none');
|
|
|
|
|
|
let req = AjaxReq(`${BASEURL}/admin/config`, {
|
|
|
@@ -62,48 +70,31 @@ function TemplateSelector(clearCache) {
|
|
|
})
|
|
|
});
|
|
|
|
|
|
- AbortLoadTemplate = req.abort;
|
|
|
+ this.AbortLoadTemplate = req.abort;
|
|
|
|
|
|
req.fetchPromise()
|
|
|
.then(json => {
|
|
|
- if (json.err == 0) {
|
|
|
- $('.templateselector .modal-body').html(json.value);
|
|
|
+ if (json.err === 0) {
|
|
|
+ $(`${self.modalClass} .modal-body`).html(json.value);
|
|
|
|
|
|
// Add onlick event to all template thumbs
|
|
|
- $('.templateselector a').on('click', function () {
|
|
|
- SetTemplate(selectedLabels, this.id);
|
|
|
+ $(`${self.modalClass} a`).on('click', function () {
|
|
|
+ self.setTemplate(selectedLabels, this.id);
|
|
|
});
|
|
|
|
|
|
} else
|
|
|
toastr.error(json.value);
|
|
|
})
|
|
|
- .catch(err => toastr.error(err.url, `${err.status} (${err.statusText})`))
|
|
|
- .finally(() => $('#spinnerloader').addClass('d-none'));
|
|
|
- });
|
|
|
-
|
|
|
- $('.templateselector').modal('show');
|
|
|
-}
|
|
|
-
|
|
|
-// MAIN CLASS
|
|
|
-export class ModalTemplateSelector {
|
|
|
- constructor(modalClass) {
|
|
|
- let self = this;
|
|
|
-
|
|
|
- this.abort = null;
|
|
|
- this.modalClass = modalClass;
|
|
|
- this.timer = null;
|
|
|
-
|
|
|
-
|
|
|
- $(modalClass).on('show.bs.modal', function () {
|
|
|
- });
|
|
|
-
|
|
|
- $(modalClass).on('hide.bs.modal', function () {
|
|
|
- self.abort();
|
|
|
- clearTimeout(self.timer);
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
- OpenESLDetails(labelID) {
|
|
|
- $(`${this.modalClass}`).modal('show');
|
|
|
+ .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')
|
|
|
+ });
|
|
|
}
|
|
|
}
|