Module: Netzke::Plugins::ConfigurationTool

Included in:
FormPanel, GridPanel
Defined in:
lib/netzke/plugins/configuration_tool.rb

Overview

Include this module into any widget where you want a “gear” tool button in the top toolbar which will triggger a modal window, which will load the ConfigurationPanel TabPanel-based widget, which in its turn will contain all the aggregatees specified in widget’s “configuration_widgets” method (which must be defined)

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/netzke/plugins/configuration_tool.rb', line 7

def self.included(base)
  base.extend ClassMethods
  
  base.class_eval do
    # replacing instance methods
    [:config, :initial_aggregatees, :js_config].each{ |m| alias_method_chain m, :config_tool }
    
    # replacing class methods
    class << self
      alias_method_chain :js_extend_properties, :config_tool
    end

    # API to commit the changes
    api :commit
  end

  # if you include ConfigurationTool, you are supposed to provide configuration_widgets method which will returns an array of arrgeratees
  # that will be included in the property window (each in its own tab or accordion pane)
  raise "configuration_widgets method undefined" unless base.instance_methods.include?("configuration_widgets")
end

Instance Method Details

#config_tool_needed?Boolean

Returns:

  • (Boolean)


116
117
118
# File 'lib/netzke/plugins/configuration_tool.rb', line 116

def config_tool_needed?
  config_without_config_tool[:ext_config][:config_tool] || config_without_config_tool[:ext_config][:mode] == :config
end

#config_with_config_toolObject



79
80
81
82
83
84
85
86
87
88
# File 'lib/netzke/plugins/configuration_tool.rb', line 79

def config_with_config_tool
  orig_config = config_without_config_tool
  return orig_config unless config_tool_needed?
  orig_config.deep_merge({
    :ext_config => {
      :tools => orig_config[:ext_config][:tools].clone << "gear",
      :header => true
    }
  })
end

#initial_aggregatees_with_config_toolObject



90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/netzke/plugins/configuration_tool.rb', line 90

def initial_aggregatees_with_config_tool
  res = initial_aggregatees_without_config_tool
  
  # Add the ConfigurationPanel as aggregatee, which in its turn aggregates widgets from the 
  # configuration_widgets method
  res.merge!(:configuration_panel => {
    :widget_class_name => 'ConfigurationPanel', 
    :items => configuration_widgets,
    :late_aggregation => true
  }) if config_tool_needed?
  
  res
end

#js_config_with_config_toolObject



111
112
113
114
# File 'lib/netzke/plugins/configuration_tool.rb', line 111

def js_config_with_config_tool
  orig_config = js_config_without_config_tool
  orig_config.merge(:configurable => config[:persistent_config])
end

#tools_with_config_toolObject



104
105
106
107
108
109
# File 'lib/netzke/plugins/configuration_tool.rb', line 104

def tools_with_config_tool
  tools = tools_without_config_tool
  # Add the toolbutton
  tools << 'gear' if config_tool_needed?
  tools
end