Sha256: b6d61fd639b686c122d6505d74c30bd8d5767689f59c28f52732ef7970e99576

Contents?: true

Size: 1.33 KB

Versions: 7

Compression:

Stored size: 1.33 KB

Contents

# -*- encoding : utf-8 -*-

def list_fields
  Card.search({ left: name, type_id: Card::ListID }, 'list fields')
end

def listed_by_fields
  Card.search({ left: name, type_id: Card::ListedByID }, 'listed by fields')
end

def linker_lists
  Card.search({ type_id: Card::ListID, link_to: name },
              "lists that link to #{name}")
end

event :trunk_cardtype_of_a_list_relation_changed, :finalize,
      changed: :type, on: :update,
      when: proc { Codename[:list] } do
  type_key_was = (tk = Card.quick_fetch(type_id_was)) && tk.key

  list_fields.each do |card|
    card.update_listed_by_cache_for card.item_keys, type_key: type_key_was
    card.update_listed_by_cache_for card.item_keys
  end
  listed_by_fields.each &:update_cached_list
end

event :trunk_name_of_a_list_relation_changed, :finalize,
      changed: :name,  on: :update,
      when: proc { Codename[:list] } do
  list_fields.each do |card|
    card.update_listed_by_cache_for card.item_keys
  end
  listed_by_fields.each &:update_cached_list
end

event :cardtype_of_list_item_changed, :validate,
      changed: :type, on: :save,
      when: proc { Codename[:list] } do
  linker_lists.each do |card|
    next unless card.item_type_id != type_id
    errors.add(:type,
               "can't be changed because #{name} " \
               "is referenced by list card #{card.name}")
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
card-1.18.6 mod/05_standard/set/all/list_changes.rb
card-1.18.5 mod/05_standard/set/all/list_changes.rb
card-1.18.4 mod/05_standard/set/all/list_changes.rb
card-1.18.3 mod/05_standard/set/all/list_changes.rb
card-1.18.2 mod/05_standard/set/all/list_changes.rb
card-1.18.1 mod/05_standard/set/all/list_changes.rb
card-1.18.0 mod/05_standard/set/all/list_changes.rb