Sha256: 2c269d8bac08d38d1b82e51a8eb4980ed95c27d32f1e1ac74e12324bcfc65919

Contents?: true

Size: 1.86 KB

Versions: 5

Compression:

Stored size: 1.86 KB

Contents

module Netzke
  module Grid
    # Overridable methods related to configuration of Grid. For example, to add a custom action to the end of the grid's
    # bbar, you can do:
    #
    #     def bbar
    #       super + [:my_action]
    #     end
    module Configuration # WTF: naming it Config causes troubles in 1.9.3
      extend ActiveSupport::Concern

      module ClassMethods
        def server_side_config_options
          super + [:scope]
        end
      end

      def bbar
        config.has_key?(:bbar) ? config[:bbar] : default_bbar
      end

      def default_bbar
        [].tap do |bbar|
          bbar << :add if has_add_action?
          bbar << :edit if has_edit_action?
          bbar << :apply if has_apply_action?
          bbar << :delete if has_delete_action?
          bbar << :search if has_search_action?
        end
      end

      def context_menu
        config.has_key?(:context_menu) ? config.context_menu : default_context_menu
      end

      def default_context_menu
        [].tap do |menu|
          menu << :edit if has_edit_action?
          menu << :delete if has_delete_action?
        end
      end

      def tools
        config.has_key?(:tools) ? config.tools : default_tools
      end

      def default_tools
        [{ type: :refresh, handler: f(:netzke_on_refresh_tool) }]
      end

      def configure_client(c)
        super
        c.title ||= model.name.pluralize
        c.columns = {items: js_columns}
        c.columns_order = columns_order
        c.pri = model_adapter.primary_key
        if c.default_filters
          populate_columns_with_filters(c)
        end
      end

      def validate_config(c)
        raise ArgumentError, "Grid requires a model" if model.nil?
        c.paging = true if c.edit_inline
        c.tools = tools
        c.bbar = bbar
        c.context_menu = context_menu
        super
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
netzke-basepack-1.0.0.1 lib/netzke/grid/configuration.rb
netzke-basepack-1.0.0.0 lib/netzke/grid/configuration.rb
netzke-basepack-1.0.0.0.pre3 lib/netzke/grid/configuration.rb
netzke-basepack-1.0.0.0.pre2 lib/netzke/grid/configuration.rb
netzke-basepack-1.0.0.0.pre lib/netzke/grid/configuration.rb