Sha256: 09ed4b803be8f05a04c6d4e5a2fc70a067e78a8da97d82650f6a237d2376b332

Contents?: true

Size: 1.34 KB

Versions: 24

Compression:

Stored size: 1.34 KB

Contents

module ActiveScaffold
  module Bridges
    class Bitfields
      module BitfieldsBridge
        def initialize_with_bitfields(model_id)
          initialize_without_bitfields(model_id)
          return unless model.respond_to?(:bitfields) && model.bitfields.present?

          model.bitfields.each do |_, options|
            columns << options.keys
            options.each do |column, value|
              columns[column].form_ui = :checkbox
              columns[column].weight = 1000 + value.to_s(2).size
            end
          end
        end

        def _load_action_columns_with_bitfields
          model.bitfields.each do |column_name, options|
            columns = options.keys.sort_by { |column| self.columns[column].weight }
            [:create, :update, :show, :subform].each do |action|
              if actions.include? action
                send(action).columns.exclude column_name
                send(action).columns.add_subgroup(column_name) { |group| group.add *columns }
              end
            end
          end if model.respond_to?(:bitfields) && model.bitfields.present?

          _load_action_columns_without_bitfields
        end

        def self.included(base)
          base.alias_method_chain :initialize, :bitfields
          base.alias_method_chain :_load_action_columns, :bitfields
        end
      end
    end
  end
end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
active_scaffold-3.4.39 lib/active_scaffold/bridges/bitfields/bitfields_bridge.rb
active_scaffold-3.4.38 lib/active_scaffold/bridges/bitfields/bitfields_bridge.rb
active_scaffold-3.4.37 lib/active_scaffold/bridges/bitfields/bitfields_bridge.rb
active_scaffold-3.4.36 lib/active_scaffold/bridges/bitfields/bitfields_bridge.rb
active_scaffold-3.4.35 lib/active_scaffold/bridges/bitfields/bitfields_bridge.rb
active_scaffold-3.4.34 lib/active_scaffold/bridges/bitfields/bitfields_bridge.rb
active_scaffold-3.4.33 lib/active_scaffold/bridges/bitfields/bitfields_bridge.rb
active_scaffold-3.4.32 lib/active_scaffold/bridges/bitfields/bitfields_bridge.rb
active_scaffold-3.4.31 lib/active_scaffold/bridges/bitfields/bitfields_bridge.rb
active_scaffold-3.4.30 lib/active_scaffold/bridges/bitfields/bitfields_bridge.rb
active_scaffold-3.4.29 lib/active_scaffold/bridges/bitfields/bitfields_bridge.rb
active_scaffold-3.4.28 lib/active_scaffold/bridges/bitfields/bitfields_bridge.rb
active_scaffold-3.4.27 lib/active_scaffold/bridges/bitfields/bitfields_bridge.rb
active_scaffold-3.4.26 lib/active_scaffold/bridges/bitfields/bitfields_bridge.rb
active_scaffold-3.4.25 lib/active_scaffold/bridges/bitfields/bitfields_bridge.rb
active_scaffold-3.4.24 lib/active_scaffold/bridges/bitfields/bitfields_bridge.rb
active_scaffold-3.4.23 lib/active_scaffold/bridges/bitfields/bitfields_bridge.rb
active_scaffold-3.4.22 lib/active_scaffold/bridges/bitfields/bitfields_bridge.rb
active_scaffold-3.4.21.1 lib/active_scaffold/bridges/bitfields/bitfields_bridge.rb
active_scaffold-3.4.21 lib/active_scaffold/bridges/bitfields/bitfields_bridge.rb