Sha256: fca8f59ba07b57d9ba47c91d2e1119d115547fd60cf9ba6b5fc9a84b049407b3

Contents?: true

Size: 1.63 KB

Versions: 17

Compression:

Stored size: 1.63 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::Bridges
  class Ancestry
    module FormColumnHelpers
      def active_scaffold_input_ancestry(column, options)
        record = options[:object]
        ActiveSupport::Deprecation.warn "Relying on @record is deprecated, include :object in html_options with record.", caller if record.nil? # TODO Remove when relying on @record is removed
        record ||= @record # TODO Remove when relying on @record is removed

        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

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
active_scaffold-3.4.17 lib/active_scaffold/bridges/ancestry/ancestry_bridge.rb
active_scaffold-3.4.16 lib/active_scaffold/bridges/ancestry/ancestry_bridge.rb
active_scaffold-3.4.14 lib/active_scaffold/bridges/ancestry/ancestry_bridge.rb
active_scaffold-3.4.13 lib/active_scaffold/bridges/ancestry/ancestry_bridge.rb
active_scaffold-3.4.12 lib/active_scaffold/bridges/ancestry/ancestry_bridge.rb
active_scaffold-3.4.11 lib/active_scaffold/bridges/ancestry/ancestry_bridge.rb
active_scaffold-3.4.10 lib/active_scaffold/bridges/ancestry/ancestry_bridge.rb
active_scaffold-3.4.9 lib/active_scaffold/bridges/ancestry/ancestry_bridge.rb
active_scaffold-3.4.8 lib/active_scaffold/bridges/ancestry/ancestry_bridge.rb
active_scaffold-3.4.7 lib/active_scaffold/bridges/ancestry/ancestry_bridge.rb
active_scaffold-3.4.5 lib/active_scaffold/bridges/ancestry/ancestry_bridge.rb
active_scaffold-3.4.4 lib/active_scaffold/bridges/ancestry/ancestry_bridge.rb
active_scaffold-3.4.3 lib/active_scaffold/bridges/ancestry/ancestry_bridge.rb
active_scaffold-3.4.2 lib/active_scaffold/bridges/ancestry/ancestry_bridge.rb
active_scaffold-3.4.1 lib/active_scaffold/bridges/ancestry/ancestry_bridge.rb
active_scaffold-3.4.0.1 lib/active_scaffold/bridges/ancestry/ancestry_bridge.rb
active_scaffold-3.4.0 lib/active_scaffold/bridges/ancestry/ancestry_bridge.rb