Sha256: 58c562e7bf51e9669e703c5fe6fc3871e26e1201daf0ab8321a8b5c5dda707c0
Contents?: true
Size: 1.95 KB
Versions: 1
Compression:
Stored size: 1.95 KB
Contents
module Concept module SKOSXL module Extension extend ActiveSupport::Concern included do validate :valid_label_language after_save do |concept| # Labelings (@labelings_by_id ||= {}).each do |labeling_relation_name, origin_mappings| # Remove all associated labelings of the given type concept.send(labeling_relation_name).destroy_all # (Re)create labelings reflecting a widget's parameters origin_mappings.each do |language, new_origins| new_origins = new_origins. split(Iqvoc::InlineDataHelper::Splitter).map(&:squish) # Iterate over all labels to be added and create them Iqvoc::XLLabel.base_class.by_origin(new_origins).each do |l| concept.send(labeling_relation_name).create!(:target => l) end end end end def valid_label_language (@labelings_by_id || {}).each { |labeling_class_name, origin_mappings| origin_mappings.each { |language, new_origins| new_origins = new_origins.split(Iqvoc::InlineDataHelper::Splitter) Iqvoc::XLLabel.base_class.by_origin(new_origins).each do |label| if label.language != language.to_s errors.add(:base, I18n.t("txt.controllers.versioned_concept.label_error") % label) end end } } end end module InstanceMethods def labelings_by_id=(hash) @labelings_by_id = hash end def labelings_by_id(relation_name, language) (@labelings_by_id && @labelings_by_id[relation_name] && @labelings_by_id[relation_name][language]) || self.send(relation_name).by_label_language(language). map { |l| l.target.origin }.join(Iqvoc::InlineDataHelper::Joiner) end end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
iqvoc_skosxl-1.1.4 | app/models/concept/skosxl/extension.rb |