active_scaffold 3.0.2 → 3.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/CHANGELOG CHANGED
@@ -1,3 +1,13 @@
1
+ = 3.0.4
2
+
3
+ - Fix a typo that made 3.0.3 unusable.
4
+
5
+ = 3.0.3
6
+
7
+ - Fixing 'require' ordering
8
+ - Code for nested and subgrouped action links
9
+ - bugfixes for better html generation
10
+
1
11
  = 3.0.2
2
12
 
3
13
  - Two bug fixes and a deprecation silencing.
@@ -2,7 +2,7 @@ $:.push File.expand_path("../lib", __FILE__)
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "active_scaffold"
5
- s.version = "3.0.2"
5
+ s.version = "3.0.4"
6
6
  s.platform = Gem::Platform::RUBY
7
7
  s.authors = ["Many, see README"]
8
8
  s.email = ["activescaffold@googlegroups.com"]
data/environment.rb CHANGED
@@ -3,9 +3,11 @@ require 'active_scaffold'
3
3
  # TODO: clean up extensions. some could be organized for autoloading, and others could be removed entirely.
4
4
  Dir["#{File.dirname __FILE__}/lib/extensions/*.rb"].each { |file| require file }
5
5
  #Dir["#{File.dirname __FILE__}/lib/generators/*/*.rb"].each { |file| require file }
6
- Dir["#{File.dirname __FILE__}/lib/active_scaffold/actions/*.rb"].each { |file| require file }
6
+ require "#{File.dirname __FILE__}/lib/active_scaffold/data_structures/set.rb"
7
7
  Dir["#{File.dirname __FILE__}/lib/active_scaffold/data_structures/*.rb"].each { |file| require file }
8
+ Dir["#{File.dirname __FILE__}/lib/active_scaffold/actions/*.rb"].each { |file| require file }
8
9
  Dir["#{File.dirname __FILE__}/lib/active_scaffold/config/*.rb"].each { |file| require file }
10
+ require "#{File.dirname __FILE__}/lib/active_scaffold/helpers/id_helpers.rb"
9
11
  Dir["#{File.dirname __FILE__}/lib/active_scaffold/helpers/*.rb"].each { |file| require file }
10
12
 
11
13
  ActionController::Base.send(:include, ActiveScaffold)
@@ -246,7 +246,6 @@ text-align: right;
246
246
 
247
247
  /* Table :: Actions (Edit, Delete)
248
248
  ============================= */
249
-
250
249
  .active-scaffold tr.record td.actions {
251
250
  border-right: solid 1px #ccc;
252
251
  padding: 0;
@@ -8,7 +8,7 @@
8
8
  <%= render :partial => 'list_messages', :locals => {:columns => columns} %>
9
9
  <tbody class="records" id="<%= active_scaffold_tbody_id %>">
10
10
  <% if !@records.empty? -%>
11
- <%= render :partial => 'list_record', :collection => @page.items, :locals => { :hidden => false, :columns => columns, :action_links => active_scaffold_config.action_links.collect_by_type(:member)} %>
11
+ <%= render :partial => 'list_record', :collection => @page.items, :locals => { :hidden => false, :columns => columns, :action_links => active_scaffold_config.action_links.member} %>
12
12
  <% end -%>
13
13
  <% if columns.any? {|c| c.calculation?} -%>
14
14
  <%= render :partial => 'list_calculations', :locals => {:columns => columns} %>
@@ -1,15 +1,22 @@
1
- <% action_links ||= active_scaffold_config.action_links %>
1
+ <% action_links ||= active_scaffold_config.action_links.member %>
2
2
  <td class="actions"><table cellpadding="0" cellspacing="0">
3
3
  <tr>
4
4
  <td class="indicator-container">
5
5
  <%= loading_indicator_tag(:action => :record, :id => record.id) %>
6
6
  </td>
7
- <% action_links.each do |link| -%>
8
- <% next if skip_action_link(link, record) -%>
9
- <td>
10
- <%= record.authorized_for?(:crud_type => link.crud_type, :action => link.action) ? render_action_link(link, url_options, record) : action_link_html(link, nil, {:class => "disabled #{link.action}#{link.html_options[:class].blank? ? '' : (' ' + link.html_options[:class])}"}) %>
11
- </td>
12
- <% end -%>
7
+ <% level = 0 %>
8
+ <% action_links.traverse(controller, {:record => record}) do |parent, link, options| -%>
9
+ <% tag = (level == 0 ? 'td' : 'li') %>
10
+ <% if (options[:node] == :finished_traversing) -%>
11
+ <% level -= 1 %>
12
+ <%= "</ul></#{(level == 0 ? 'td' : 'li')}>".html_safe %>
13
+ <% elsif (options[:node] == :start_traversing) -%>
14
+ <%= "<#{tag} #{"class=\"action_list\"" if tag == 'td'}> #{content_tag('span', parent.name)}<ul>".html_safe %>
15
+ <% level += 1 %>
16
+ <% else -%>
17
+ <%= content_tag(tag, options[:authorized] ? render_action_link(link, url_options, record) : action_link_html(link, nil, {:class => "disabled #{link.action}#{link.html_options[:class].blank? ? '' : (' ' + link.html_options[:class])}"})) %>
18
+ <% end -%>
19
+ <% end -%>
13
20
  </tr>
14
21
  </table>
15
22
  </td>
@@ -2,7 +2,7 @@
2
2
  columns ||= list_columns -%>
3
3
  <tr id="<%= active_scaffold_calculations_id %>" class="active-scaffold-calculations">
4
4
  <% columns.each do |column| -%>
5
- <td id="<%= active_scaffold_calculations_id(column) if column.calculation? %>">
5
+ <td <%= "id=#{active_scaffold_calculations_id(column)}" if column.calculation? %>>
6
6
  <% if column.calculation? -%>
7
7
  <%= render_column_calculation(column) %>
8
8
  <% else -%>
@@ -1,4 +1,4 @@
1
- <% action_links = active_scaffold_config.action_links.collect_by_type(:collection)
1
+ <% action_links = active_scaffold_config.action_links.collection.collect
2
2
  unless action_links.empty? -%>
3
3
  <div class="actions">
4
4
  <% new_params = params_for %>
@@ -21,7 +21,7 @@
21
21
  record = active_scaffold_config.model.new
22
22
  record.id = 0
23
23
  action_links.add(search_link) -%>
24
- <%= render :partial => 'list_actions', :locals => {:record => record, :url_options => params_for(:escape => false, :search => ''), :action_links => action_links} %>
24
+ <%= render :partial => 'list_actions', :locals => {:record => record, :url_options => params_for(:escape => false, :search => ''), :action_links => action_links.member} %>
25
25
  <% else %>
26
26
  <td class='actions'><%= '<p class="empty-message">&nbsp;</p>'.html_safe if @page.items.empty? %></td>
27
27
  <% end -%>
@@ -4,7 +4,7 @@ columns ||= list_columns
4
4
  tr_class = cycle("", "even-record")
5
5
  tr_class += " #{list_row_class(record)}" if respond_to? :list_row_class
6
6
  url_options = params_for(:action => :list, :id => record.id)
7
- action_links ||= active_scaffold_config.action_links.collect_by_type(:member)
7
+ action_links ||= active_scaffold_config.action_links.member
8
8
  -%>
9
9
 
10
10
  <tr class="record <%= tr_class %>" id="<%= element_row_id(:action => :list, :id => record.id) %>" data-refresh="<%= url_for(params_for(:action => :row, :id => record.id, :_method => :get, :escape => false)).html_safe %>">
@@ -1,6 +1,6 @@
1
1
  <div class="active-scaffold-header">
2
2
  <div class="actions">
3
- <% active_scaffold_config.action_links.each :member do |link| -%>
3
+ <% active_scaffold_config.action_links.member.each do |link| -%>
4
4
  <% next unless link.action == 'nested' -%>
5
5
  <% next if skip_action_link(link) -%>
6
6
  <%= record.authorized_for?(:crud_type => link.crud_type, :action => link.action) ? render_action_link(link, url_options, record) : "<a class='disabled'>#{link.label}</a>" -%>
@@ -1,6 +1,6 @@
1
1
  <div class="active-scaffold">
2
2
  <div class="update-view <%= "#{params[:controller]}-view" %> view">
3
- <% if active_scaffold_config.update.nested_links and active_scaffold_config.action_links.any? {|link| link.type == :member } -%>
3
+ <% if active_scaffold_config.update.nested_links and active_scaffold_config.action_links.member.empty? -%>
4
4
  <%= render :partial => 'update_actions', :locals => {:record => @record, :url_options => params_for(:action => :list, :id => @record.id)} %>
5
5
  <% end -%>
6
6
  <%= render :partial => 'update_form' -%>
@@ -33,17 +33,17 @@ module ActiveScaffold::Config
33
33
  @conf = conf
34
34
  end
35
35
  end
36
-
36
+
37
37
  def formats
38
38
  @formats ||= []
39
39
  end
40
-
40
+
41
41
  def formats=(val)
42
42
  @formats=val
43
43
  end
44
-
44
+
45
45
  private
46
-
46
+
47
47
  def columns=(val)
48
48
  @columns = ActiveScaffold::DataStructures::ActionColumns.new(*val)
49
49
  @columns.action = self
@@ -33,7 +33,7 @@ module ActiveScaffold::Config
33
33
  model ||= @core.label(:count => 1)
34
34
  @label ? as_(@label) : as_(:create_model, :model => model)
35
35
  end
36
-
36
+
37
37
  # whether the form stays open after a create or not
38
38
  attr_accessor :persistent
39
39
 
@@ -49,26 +49,26 @@ module ActiveScaffold::Config
49
49
  # * false: LIKE ?
50
50
  # Default is :full
51
51
  attr_accessor :text_search
52
-
52
+
53
53
  # the ActionLink for this action
54
54
  attr_accessor :link
55
-
55
+
56
56
  # rarely searched columns may be placed in a hidden subgroup
57
57
  def optional_columns=(optionals)
58
58
  @optional_columns= Array(optionals)
59
59
  end
60
-
60
+
61
61
  def optional_columns
62
62
  @optional_columns ||= []
63
63
  end
64
-
64
+
65
65
  # default search params
66
- # default_params = {:title => {"from"=>"test", "to"=>"", "opt"=>"%?%"}}
66
+ # default_params = {:title => {"from"=>"test", "to"=>"", "opt"=>"%?%"}}
67
67
  attr_accessor :default_params
68
-
68
+
69
69
  # human conditions
70
70
  # instead of just filtered you may show the user a humanized search condition statment
71
71
  attr_accessor :human_conditions
72
-
72
+
73
73
  end
74
74
  end
@@ -34,9 +34,9 @@ module ActiveScaffold::Config
34
34
  end
35
35
  @columns
36
36
  end
37
-
37
+
38
38
  public :columns=
39
-
39
+
40
40
  # whether the form should be multipart
41
41
  attr_writer :multipart
42
42
  def multipart?
@@ -1,22 +1,22 @@
1
1
  module ActiveScaffold::Config
2
2
  class Mark < Base
3
3
  self.crud_type = :read
4
-
4
+
5
5
  def initialize(core_config)
6
6
  @core = core_config
7
7
  @core.model.send(:include, ActiveScaffold::MarkedModel) unless @core.model.ancestors.include?(ActiveScaffold::MarkedModel)
8
8
  add_mark_column
9
9
  end
10
-
10
+
11
11
  protected
12
-
12
+
13
13
  def add_mark_column
14
14
  @core.columns.add :marked
15
15
  @core.columns[:marked].label = 'M'
16
16
  @core.columns[:marked].form_ui = :checkbox
17
17
  @core.columns[:marked].inplace_edit = true
18
18
  @core.columns[:marked].sort = false
19
- @core.list.columns = [:marked] + @core.list.columns.names unless @core.list.columns.include? :marked
19
+ @core.list.columns = [:marked] + @core.list.columns.names unless @core.list.columns.include? :marked
20
20
  end
21
21
  end
22
22
  end
@@ -20,14 +20,14 @@ module ActiveScaffold::Config
20
20
  def add_link(attribute, options = {})
21
21
  column = @core.columns[attribute.to_sym]
22
22
  unless column.nil? || column.association.nil?
23
- options.reverse_merge! :security_method => :nested_authorized?, :label => column.association.klass.model_name.human({:count => 2, :default => column.association.klass.name.pluralize})
23
+ options.reverse_merge! :security_method => :nested_authorized?, :label => column.association.klass.model_name.human({:count => 2, :default => column.association.klass.name.pluralize})
24
24
  action_link = @core.link_for_association(column, options)
25
25
  @core.action_links.add(action_link) unless action_link.nil?
26
26
  else
27
-
27
+
28
28
  end
29
29
  end
30
-
30
+
31
31
  def add_scoped_link(named_scope, options = {})
32
32
  action_link = @core.link_for_association_as_scope(named_scope.to_sym, options)
33
33
  @core.action_links.add(action_link) unless action_link.nil?
@@ -28,7 +28,7 @@ module ActiveScaffold::Config
28
28
  self.columns = @core.columns._inheritable unless @columns # lazy evaluation
29
29
  @columns
30
30
  end
31
-
31
+
32
32
  public :columns=
33
33
  end
34
34
  end
@@ -15,7 +15,7 @@ module ActiveScaffold::DataStructures
15
15
 
16
16
  # Whether this column set is collapsed by default in contexts where collapsing is supported
17
17
  attr_accessor :collapsed
18
-
18
+
19
19
  # nests a subgroup in the column set
20
20
  def add_subgroup(label, &proc)
21
21
  columns = ActiveScaffold::DataStructures::ActionColumns.new
@@ -73,7 +73,7 @@ module ActiveScaffold::DataStructures
73
73
  end
74
74
  end
75
75
  end
76
-
76
+
77
77
  def collect_visible(options = {}, &proc)
78
78
  columns = []
79
79
  options[:for] ||= @columns.active_record_class
@@ -90,8 +90,8 @@ module ActiveScaffold::DataStructures
90
90
  end
91
91
  end
92
92
  columns
93
- end
94
-
93
+ end
94
+
95
95
  def skip_column?(column, options)
96
96
  result = false
97
97
  # skip if this matches a constrained column
@@ -119,12 +119,12 @@ module ActiveScaffold::DataStructures
119
119
  def constraint_columns
120
120
  @constraint_columns ||= []
121
121
  end
122
-
122
+
123
123
  attr_writer :unauthorized_columns
124
124
  def unauthorized_columns
125
125
  @unauthorized_columns ||= []
126
126
  end
127
-
127
+
128
128
  def length
129
129
  ((@set - self.constraint_columns) - self.unauthorized_columns).length
130
130
  end
@@ -27,7 +27,7 @@ module ActiveScaffold::DataStructures
27
27
 
28
28
  # the action-path for this link. what page to request? this is required!
29
29
  attr_accessor :action
30
-
30
+
31
31
  # the controller for this action link. if nil, the current controller should be assumed.
32
32
  attr_accessor :controller
33
33
 
@@ -42,7 +42,7 @@ module ActiveScaffold::DataStructures
42
42
  def label
43
43
  @label.is_a?(Symbol) ? as_(@label) : @label
44
44
  end
45
-
45
+
46
46
  # image to use {:name => 'arrow.png', :size => '16x16'}
47
47
  attr_accessor :image
48
48
 
@@ -54,7 +54,7 @@ module ActiveScaffold::DataStructures
54
54
  def confirm?
55
55
  @confirm ? true : false
56
56
  end
57
-
57
+
58
58
  # if the action uses a DHTML based (i.e. 2-phase) confirmation
59
59
  attr_writer :dhtml_confirm
60
60
  def dhtml_confirm
@@ -74,9 +74,9 @@ module ActiveScaffold::DataStructures
74
74
  def security_method_set?
75
75
  !!@security_method
76
76
  end
77
-
77
+
78
78
  attr_accessor :ignore_method
79
-
79
+
80
80
  # the crud type of the (eventual?) action. different than :method, because this crud action may not be imminent.
81
81
  # this is used to determine record-level authorization (e.g. record.authorized_for?(:crud_type => link.crud_type).
82
82
  # options are :create, :read, :update, and :delete
@@ -145,18 +145,18 @@ module ActiveScaffold::DataStructures
145
145
 
146
146
  # html options for the link
147
147
  attr_accessor :html_options
148
-
148
+
149
149
  # nested action_links are referencing a column
150
150
  attr_accessor :column
151
-
151
+
152
152
  # indicates that this a nested_link
153
153
  def nested_link?
154
154
  @column || (parameters && parameters[:named_scope])
155
155
  end
156
-
156
+
157
157
  # Internal use: generated eid for this action_link
158
158
  attr_accessor :eid
159
-
160
-
159
+
160
+
161
161
  end
162
162
  end
@@ -8,11 +8,15 @@ module ActiveScaffold::DataStructures
8
8
 
9
9
  # adds an ActionLink, creating one from the arguments if need be
10
10
  def add(action, options = {})
11
- link = action.is_a?(ActiveScaffold::DataStructures::ActionLink) ? action : ActiveScaffold::DataStructures::ActionLink.new(action, options)
11
+ link = if action.is_a?(ActiveScaffold::DataStructures::ActionLink) || action.is_a?(ActiveScaffold::DataStructures::ActionLinks)
12
+ action
13
+ else
14
+ ActiveScaffold::DataStructures::ActionLink.new(action, options)
15
+ end
12
16
  # NOTE: this duplicate check should be done by defining the comparison operator for an Action data structure
13
- existing = @set.find {|a| a.action == link.action and a.controller == link.controller and a.parameters == link.parameters}
17
+ existing = find_duplicate(link)
14
18
  unless existing
15
- @set << link
19
+ subgroup(link.type, link.type).add_to_set(link)
16
20
  link
17
21
  else
18
22
  existing
@@ -20,40 +24,121 @@ module ActiveScaffold::DataStructures
20
24
  end
21
25
  alias_method :<<, :add
22
26
 
27
+ def add_to_set(link)
28
+ @set << link
29
+ end
30
+
23
31
  # finds an ActionLink by matching the action
24
32
  def [](val)
25
- @set.find {|item| item.action == val.to_s}
33
+ @set.find do |item|
34
+ if item.is_a?(ActiveScaffold::DataStructures::ActionLinks)
35
+ item[val]
36
+ else
37
+ item.action == val.to_s
38
+ end
39
+ end
40
+ end
41
+
42
+ def find_duplicate(link)
43
+ @set.find do |item|
44
+ if item.is_a?(ActiveScaffold::DataStructures::ActionLinks)
45
+ item.find_duplicate(link)
46
+ else
47
+ item.action == link.action and item.controller == link.controller and item.parameters == link.parameters
48
+ end
49
+ end
26
50
  end
27
51
 
28
52
  def delete(val)
29
- @set.delete_if{|item| item.action == val.to_s}
53
+ @set.delete_if do |item|
54
+ if item.is_a?(ActiveScaffold::DataStructures::ActionLinks)
55
+ delete(val)
56
+ else
57
+ item.action == val.to_s
58
+ end
59
+ end
30
60
  end
31
61
 
32
62
  # iterates over the links, possibly by type
33
63
  def each(type = nil)
34
- type = type.to_sym if type
35
64
  @set.each {|item|
36
- next if type and item.type != type
37
65
  yield item
38
66
  }
39
67
  end
40
-
68
+
41
69
  def collect_by_type(type = nil)
42
70
  links = []
43
- each(type) {|link| links << link}
71
+ subgroup(type).each(type) {|link| links << link}
44
72
  links
45
73
  end
46
74
 
75
+ def traverse(controller, options = {}, &block)
76
+ @set.each do |link|
77
+ if link.is_a?(ActiveScaffold::DataStructures::ActionLinks)
78
+ # add top node only if there is anything in the list
79
+ #yield({:kind => :node, :level => 1, :last => false, :link => link})
80
+ yield(link, nil, {:node => :start_traversing})
81
+ link.traverse(options, &block)
82
+ yield(link, nil, {:node => :finished_traversing})
83
+ #yield({:kind => :completed_group, :level => 1, :last => false, :link => link})
84
+ elsif controller.nil? || !skip_action_link(controller, link, options[:record])
85
+ authorized = options[:for].nil? ? true : options[:for].authorized_for?(:crud_type => link.crud_type, :action => link.action)
86
+ yield(self, link, {:authorized => authorized})
87
+ end
88
+ end
89
+ end
90
+
91
+ def collect
92
+ @set.collect
93
+ end
94
+
47
95
  def empty?
48
96
  @set.size == 0
49
97
  end
50
98
 
99
+ def subgroup(name, label = nil)
100
+ group = self if name == self.name
101
+ group ||= @set.find do |item|
102
+ name == item.name if item.is_a?(ActiveScaffold::DataStructures::ActionLinks)
103
+ end
104
+
105
+ if group.nil?
106
+ group = ActiveScaffold::DataStructures::ActionLinks.new
107
+ group.label = label || name
108
+ group.name = name
109
+ add_to_set group
110
+ end
111
+ group
112
+ end
113
+
114
+ attr_writer :label
115
+ def label
116
+ as_(@label) if @label
117
+ end
118
+
119
+ def method_missing(name, *args, &block)
120
+ class_eval %{
121
+ def #{name}
122
+ @#{name} ||= subgroup('#{name}'.to_sym)
123
+ yield @#{name} if block_given?
124
+ @#{name}
125
+ end
126
+ }
127
+ send(name, &block)
128
+ end
129
+
130
+ attr_accessor :name
131
+
51
132
  protected
52
133
 
134
+ def skip_action_link(controller, link, *args)
135
+ (!link.ignore_method.nil? and controller.try(link.ignore_method, *args)) || ((link.security_method_set? or controller.respond_to? link.security_method) and !controller.send(link.security_method, *args))
136
+ end
137
+
53
138
  # called during clone or dup. makes the clone/dup deeper.
54
139
  def initialize_copy(from)
55
140
  @set = []
56
141
  from.instance_variable_get('@set').each { |link| @set << link.clone }
57
142
  end
58
143
  end
59
- end
144
+ end
@@ -19,7 +19,7 @@ module ActiveScaffold::DataStructures
19
19
 
20
20
  # Whether to enable add_existing for this column
21
21
  attr_accessor :allow_add_existing
22
-
22
+
23
23
  # Any extra parameters this particular column uses. This is for create/update purposes.
24
24
  def params
25
25
  # lazy initialize
@@ -52,9 +52,9 @@ module ActiveScaffold::DataStructures
52
52
  def required?
53
53
  @required
54
54
  end
55
-
55
+
56
56
  attr_reader :update_columns
57
-
57
+
58
58
  # update dependent columns after value change in form
59
59
  # update_columns = :name
60
60
  # update_columns = [:name, :age]
@@ -199,7 +199,7 @@ module ActiveScaffold::DataStructures
199
199
  cattr_accessor :actions_for_association_links
200
200
  @@actions_for_association_links = [:new, :edit, :show]
201
201
  attr_accessor :actions_for_association_links
202
-
202
+
203
203
  cattr_accessor :association_form_ui
204
204
  @@association_form_ui = nil
205
205
 
@@ -269,13 +269,13 @@ module ActiveScaffold::DataStructures
269
269
  @form_ui = :checkbox if @column and @column.type == :boolean
270
270
  @allow_add_existing = true
271
271
  @form_ui = self.class.association_form_ui if @association && self.class.association_form_ui
272
-
272
+
273
273
  # default all the configurable variables
274
274
  self.css_class = ''
275
275
  self.required = active_record_class.validators_on(self.name).map(&:class).include? ActiveModel::Validations::PresenceValidator
276
276
  self.sort = true
277
277
  self.search_sql = true
278
-
278
+
279
279
  @weight = estimate_weight
280
280
 
281
281
  self.includes = (association and not polymorphic_association?) ? [association.name] : []
@@ -308,7 +308,7 @@ module ActiveScaffold::DataStructures
308
308
  end
309
309
  end
310
310
  end
311
-
311
+
312
312
  def initialize_search_sql
313
313
  self.search_sql = unless self.virtual?
314
314
  if association.nil?
@@ -328,13 +328,13 @@ module ActiveScaffold::DataStructures
328
328
  def field
329
329
  @field ||= [@active_record_class.connection.quote_column_name(@table), field_name].join('.')
330
330
  end
331
-
331
+
332
332
  def estimate_weight
333
333
  if singular_association?
334
334
  400
335
335
  elsif plural_association?
336
336
  500
337
- elsif [:created_at, :updated_at].include?(self.name)
337
+ elsif [:created_at, :updated_at].include?(self.name)
338
338
  600
339
339
  elsif [:name, :label, :title].include?(self.name)
340
340
  100
@@ -1,7 +1,7 @@
1
1
  module ActiveScaffold::DataStructures
2
2
  class NestedInfo
3
3
  def self.get(model, session_storage)
4
- if session_storage[:nested].nil?
4
+ if session_storage[:nested].nil?
5
5
  nil
6
6
  else
7
7
  session_info = session_storage[:nested].clone
@@ -13,32 +13,32 @@ module ActiveScaffold::DataStructures
13
13
  end
14
14
  end
15
15
  end
16
-
16
+
17
17
  attr_accessor :association, :child_association, :parent_model, :parent_id, :constrained_fields, :scope
18
-
18
+
19
19
  def initialize(model, session_info)
20
20
  @parent_model = session_info[:parent_model]
21
21
  @parent_id = session_info[:parent_id]
22
22
  end
23
-
23
+
24
24
  def new_instance?
25
25
  result = @new_instance.nil?
26
26
  @new_instance = false
27
27
  result
28
28
  end
29
-
29
+
30
30
  def parent_scope
31
31
  parent_model.find(parent_id)
32
32
  end
33
-
33
+
34
34
  def habtm?
35
- false
35
+ false
36
36
  end
37
-
37
+
38
38
  def belongs_to?
39
39
  false
40
40
  end
41
-
41
+
42
42
  def readonly?
43
43
  false
44
44
  end
@@ -47,22 +47,22 @@ module ActiveScaffold::DataStructures
47
47
  false
48
48
  end
49
49
  end
50
-
50
+
51
51
  class NestedInfoAssociation < NestedInfo
52
52
  def initialize(model, session_info)
53
53
  super(model, session_info)
54
54
  @association = session_info[:association]
55
55
  iterate_model_associations(model)
56
56
  end
57
-
57
+
58
58
  def habtm?
59
- association.macro == :has_and_belongs_to_many
59
+ association.macro == :has_and_belongs_to_many
60
60
  end
61
-
61
+
62
62
  def belongs_to?
63
63
  association.belongs_to?
64
64
  end
65
-
65
+
66
66
  def readonly?
67
67
  if association.options.has_key? :readonly
68
68
  association.options[:readonly]
@@ -78,11 +78,11 @@ module ActiveScaffold::DataStructures
78
78
  def default_sorting
79
79
  association.options[:order]
80
80
  end
81
-
81
+
82
82
  protected
83
-
83
+
84
84
  def iterate_model_associations(model)
85
- @constrained_fields = []
85
+ @constrained_fields = []
86
86
  @constrained_fields << association.primary_key_name.to_sym unless association.belongs_to?
87
87
  model.reflect_on_all_associations.each do |current|
88
88
  if !current.belongs_to? && association.primary_key_name == current.association_foreign_key
@@ -91,18 +91,18 @@ module ActiveScaffold::DataStructures
91
91
  end
92
92
  if association.primary_key_name == current.primary_key_name
93
93
  # show columns for has_many and has_one child associationes
94
- constrained_fields << current.name.to_sym if current.belongs_to?
94
+ constrained_fields << current.name.to_sym if current.belongs_to?
95
95
  @child_association = current
96
96
  end
97
97
  end
98
98
  end
99
99
  end
100
-
100
+
101
101
  class NestedInfoScope < NestedInfo
102
102
  def initialize(model, session_info)
103
103
  super(model, session_info)
104
104
  @scope = session_info[:name]
105
- @constrained_fields = []
105
+ @constrained_fields = []
106
106
  end
107
107
  end
108
108
  end
@@ -53,10 +53,11 @@ module ActiveScaffold::DataStructures
53
53
  def length
54
54
  @set.length
55
55
  end
56
-
56
+
57
57
  def empty?
58
58
  @set.empty?
59
59
  end
60
60
 
61
61
  end
62
- end
62
+
63
+ end
@@ -7,7 +7,7 @@ module ActiveScaffold::DataStructures
7
7
  @columns = columns
8
8
  @clauses = []
9
9
  end
10
-
10
+
11
11
  def set_default_sorting(model)
12
12
  model_scope = model.send(:current_scoped_methods)
13
13
  order_clause = model_scope.arel.order_clauses.join(",") if model_scope
@@ -26,7 +26,7 @@ module ActiveScaffold::DataStructures
26
26
  clear
27
27
  set_sorting_from_order_clause(order_clause, table_name)
28
28
  end
29
-
29
+
30
30
  # add a clause to the sorting, assuming the column is sortable
31
31
  def add(column_name, direction = nil)
32
32
  direction ||= 'ASC'
@@ -121,7 +121,7 @@ module ActiveScaffold::DataStructures
121
121
  def mixed_sorting?
122
122
  sorts_by_method? and sorts_by_sql?
123
123
  end
124
-
124
+
125
125
  def default_sorting?
126
126
  @default_sorting
127
127
  end
@@ -135,7 +135,7 @@ module ActiveScaffold::DataStructures
135
135
  end
136
136
  end
137
137
  end
138
-
138
+
139
139
  def extract_order_parts(criterion_parts)
140
140
  column_name_part, direction_part = criterion_parts.strip.split(' ')
141
141
  column_name_parts = column_name_part.split('.')
@@ -144,11 +144,11 @@ module ActiveScaffold::DataStructures
144
144
  order[:table_name] = remove_quotes(column_name_parts[-2]) if column_name_parts.length >= 2
145
145
  order
146
146
  end
147
-
147
+
148
148
  def different_table?(model_table_name, order_table_name)
149
149
  !order_table_name.nil? && model_table_name != order_table_name
150
150
  end
151
-
151
+
152
152
  def remove_quotes(sql_name)
153
153
  if sql_name.starts_with?('"') || sql_name.starts_with?('`')
154
154
  sql_name[1, (sql_name.length - 2)]
@@ -156,7 +156,7 @@ module ActiveScaffold::DataStructures
156
156
  sql_name
157
157
  end
158
158
  end
159
-
159
+
160
160
  def extract_direction(direction_part)
161
161
  if direction_part.to_s.upcase == 'DESC'
162
162
  'DESC'
@@ -330,7 +330,7 @@ module ActiveScaffold
330
330
 
331
331
  def column_heading_value(column, sorting, sort_direction)
332
332
  if column.sortable?
333
- options = {:id => search_form_id, :class => "as_sort",
333
+ options = {:id => nil, :class => "as_sort",
334
334
  'data-page-history' => controller_id,
335
335
  :remote => true, :method => :get}
336
336
  url_options = params_for(:action => :index, :page => 1,
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_scaffold
3
3
  version: !ruby/object:Gem::Version
4
- hash: 3
4
+ hash: 15
5
5
  prerelease: false
6
6
  segments:
7
7
  - 3
8
8
  - 0
9
- - 2
10
- version: 3.0.2
9
+ - 4
10
+ version: 3.0.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Many, see README
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-11-18 00:00:00 -05:00
18
+ date: 2010-11-20 00:00:00 -05:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency