Module: Netzke::Grid::Configuration

Extended by:
ActiveSupport::Concern
Included in:
Base, Tree::Base
Defined in:
lib/netzke/grid/configuration.rb

Overview

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

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#bbarObject



18
19
20
# File 'lib/netzke/grid/configuration.rb', line 18

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

#configure_client(c) ⇒ Object



45
46
47
48
49
50
51
52
53
54
# File 'lib/netzke/grid/configuration.rb', line 45

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

#context_menuObject



26
27
28
# File 'lib/netzke/grid/configuration.rb', line 26

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

#default_bbarObject



22
23
24
# File 'lib/netzke/grid/configuration.rb', line 22

def default_bbar
  [:add, :add_in_form, :edit, :edit_in_form, :apply, :delete, :search]
end

#default_context_menuObject



30
31
32
33
34
35
# File 'lib/netzke/grid/configuration.rb', line 30

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

#default_toolsObject



41
42
43
# File 'lib/netzke/grid/configuration.rb', line 41

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

#toolsObject



37
38
39
# File 'lib/netzke/grid/configuration.rb', line 37

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

#validate_config(c) ⇒ Object

Raises:

  • (ArgumentError)


56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/netzke/grid/configuration.rb', line 56

def validate_config(c)
  raise ArgumentError, "Grid requires a model" if model.nil?

  c.editing = :in_form if c.editing.nil?

  c.edits_in_form = [:both, :in_form].include?(c.editing)
  c.edits_inline = [:both, :inline].include?(c.editing)

  if c.paging.nil?
    c.paging = c.edits_inline ? :pagination : :buffered
  end

  if c.paging == :buffered && c.edits_inline
    raise ArgumentError, "Buffered grid cannot have inline editing"
  end

  c.tools = tools
  c.bbar = bbar
  c.context_menu = context_menu

  super
end