mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2024-11-10 17:36:33 +08:00
a3ea6e608c
* Add validation to print modal [SCI-7052] * Fix dropdown on label modal print [SCI-7052] * Fix hound [SCI-7052] * Rename validation endpoint [SCI-7052] * Add zpl label printing and fix fluics printing [SCI-7221] * Fix hound [SCI-7221]
44 lines
1 KiB
Ruby
44 lines
1 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
class LabelTemplate < ApplicationRecord
|
|
include SearchableModel
|
|
|
|
belongs_to :team
|
|
belongs_to :created_by, class_name: 'User', optional: true
|
|
belongs_to :last_modified_by, class_name: 'User', optional: true
|
|
|
|
validates :name, presence: true, length: { minimum: Constants::NAME_MIN_LENGTH,
|
|
maximum: Constants::NAME_MAX_LENGTH }
|
|
validates :content, presence: true
|
|
|
|
validate :ensure_single_default_template!
|
|
|
|
def self.enabled?
|
|
ApplicationSettings.instance.values['label_templates_enabled']
|
|
end
|
|
|
|
def icon
|
|
'zpl'
|
|
end
|
|
|
|
def language_type
|
|
'zpl'
|
|
end
|
|
|
|
def read_only?
|
|
false
|
|
end
|
|
|
|
def label_format
|
|
Extends::LABEL_TEMPLATE_FORMAT_MAP[type]
|
|
end
|
|
|
|
private
|
|
|
|
def ensure_single_default_template!
|
|
if default && self.class.where(team_id: team_id, default: true, type: type)
|
|
.where.not(id: id).any?
|
|
errors.add(:default, I18n.t('activerecord.errors.models.label_template.attributes.default.already_exist'))
|
|
end
|
|
end
|
|
end
|