Sha256: de991effd4b1d3de682b916134470ebb6500d04be491b2e83fc983fea025bfab
Contents?: true
Size: 1.87 KB
Versions: 4
Compression:
Stored size: 1.87 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 end 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 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 end end
Version data entries
4 entries across 4 versions & 1 rubygems