Load label templates and printers only when the print modal is shown and fix double validate template request [SCI-10155] (#7083)

This commit is contained in:
wandji 2024-02-15 12:42:24 +01:00 committed by GitHub
parent fd74a127ae
commit 9b356a9837
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1,6 +1,6 @@
<template>
<div ref="modal" class="modal fade" id="modal-print-repository-row-label" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<div class="modal-dialog" role="document" data-e2e="e2e-MD-printLabel">
<div class="modal-dialog" role="document" data-e2e="e2e-MD-printLabel" v-if="showModal && fetchedPrintersAndTemplates">
<div class="modal-content">
<div v-if="availablePrinters.length > 0" class="printers-available">
<div class="modal-header">
@ -112,7 +112,8 @@ export default {
copies: 1,
zebraPrinters: null,
labelTemplateError: null,
labelTemplateCode: null
labelTemplateCode: null,
fetchedPrintersAndTemplates: false
};
},
components: {
@ -120,13 +121,18 @@ export default {
LabelPreview
},
mounted() {
$.get(this.urls.labelTemplates, (result) => {
this.templates = result.data;
this.selectDefaultLabelTemplate();
});
$(this.$refs.modal).on('show.bs.modal', () => {
if (!this.fetchedPrintersAndTemplates) {
$.get(this.urls.labelTemplates, (result) => {
this.templates = result.data;
this.selectDefaultLabelTemplate();
});
$.get(this.urls.printers, (result) => {
this.printers = result.data;
$.get(this.urls.printers, (result) => {
this.printers = result.data;
});
this.fetchedPrintersAndTemplates = true;
}
});
$(this.$refs.modal).on('hidden.bs.modal', () => {
@ -163,7 +169,9 @@ export default {
if (this.showModal) {
this.initZebraPrinter();
$(this.$refs.modal).modal('show');
this.validateTemplate();
if (!this.fetchedPrintersAndTemplates) {
this.validateTemplate();
}
}
},
row_ids() {