Sha256: 874dbfa591ce1c8d447e02122282e1c2fb80801c3c495eb2c5b8eefebc87f7ea

Contents?: true

Size: 1.39 KB

Versions: 30

Compression:

Stored size: 1.39 KB

Contents

module ActiveScaffold::Bridges
  class Ancestry
    module AncestryBridge
      def initialize(model_id)
        super(model_id)

        return unless model.respond_to? :ancestry_column

        columns << :parent_id
        columns[:parent_id].form_ui = :ancestry
        update.columns.exclude :ancestry
        create.columns.exclude :ancestry, :parent_id
        list.columns.exclude :ancestry, :parent_id
      end
    end

    module FormColumnHelpers
      def active_scaffold_input_ancestry(column, options)
        record = options[:object]
        select_options = []
        select_control_options = {:selected => record.parent_id}
        select_control_options[:include_blank] = as_(:_select_) if record.parent_id.nil?
        method = column.options[:label_method] || :to_label
        traverse_ancestry = proc do |key, value|
          unless key == record
            select_options << ["#{'__' * key.depth}#{key.send(method)}", key.id]
            value.each(&traverse_ancestry) if value.is_a?(Hash) && !value.empty?
          end
        end
        record.class.arrange.each(&traverse_ancestry)
        select(:record, :ancestry, select_options, select_control_options, options)
      end
    end
  end
end

ActionView::Base.class_eval do
  include ActiveScaffold::Bridges::Ancestry::FormColumnHelpers
end
ActiveScaffold::Config::Core.send :prepend, ActiveScaffold::Bridges::Ancestry::AncestryBridge

Version data entries

30 entries across 30 versions & 1 rubygems

Version Path
active_scaffold-3.7.0 lib/active_scaffold/bridges/ancestry/ancestry_bridge.rb
active_scaffold-3.6.20 lib/active_scaffold/bridges/ancestry/ancestry_bridge.rb
active_scaffold-3.6.19 lib/active_scaffold/bridges/ancestry/ancestry_bridge.rb
active_scaffold-3.6.17 lib/active_scaffold/bridges/ancestry/ancestry_bridge.rb
active_scaffold-3.6.15 lib/active_scaffold/bridges/ancestry/ancestry_bridge.rb
active_scaffold-3.6.14 lib/active_scaffold/bridges/ancestry/ancestry_bridge.rb
active_scaffold-3.6.13 lib/active_scaffold/bridges/ancestry/ancestry_bridge.rb
active_scaffold-3.6.12 lib/active_scaffold/bridges/ancestry/ancestry_bridge.rb
active_scaffold-3.6.11.1 lib/active_scaffold/bridges/ancestry/ancestry_bridge.rb
active_scaffold-3.6.11 lib/active_scaffold/bridges/ancestry/ancestry_bridge.rb
active_scaffold-3.6.10 lib/active_scaffold/bridges/ancestry/ancestry_bridge.rb
active_scaffold-3.6.9 lib/active_scaffold/bridges/ancestry/ancestry_bridge.rb
active_scaffold-3.6.8 lib/active_scaffold/bridges/ancestry/ancestry_bridge.rb
active_scaffold-3.6.6 lib/active_scaffold/bridges/ancestry/ancestry_bridge.rb
active_scaffold-3.6.5 lib/active_scaffold/bridges/ancestry/ancestry_bridge.rb
active_scaffold-3.6.4.1 lib/active_scaffold/bridges/ancestry/ancestry_bridge.rb
active_scaffold-3.6.4 lib/active_scaffold/bridges/ancestry/ancestry_bridge.rb
active_scaffold-3.6.3 lib/active_scaffold/bridges/ancestry/ancestry_bridge.rb
active_scaffold-3.6.2 lib/active_scaffold/bridges/ancestry/ancestry_bridge.rb
active_scaffold-3.6.1 lib/active_scaffold/bridges/ancestry/ancestry_bridge.rb