Class: ActiveScaffold::Config::Core

Inherits:
Base show all
Defined in:
lib/six-updater-web/vendor/plugins/active_scaffold/lib/bridges/checkbox.rb,
lib/six-updater-web/vendor/plugins/activescaffold_advanced_search/lib/config/core.rb,
lib/six-updater-web/vendor/plugins/active_scaffold/lib/active_scaffold/config/core.rb,
lib/six-updater-web/vendor/plugins/active_scaffold/lib/bridges/file_column/lib/as_file_column_bridge.rb,
lib/six-updater-web/vendor/plugins/active_scaffold/lib/bridges/calendar_date_select/lib/as_cds_bridge.rb

Constant Summary collapse

@@advanced_search_plugin_directory =
File.expand_path(__FILE__).match(/vendor\/plugins\/([^\/]*)/)[1]
@@plugin_directory =
@@frontend =
:default
@@theme =
:default
@@left_handed =
false
@@one_column_list =
false
@@show_actions_column =
true
@@show_missing_translations =
false
@@secure_download_controller =
"/downloads"
@@secure_download_key =
nil
@@upper_case_form_fields =
false
@@dhtml_history =
true
ActiveScaffold::DataStructures::ActionLinks.new
@@ignore_columns =
ActiveScaffold::DataStructures::Set.new

Instance Attribute Summary collapse

Attributes inherited from Base

#user

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#crud_type, #formats, #formats=, inherited

Methods included from ActiveScaffold::Configurable

#configure

Constructor Details

#initialize(model_id) ⇒ Core

internal usage only below this point




135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/lib/active_scaffold/config/core.rb', line 135

def initialize(model_id)
  # model_id is the only absolutely required configuration value. it is also not publicly accessible.
  @model_id = model_id.to_s.pluralize.singularize

  # inherit the actions list directly from the global level
  @actions = self.class.actions.clone

  # create a new default columns datastructure, since it doesn't make sense before now
  attribute_names = self.model.columns.collect{ |c| c.name.to_sym }.sort_by { |c| c.to_s }
  association_column_names = self.model.reflect_on_all_associations.collect{ |a| a.name.to_sym }.sort_by { |c| c.to_s }
  @columns = ActiveScaffold::DataStructures::Columns.new(self.model, attribute_names + association_column_names)

  # and then, let's remove some columns from the inheritable set.
  @columns.exclude(*self.class.ignore_columns)
  @columns.exclude(*@columns.find_all { |c| c.column and (c.column.primary or c.column.name =~ /(_id|_count)$/) }.collect {|c| c.name})
  @columns.exclude(*self.model.reflect_on_all_associations.collect{|a| :"#{a.name}_type" if a.options[:polymorphic]}.compact)

  # inherit the global frontend
  @frontend = self.class.frontend
  @theme = self.class.theme
  @left_handed = self.class.left_handed
  @one_column_list = self.class.one_column_list
  @show_actions_column = self.class.show_actions_column
	  @sti_create_links = self.class.sti_create_links

  # inherit from the global set of action links
  @action_links = self.class.action_links.clone
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args) ⇒ Object

configuration routing. we want to route calls named like an activated action to that action’s global or local Config class.




207
208
209
210
211
212
213
214
215
216
217
218
219
220
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/lib/active_scaffold/config/core.rb', line 207

def method_missing(name, *args)
  @action_configs ||= {}
  titled_name = name.to_s.camelcase
  underscored_name = name.to_s.underscore.to_sym
  klass = "ActiveScaffold::Config::#{titled_name}".constantize rescue nil
  if klass
    if @actions.include? underscored_name
      return @action_configs[underscored_name] ||= klass.new(self)
    else
      raise "#{titled_name} is not enabled. Please enable it or remove any references in your configuration (e.g. config.#{underscored_name}.columns = [...])."
    end
  end
  super
end

Instance Attribute Details

action links are used by actions to tie together. they appear as links for each record, or general links for the ActiveScaffold.



119
120
121
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/lib/active_scaffold/config/core.rb', line 119

def action_links
  @action_links
end

#actionsObject

provides read/write access to the local Actions DataStructure



89
90
91
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/lib/active_scaffold/config/core.rb', line 89

def actions
  @actions
end

#columnsObject

provides read/write access to the local Columns DataStructure



95
96
97
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/lib/active_scaffold/config/core.rb', line 95

def columns
  @columns
end

#file_column_fieldsObject

Returns the value of attribute file_column_fields.



10
11
12
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/lib/bridges/file_column/lib/as_file_column_bridge.rb', line 10

def file_column_fields
  @file_column_fields
end

#frontendObject

lets you override the global ActiveScaffold frontend for a specific controller



107
108
109
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/lib/active_scaffold/config/core.rb', line 107

def frontend
  @frontend
end

#label(options = {}) ⇒ Object



123
124
125
126
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/lib/active_scaffold/config/core.rb', line 123

def label(options={})
  # ActiveRecord supports I18 via :scope => activerecord.models
  as_(@label, options) || model.human_name(options.merge(options[:count].to_i == 1 ? {} : {:default => model.name.pluralize}))
end

#left_handedObject

Returns the value of attribute left_handed.



102
103
104
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/lib/active_scaffold/config/core.rb', line 102

def left_handed
  @left_handed
end

#one_column_listObject

Returns the value of attribute one_column_list.



103
104
105
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/lib/active_scaffold/config/core.rb', line 103

def one_column_list
  @one_column_list
end

#show_actions_columnObject

Returns the value of attribute show_actions_column.



104
105
106
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/lib/active_scaffold/config/core.rb', line 104

def show_actions_column
  @show_actions_column
end

#sti_childrenObject

STI children models, use an array of model names



129
130
131
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/lib/active_scaffold/config/core.rb', line 129

def sti_children
  @sti_children
end

lets you specify whether add a create link for each sti child for a specific controller



113
114
115
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/lib/active_scaffold/config/core.rb', line 113

def sti_create_links
  @sti_create_links
end

#themeObject

lets you override the global ActiveScaffold theme for a specific controller



110
111
112
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/lib/active_scaffold/config/core.rb', line 110

def theme
  @theme
end

Class Method Details

.actions=(val) ⇒ Object



9
10
11
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/lib/active_scaffold/config/core.rb', line 9

def self.actions=(val)
  @@actions = ActiveScaffold::DataStructures::Actions.new(*val)
end

.asset_path(filename, frontend = self.frontend) ⇒ Object

must be a class method so the layout doesn’t depend on a controller that uses active_scaffold note that this is unaffected by per-controller frontend configuration.



247
248
249
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/lib/active_scaffold/config/core.rb', line 247

def self.asset_path(filename, frontend = self.frontend)
  "active_scaffold/#{frontend}/#{filename}"
end

.available_frontendsObject



258
259
260
261
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/lib/active_scaffold/config/core.rb', line 258

def self.available_frontends
  frontends_dir = File.join(Rails.root, "vendor", "plugins", ActiveScaffold::Config::Core.plugin_directory, "frontends")
  Dir.entries(frontends_dir).reject { |e| e.match(/^\./) } # Get rid of files that start with .
end

.dhtml_history=(val) ⇒ Object

lets you disable the DHTML history



52
53
54
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/lib/active_scaffold/config/core.rb', line 52

def self.dhtml_history=(val)
  @@dhtml_history = val
end

.dhtml_history?Boolean

Returns:

  • (Boolean)


55
56
57
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/lib/active_scaffold/config/core.rb', line 55

def self.dhtml_history?
  @@dhtml_history ? true : false
end

.ignore_columnsObject

columns that should be ignored for every model. these should be metadata columns like change dates, versions, etc. values in this array may be symbols or strings.



74
75
76
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/lib/active_scaffold/config/core.rb', line 74

def self.ignore_columns
  @@ignore_columns
end

.ignore_columns=(val) ⇒ Object



77
78
79
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/lib/active_scaffold/config/core.rb', line 77

def self.ignore_columns=(val)
  @@ignore_columns = ActiveScaffold::DataStructures::Set.new(*val)
end

.javascripts(frontend = self.frontend) ⇒ Object

must be a class method so the layout doesn’t depend on a controller that uses active_scaffold note that this is unaffected by per-controller frontend configuration.



253
254
255
256
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/lib/active_scaffold/config/core.rb', line 253

def self.javascripts(frontend = self.frontend)
  javascript_dir = File.join(Rails.public_path, "javascripts", asset_path('', frontend))
  Dir.entries(javascript_dir).reject { |e| !e.match(/\.js$/) or (!self.dhtml_history? and e.match('dhtml_history')) }
end

.method_missing(name, *args) ⇒ Object



222
223
224
225
226
227
228
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/lib/active_scaffold/config/core.rb', line 222

def self.method_missing(name, *args)
  klass = "ActiveScaffold::Config::#{name.to_s.titleize}".constantize rescue nil
  if @@actions.include? name.to_s.underscore and klass
    return eval("ActiveScaffold::Config::#{name.to_s.titleize}")
  end
  super
end

.securityObject

access to the permissions configuration. configuration options include:

* current_user_method - what method on the controller returns the current user. default: :current_user
* default_permission - what the default permission is. default: true


68
69
70
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/lib/active_scaffold/config/core.rb', line 68

def self.security
  ActiveRecordPermissions
end

Instance Method Details

To be called after include action modules



191
192
193
194
195
196
197
198
199
200
201
202
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/lib/active_scaffold/config/core.rb', line 191

def _add_sti_create_links
  new_action_link = @action_links['new']
  unless new_action_link.nil?
    @action_links.delete('new')
    self.sti_children.each do |child| 
      new_sti_link = Marshal.load(Marshal.dump(new_action_link)) # deep clone
      new_sti_link.label = as_(:create_model, :model => child.to_s.camelize.constantize.human_name)
      new_sti_link.parameters = {model.inheritance_column => child}
      @action_links.add(new_sti_link)
    end
  end
end

#_configure_stiObject

To be called after your finished configuration



177
178
179
180
181
182
183
184
185
186
187
188
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/lib/active_scaffold/config/core.rb', line 177

def _configure_sti
  column = self.model.inheritance_column
  if sti_create_links
    self.columns[column].form_ui ||= :hidden
  else
    self.columns[column].form_ui ||= :select
    self.columns[column].options ||= {}
    self.columns[column].options[:options] = self.sti_children.collect do |model_name|
      [model_name.to_s.camelize.constantize.human_name, model_name.to_s.camelize]
    end
  end
end

#_load_action_columnsObject

To be called after your finished configuration



165
166
167
168
169
170
171
172
173
174
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/lib/active_scaffold/config/core.rb', line 165

def _load_action_columns
  ActiveScaffold::DataStructures::ActionColumns.class_eval {include ActiveScaffold::DataStructures::ActionColumns::AfterConfiguration}

  # then, register the column objects
  self.actions.each do |action_name|
    action = self.send(action_name)
    next unless action.respond_to? :columns
    action.columns.set_columns(self.columns)
  end
end

#add_sti_create_links?Boolean

Returns:

  • (Boolean)


114
115
116
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/lib/active_scaffold/config/core.rb', line 114

def add_sti_create_links?
  self.sti_create_links and not self.sti_children.nil?
end

#configure_file_column_field(field) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/lib/bridges/file_column/lib/as_file_column_bridge.rb', line 32

def configure_file_column_field(field)
  # set list_ui first because it gets its default value from form_ui
  self.columns[field].list_ui ||= self.model.field_has_image_version?(field, "thumb") ? :thumbnail : :download_link_with_filename
  self.columns[field].form_ui ||= :file_column
  
  # these 2 parameters are necessary helper attributes for the file column that must be allowed to be set to the model by active scaffold.
  self.columns[field].params.add "#{field}_temp", "delete_#{field}"
  
  # set null to false so active_scaffold wont set it to null
  # delete_file_column will take care of deleting a file or not.
  self.model.columns_hash[field.to_s].instance_variable_set("@null", false)
  
rescue
  false
end

#inherited_view_pathsObject

warning - this won’t work as a per-request dynamic attribute in rails 2.0. You’ll need to interact with Controller#generic_view_paths



241
242
243
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/lib/active_scaffold/config/core.rb', line 241

def inherited_view_paths
  @inherited_view_paths||=[]
end

#initialize_with_calendar_date_select(model_id) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/lib/bridges/calendar_date_select/lib/as_cds_bridge.rb', line 4

def initialize_with_calendar_date_select(model_id)
  initialize_without_calendar_date_select(model_id)
  
  calendar_date_select_fields = self.model.columns.collect{|c| c.name.to_sym if [:date, :datetime].include?(c.type) }.compact
  # check to see if file column was used on the model
  return if calendar_date_select_fields.empty?
  
  # automatically set the forum_ui to a file column
  calendar_date_select_fields.each{|field|
    self.columns[field].form_ui = :calendar_date_select
  }
end

#initialize_with_checkbox(model_id) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/lib/bridges/checkbox.rb', line 5

def initialize_with_checkbox(model_id)
  initialize_without_checkbox(model_id)
  
  checkbox_fields = self.model.columns.collect{|c| c.name.to_sym if [:boolean].include?(c.type) }.compact
  # check to see if file column was used on the model
  return if checkbox_fields.empty?
  
  # automatically set the forum_ui to a file column
  checkbox_fields.each{|field|
    self.columns[field].form_ui = :checkbox
  }
end

#initialize_with_file_column(model_id) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/lib/bridges/file_column/lib/as_file_column_bridge.rb', line 11

def initialize_with_file_column(model_id)
  initialize_without_file_column(model_id)
  
  return unless FileColumnHelpers.klass_has_file_column_fields?(self.model)
  
  self.model.send :extend, FileColumnHelpers
  
  # include the "delete" helpers for use with active scaffold, unless they are already included
  self.model.generate_delete_helpers
  
  # switch on multipart
  self.update.multipart = true
  self.create.multipart = true
  
  self.model.file_column_fields.each{ |field|
    configure_file_column_field(field)
  }
end

#modelObject



236
237
238
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/lib/active_scaffold/config/core.rb', line 236

def model
  @model ||= @model_id.to_s.camelize.constantize
end

#model_idObject

some utility methods




232
233
234
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/lib/active_scaffold/config/core.rb', line 232

def model_id
  @model_id
end

#template_search_path_with_advanced_search(frontend = self.frontend) ⇒ Object



8
9
10
11
12
13
14
15
# File 'lib/six-updater-web/vendor/plugins/activescaffold_advanced_search/lib/config/core.rb', line 8

def template_search_path_with_advanced_search(frontend = self.frontend)
  frontends_path = "../../vendor/plugins/#{ActiveScaffold::Config::Core.advanced_search_plugin_directory}/frontends"

  search_path = template_search_path_without_advanced_search
  search_path << "#{frontends_path}/#{frontend}/views" if frontend.to_sym != :default
  search_path << "#{frontends_path}/default/views"
  return search_path
end