Sha256: cce792dde0faaa3d6f7df5f5d8c171698bf51cd43fd9d1580e6c28dbf6132937

Contents?: true

Size: 1.27 KB

Versions: 60

Compression:

Stored size: 1.27 KB

Contents

ActiveScaffold::Config::Core.class_eval do
  def initialize_with_ancestry(model_id)
    initialize_without_ancestry(model_id)

    return unless self.model.respond_to? :ancestry_column
    
    self.columns << :parent_id
    self.columns[:parent_id].form_ui = :ancestry
    update.columns.exclude :ancestry
    create.columns.exclude :ancestry, :parent_id
    list.columns.exclude :ancestry, :parent_id
  end

  alias_method_chain :initialize, :ancestry
end

module ActiveScaffold
  module AncestryBridge
    module FormColumnHelpers
      def active_scaffold_input_ancestry(column, options)
        select_options = []
        select_control_options = {:selected => @record.parent_id}
        select_control_options[:include_blank] = as_(:_select_) if @record.parent_id.nil?
        traverse_ancestry = proc do|key, value|
          unless key == @record
            select_options << ["#{'__' * key.depth}#{key.to_label}", 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::AncestryBridge::FormColumnHelpers
end

Version data entries

60 entries across 60 versions & 4 rubygems

Version Path
active_scaffold_vho-4.0.0 lib/active_scaffold/bridges/ancestry/lib/ancestry_bridge.rb
active_scaffold_vho-3.2.14 lib/active_scaffold/bridges/ancestry/lib/ancestry_bridge.rb
active_scaffold_vho-3.2.13 lib/active_scaffold/bridges/ancestry/lib/ancestry_bridge.rb
active_scaffold_vho-3.2.12 lib/active_scaffold/bridges/ancestry/lib/ancestry_bridge.rb
active_scaffold_vho-3.2.11 lib/active_scaffold/bridges/ancestry/lib/ancestry_bridge.rb
active_scaffold_vho-3.2.10 lib/active_scaffold/bridges/ancestry/lib/ancestry_bridge.rb
active_scaffold_vho-3.2.9 lib/active_scaffold/bridges/ancestry/lib/ancestry_bridge.rb
active_scaffold_vho-3.2.8 lib/active_scaffold/bridges/ancestry/lib/ancestry_bridge.rb
active_scaffold_vho-3.2.7 lib/active_scaffold/bridges/ancestry/lib/ancestry_bridge.rb
active_scaffold_vho-3.2.6 lib/active_scaffold/bridges/ancestry/lib/ancestry_bridge.rb
active_scaffold_vho-3.2.5 lib/active_scaffold/bridges/ancestry/lib/ancestry_bridge.rb
active_scaffold_vho-3.2.4 lib/active_scaffold/bridges/ancestry/lib/ancestry_bridge.rb
active_scaffold_vho-3.2.3 lib/active_scaffold/bridges/ancestry/lib/ancestry_bridge.rb
active_scaffold_vho-3.2.2 lib/active_scaffold/bridges/ancestry/lib/ancestry_bridge.rb
active_scaffold_vho-3.2.1 lib/active_scaffold/bridges/ancestry/lib/ancestry_bridge.rb
active_scaffold_vho-3.2.0 lib/active_scaffold/bridges/ancestry/lib/ancestry_bridge.rb
active_scaffold_vho-3.0.31 lib/active_scaffold/bridges/ancestry/lib/ancestry_bridge.rb
active_scaffold_vho-3.1.8 lib/active_scaffold/bridges/ancestry/lib/ancestry_bridge.rb
active_scaffold_vho-3.0.30 lib/active_scaffold/bridges/ancestry/lib/ancestry_bridge.rb
active_scaffold_vho-3.0.29 lib/active_scaffold/bridges/ancestry/lib/ancestry_bridge.rb