Sha256: accfe7380121d5fb9ab3009eed39aff45fa0e70f9aabd130118b5ac924765f87

Contents?: true

Size: 1.34 KB

Versions: 18

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 self.model.respond_to?(:bitfields) and self.model.bitfields.present?

          self.model.bitfields.each do |column_name, options|
            self.columns << options.keys
            options.each do |column, value|
              self.columns[column].form_ui = :checkbox
              self.columns[column].weight = 1000 + value.to_s(2).size
            end
          end
        end
        
        def _load_action_columns_with_bitfields
          self.model.bitfields.each do |column_name, options|
            columns = options.keys.sort_by { |column| self.columns[column].weight }
            [:create, :update, :show, :subform].each do |action|
              self.send(action).columns.add_subgroup(column_name) { |group| group.add *columns } if self.actions.included? action
            end
          end if self.model.respond_to?(:bitfields) and self.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

18 entries across 18 versions & 1 rubygems

Version Path
active_scaffold-3.2.20 lib/active_scaffold/bridges/bitfields/bitfields_bridge.rb
active_scaffold-3.3.0.rc3 lib/active_scaffold/bridges/bitfields/bitfields_bridge.rb
active_scaffold-3.3.0.rc2 lib/active_scaffold/bridges/bitfields/bitfields_bridge.rb
active_scaffold-3.2.19 lib/active_scaffold/bridges/bitfields/bitfields_bridge.rb
active_scaffold-3.3.0.rc lib/active_scaffold/bridges/bitfields/bitfields_bridge.rb
active_scaffold-3.2.17 lib/active_scaffold/bridges/bitfields/bitfields_bridge.rb
active_scaffold-3.2.16 lib/active_scaffold/bridges/bitfields/bitfields_bridge.rb
active_scaffold-3.2.15 lib/active_scaffold/bridges/bitfields/bitfields_bridge.rb
active_scaffold-3.2.14 lib/active_scaffold/bridges/bitfields/bitfields_bridge.rb
active_scaffold-3.2.13 lib/active_scaffold/bridges/bitfields/bitfields_bridge.rb
active_scaffold-3.2.12 lib/active_scaffold/bridges/bitfields/bitfields_bridge.rb
active_scaffold-3.2.11 lib/active_scaffold/bridges/bitfields/bitfields_bridge.rb
active_scaffold-3.2.10 lib/active_scaffold/bridges/bitfields/bitfields_bridge.rb
active_scaffold-3.2.9 lib/active_scaffold/bridges/bitfields/bitfields_bridge.rb
active_scaffold-3.2.8 lib/active_scaffold/bridges/bitfields/bitfields_bridge.rb
active_scaffold-3.2.7 lib/active_scaffold/bridges/bitfields/bitfields_bridge.rb
active_scaffold-3.2.6 lib/active_scaffold/bridges/bitfields/bitfields_bridge.rb
active_scaffold-3.2.5 lib/active_scaffold/bridges/bitfields/bitfields_bridge.rb