Select default label template based on selected pritner type [SCI-7268][7257] (#4475)

This commit is contained in:
ajugo 2022-09-29 14:47:59 +02:00 committed by GitHub
parent 69bc48fef8
commit 103bdff654
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 2 deletions

View file

@ -36,6 +36,7 @@
</label>
<DropdownSelector
ref="labelTemplateDropdown"
:disableSearch="true"
:options="templates_dropdown"
:selectorId="`LabelTemplateSelector`"
@ -121,6 +122,7 @@
mounted() {
$.get(this.urls.labelTemplates, (result) => {
this.templates = result.data
this.selectDefaultLabelTemplate();
})
$.get(this.urls.printers, (result) => {
@ -172,8 +174,20 @@
}
},
methods: {
selectDefaultLabelTemplate() {
if (this.selectedPrinter && this.templates) {
let template = this.templates.find(i => i.attributes.default
&& i.type.includes(this.selectedPrinter.attributes.type_of));
if (template) {
this.$nextTick(() => {
this.$refs.labelTemplateDropdown.selectValues(template.id);
});
}
}
},
selectPrinter(value) {
this.selectedPrinter = this.printers.find(i => i.id === value);
this.selectedPrinter = this.printers.find(i => i.id === value)
this.selectDefaultLabelTemplate();
},
selectTemplate(value) {
this.selectedTemplate = this.templates.find(i => i.id === value);

View file

@ -130,6 +130,9 @@
'dropdown:changed',
value
);
},
selectValues(value) {
dropdownSelector.selectValues(`#${this.selectorId}`, value);
}
}
}

View file

@ -4,7 +4,7 @@ class LabelTemplateSerializer < ActiveModel::Serializer
include Canaid::Helpers::PermissionsHelper
include Rails.application.routes.url_helpers
attributes :name, :description, :language_type, :icon_url, :urls, :content, :type
attributes :name, :description, :language_type, :icon_url, :urls, :content, :type, :default
def icon_url
ActionController::Base.helpers.image_path("label_template_icons/#{object.icon}.svg")