active_scaffold 3.1.14 → 3.1.15

Sign up to get free protection for your applications and to get access to all the features.
@@ -14,5 +14,6 @@
14
14
  <% require_asset "prototype/form_enhancements" %>
15
15
  <% require_asset "prototype/rico_corner" %>
16
16
  <% end %>
17
+ ActiveScaffold.config = <%= ActiveScaffold.js_config.to_json %>;
17
18
  <% ActiveScaffold.javascripts.each {|js| require_asset js} %>
18
19
  <% ActiveScaffold::Bridges.all_javascripts.each {|js| require_asset js} %>
@@ -894,6 +894,7 @@ ActiveScaffold.ActionLink.Abstract = Class.extend({
894
894
  this.enable();
895
895
  this.adapter.remove();
896
896
  if (this.hide_target) this.target.show();
897
+ if (ActiveScaffold.config.scroll_on_close) ActiveScaffold.scroll_to(this.target);
897
898
  },
898
899
 
899
900
  reload: function() {
@@ -791,6 +791,7 @@ ActiveScaffold.ActionLink.Abstract = Class.create({
791
791
  this.enable();
792
792
  this.adapter.remove();
793
793
  if (this.hide_target) this.target.show();
794
+ if (ActiveScaffold.config.scroll_on_close) ActiveScaffold.scroll_to(this.target);
794
795
  },
795
796
 
796
797
  reload: function() {
@@ -1,4 +1,4 @@
1
- <% url_options = params_for(:action => :index, :escape => false, :search => nil) -%>
1
+ <% url_options = params_for(:action => :index, :search => nil) -%>
2
2
  <%=
3
3
  options = {:id => element_form_id(:action => 'search'),
4
4
  :class => "as_form search",
@@ -11,8 +11,8 @@ show_add_new = column_show_add_new(column, associated, @record)
11
11
 
12
12
  return unless show_add_new or show_add_existing
13
13
 
14
- edit_associated_url = url_for(:action => 'edit_associated', :id => parent_record.id, :association => column.name, :associated_id => '--ID--', :escape => false, :eid => params[:eid], :parent_controller => params[:parent_controller], :parent_id => params[:parent_id]) if show_add_existing
15
- add_new_url = url_for(:action => 'edit_associated', :id => parent_record.id, :association => column.name, :escape => false, :eid => params[:eid], :parent_controller => params[:parent_controller], :parent_id => params[:parent_id]) if show_add_new
14
+ edit_associated_url = url_for(:action => 'edit_associated', :id => parent_record.id, :association => column.name, :associated_id => '--ID--', :eid => params[:eid], :parent_controller => params[:parent_controller], :parent_id => params[:parent_id]) if show_add_existing
15
+ add_new_url = url_for(:action => 'edit_associated', :id => parent_record.id, :association => column.name, :eid => params[:eid], :parent_controller => params[:parent_controller], :parent_id => params[:parent_id]) if show_add_new
16
16
 
17
17
  -%>
18
18
  <div class="footer-wrapper">
@@ -19,7 +19,7 @@
19
19
  <% search_link = ActiveScaffold::DataStructures::ActionLink.new('index', :label => :click_to_reset, :type => :member, :position => false)
20
20
  action_links = ActiveScaffold::DataStructures::ActionLinks.new
21
21
  action_links.add(search_link) -%>
22
- <%= render :partial => 'list_actions', :locals => {:record => new_model, :url_options => params_for(:escape => false, :search => ''), :action_links => action_links.member} %>
22
+ <%= render :partial => 'list_actions', :locals => {:record => new_model, :url_options => params_for(:search => ''), :action_links => action_links.member} %>
23
23
  <% else %>
24
24
  <td class='actions'><%= '<p class="empty-message">&nbsp;</p>'.html_safe if @page.items.empty? %></td>
25
25
  <% end -%>
@@ -7,7 +7,7 @@ url_options = params_for(:action => :list, :id => record.id)
7
7
  action_links ||= active_scaffold_config.action_links.member
8
8
  -%>
9
9
 
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 %>">
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)).html_safe %>">
11
11
  <%= render :partial => 'list_record_columns', :locals => {:record => record, :columns => columns} %>
12
12
  <%= render :partial => 'list_actions', :locals => {:record => record, :url_options => url_options, :action_links => action_links} unless action_links.empty? %>
13
13
  <%= render_nested_view(action_links, url_options, record) unless @nested_auto_open.nil? %>
@@ -1,5 +1,5 @@
1
1
  <% live_search = active_scaffold_config.search.live? -%>
2
- <% url_options = params_for(:action => :index, :escape => false).delete_if{|k,v| k == 'search'} -%>
2
+ <% url_options = params_for(:action => :index).delete_if{|k,v| k == 'search'} -%>
3
3
  <%=
4
4
  options = {:id => element_form_id(:action => 'search'),
5
5
  :class => "as_form search",
@@ -4,7 +4,7 @@
4
4
  <%render_parent_options%>
5
5
  <%if render_parent_action == :row%>
6
6
  <%# TODO: That s not working with delete....%>
7
- ActiveScaffold.delete_record_row('<%=element_row_id(:controller_id => "as_#{id_from_controller(params[:eid] || params[:parent_sti])}", :action => 'list', :id => params[:id])%>', '<%=url_for(params_for(:action => :index, :id => nil, :page => [active_scaffold_config.list.user.page.to_i - 1, 1].max, :escape => false))%>');
7
+ ActiveScaffold.delete_record_row('<%=element_row_id(:controller_id => "as_#{id_from_controller(params[:eid] || params[:parent_sti])}", :action => 'list', :id => params[:id])%>', '<%=url_for(params_for(:action => :index, :id => nil, :page => [active_scaffold_config.list.user.page.to_i - 1, 1].max))%>');
8
8
  <%messages_id = active_scaffold_messages_id(:controller_id => "as_#{id_from_controller(params[:eid] || params[:parent_sti])}")%>
9
9
  <%elsif render_parent_action == :index%>
10
10
  <%= escape_javascript(controller.send(:render_component_into_view, render_parent_options))%>
@@ -13,7 +13,7 @@
13
13
  <%elsif (active_scaffold_config.delete.refresh_list)%>
14
14
  ActiveScaffold.replace('<%=active_scaffold_content_id%>', '<%=escape_javascript(render(:partial => 'list', :layout => false))%>');
15
15
  <%else%>
16
- ActiveScaffold.delete_record_row('<%=element_row_id(:action => 'list', :id => params[:id])%>', '<%=url_for(params_for(:action => :index, :id => nil, :page => [active_scaffold_config.list.user.page.to_i - 1, 1].max, :escape => false))%>');
16
+ ActiveScaffold.delete_record_row('<%=element_row_id(:action => 'list', :id => params[:id])%>', '<%=url_for(params_for(:action => :index, :id => nil, :page => [active_scaffold_config.list.user.page.to_i - 1, 1].max))%>');
17
17
  <% if active_scaffold_config.list.columns.any? {|c| c.calculation?}%>
18
18
  ActiveScaffold.replace('<%=active_scaffold_calculations_id%>', '<%=escape_javascript(render(:partial => 'list_calculations'))%>');
19
19
  <% end %>
@@ -21,4 +21,4 @@
21
21
  <%else%>
22
22
  <%flash[:error] = active_scaffold_error_messages_for(@record, :object_name => "#{@record.class.model_name.human.downcase}#{@record.new_record? ? '' : ": #{@record.to_label}"}", :header_message => '', :message => "#{@record.class.model_name.human.downcase}#{@record.new_record? ? '' : ": #{@record.to_label}"}", :container_tag => nil, :list_type => :br)%>
23
23
  <%end%>
24
- ActiveScaffold.replace_html('<%=messages_id%>', '<%=escape_javascript(render(:partial => 'messages'))%>');
24
+ ActiveScaffold.replace_html('<%=messages_id%>', '<%=escape_javascript(render(:partial => 'messages'))%>');
@@ -2,6 +2,7 @@ module ActiveScaffold::Actions
2
2
  module Core
3
3
  def self.included(base)
4
4
  base.class_eval do
5
+ after_filter :clean_up_session
5
6
  after_filter :clear_flashes
6
7
  end
7
8
  base.helper_method :nested?
@@ -17,6 +18,9 @@ module ActiveScaffold::Actions
17
18
  end
18
19
 
19
20
  protected
21
+ def clean_up_session
22
+ backup = session.reject! { |k, v| k.is_a?(String) && v != active_scaffold_session_storage && k.start_with?('as:')}
23
+ end
20
24
 
21
25
  def nested?
22
26
  false
@@ -165,7 +169,7 @@ module ActiveScaffold::Actions
165
169
  params = params[:record] || {} unless params[model.inheritance_column] # in create action must be inside record key
166
170
  model = params.delete(model.inheritance_column).camelize.constantize if params[model.inheritance_column]
167
171
  end
168
- model.new(build_options || {})
172
+ model.respond_to?(:build) ? model.build(build_options || {}) : model.new
169
173
  end
170
174
 
171
175
  private
@@ -17,11 +17,6 @@ module ActiveScaffold::Actions
17
17
 
18
18
  protected
19
19
  def nested
20
- @nested ||= ActiveScaffold::DataStructures::NestedInfo.get(active_scaffold_config.model, active_scaffold_session_storage)
21
- if !@nested.nil? && @nested.new_instance?
22
- register_constraints_with_action_columns(@nested.constrained_fields, active_scaffold_config.list.hide_nested_column ? [] : [:list])
23
- active_scaffold_constraints[:id] = params[:id] if @nested.belongs_to?
24
- end
25
20
  @nested
26
21
  end
27
22
 
@@ -31,11 +26,12 @@ module ActiveScaffold::Actions
31
26
 
32
27
  def set_nested
33
28
  if params[:parent_scaffold] && ((params[:association] && params[:assoc_id]) || params[:named_scope])
34
- @nested = nil
35
- active_scaffold_session_storage[:nested] = {:parent_scaffold => params[:parent_scaffold].to_s,
36
- :name => (params[:association] || params[:named_scope]).to_sym,
37
- :parent_id => params[:assoc_id]}
38
- params.delete_if {|key, value| [:parent_scaffold, :association, :named_scope, :assoc_id].include? key.to_sym}
29
+ @nested = ActiveScaffold::DataStructures::NestedInfo.get(active_scaffold_config.model, params)
30
+ unless @nested.nil?
31
+ register_constraints_with_action_columns(@nested.constrained_fields, active_scaffold_config.list.hide_nested_column ? [] : [:list])
32
+ active_scaffold_constraints[:id] = params[:id] if @nested.belongs_to?
33
+ end
34
+ #params.delete_if {|key, value| [:parent_scaffold, :association, :named_scope, :assoc_id].include? key.to_sym}
39
35
  end
40
36
  end
41
37
 
@@ -17,11 +17,6 @@ module ActiveScaffold::Actions
17
17
 
18
18
  protected
19
19
  def nested
20
- @nested ||= ActiveScaffold::DataStructures::NestedInfo.get(active_scaffold_config.model, active_scaffold_session_storage)
21
- if !@nested.nil? && @nested.new_instance?
22
- register_constraints_with_action_columns(@nested.constrained_fields, active_scaffold_config.list.hide_nested_column ? [] : [:list])
23
- active_scaffold_constraints[:id] = params[:id] if @nested.belongs_to?
24
- end
25
20
  @nested
26
21
  end
27
22
 
@@ -31,11 +26,16 @@ module ActiveScaffold::Actions
31
26
 
32
27
  def set_nested
33
28
  if params[:parent_scaffold] && ((params[:association] && params[:assoc_id]) || params[:named_scope])
34
- @nested = nil
35
- active_scaffold_session_storage[:nested] = {:parent_scaffold => params[:parent_scaffold].to_s,
36
- :name => (params[:association] || params[:named_scope]).to_sym,
37
- :parent_id => params[:assoc_id]}
38
- params.delete_if {|key, value| [:parent_scaffold, :association, :named_scope, :assoc_id].include? key.to_sym}
29
+ nested_info = {:parent_scaffold => params[:parent_scaffold].to_s,
30
+ :association => params[:association],
31
+ :named_scope => params[:named_scope],
32
+ :parent_id => params[:assoc_id]}
33
+ @nested = ActiveScaffold::DataStructures::NestedInfo.get(active_scaffold_config.model, nested_info)
34
+ unless @nested.nil?
35
+ register_constraints_with_action_columns(@nested.constrained_fields, active_scaffold_config.list.hide_nested_column ? [] : [:list])
36
+ active_scaffold_constraints[:id] = params[:id] if @nested.belongs_to?
37
+ end
38
+ #params.delete_if {|key, value| [:parent_scaffold, :association, :named_scope, :assoc_id].include? key.to_sym}
39
39
  end
40
40
  end
41
41
 
@@ -83,7 +83,6 @@ module ActiveScaffold::Actions
83
83
 
84
84
  def beginning_of_chain
85
85
  if nested? && nested.association && !nested.association.belongs_to?
86
- debugger
87
86
  if nested.association.collection?
88
87
  nested.parent_scope.send(nested.association.name)
89
88
  elsif nested.child_association.belongs_to?
@@ -25,7 +25,8 @@ module ActiveScaffold::Config
25
25
  # delegate
26
26
  def crud_type; self.class.crud_type end
27
27
 
28
- def label(model = @core.label(:count => 1))
28
+ def label(model = nil)
29
+ model ||= @core.label(:count => 1)
29
30
  @label.nil? ? model : as_(@label, :model => model)
30
31
  end
31
32
 
@@ -43,6 +44,7 @@ module ActiveScaffold::Config
43
44
  def initialize(conf, storage, params)
44
45
  # the session hash relevant to this action
45
46
  @session = storage
47
+ debugger
46
48
  # all the request params
47
49
  @params = params
48
50
  # the configuration object for this action
@@ -0,0 +1,195 @@
1
+ module ActiveScaffold::Config
2
+ class List < Base
3
+ self.crud_type = :read
4
+
5
+ def initialize(core_config)
6
+ super
7
+ # inherit from global scope
8
+ # full configuration path is: defaults => global table => local table
9
+ @per_page = self.class.per_page
10
+ @page_links_window = self.class.page_links_window
11
+
12
+ # originates here
13
+ @sorting = ActiveScaffold::DataStructures::Sorting.new(@core.columns)
14
+ @sorting.set_default_sorting(@core.model)
15
+
16
+ # inherit from global scope
17
+ @empty_field_text = self.class.empty_field_text
18
+ @association_join_text = self.class.association_join_text
19
+ @pagination = self.class.pagination
20
+ @show_search_reset = true
21
+ @mark_records = self.class.mark_records
22
+ end
23
+
24
+ # global level configuration
25
+ # --------------------------
26
+ # how many records to show per page
27
+ cattr_accessor :per_page
28
+ @@per_page = 15
29
+
30
+ # how many page links around current page to show
31
+ cattr_accessor :page_links_window
32
+ @@page_links_window = 2
33
+
34
+ # what string to use when a field is empty
35
+ cattr_accessor :empty_field_text
36
+ @@empty_field_text = '-'
37
+
38
+ # what string to use to join records from plural associations
39
+ cattr_accessor :association_join_text
40
+ @@association_join_text = ', '
41
+
42
+ # What kind of pagination to use:
43
+ # * true: The usual pagination
44
+ # * :infinite: Treat the source as having an infinite number of pages (i.e. don't count the records; useful for large tables where counting is slow and we don't really care anyway)
45
+ # * false: Disable pagination
46
+ cattr_accessor :pagination
47
+ @@pagination = true
48
+
49
+ # Add a checkbox in front of each record to mark them and use them with a batch action later
50
+ cattr_accessor :mark_records
51
+
52
+ # instance-level configuration
53
+ # ----------------------------
54
+
55
+ # provides access to the list of columns specifically meant for the Table to use
56
+ def columns
57
+ self.columns = @core.columns._inheritable unless @columns # lazy evaluation
58
+ @columns
59
+ end
60
+
61
+ public :columns=
62
+
63
+ # how many rows to show at once
64
+ attr_accessor :per_page
65
+
66
+ # how many page links around current page to show
67
+ attr_accessor :page_links_window
68
+
69
+ # What kind of pagination to use:
70
+ # * true: The usual pagination
71
+ # * :infinite: Treat the source as having an infinite number of pages (i.e. don't count the records; useful for large tables where counting is slow and we don't really care anyway)
72
+ # * false: Disable pagination
73
+ attr_accessor :pagination
74
+
75
+ # what string to use when a field is empty
76
+ attr_accessor :empty_field_text
77
+
78
+ # what string to use to join records from plural associations
79
+ attr_accessor :association_join_text
80
+
81
+ # show a link to reset the search next to filtered message
82
+ attr_accessor :show_search_reset
83
+
84
+ # Add a checkbox in front of each record to mark them and use them with a batch action later
85
+ attr_accessor :mark_records
86
+
87
+ # the default sorting. should be an array of hashes of {column_name => direction}, e.g. [{:a => 'desc'}, {:b => 'asc'}]. to just sort on one column, you can simply provide a hash, though, e.g. {:a => 'desc'}.
88
+ def sorting=(val)
89
+ val = [val] if val.is_a? Hash
90
+ sorting.clear
91
+ val.each { |clause| sorting.add *Array(clause).first }
92
+ end
93
+ def sorting
94
+ @sorting ||= ActiveScaffold::DataStructures::Sorting.new(@core.columns)
95
+ end
96
+
97
+ # overwrite the includes used for the count sql query
98
+ attr_accessor :count_includes
99
+
100
+ # the label for this List action. used for the header.
101
+ attr_writer :label
102
+ def label
103
+ @label ? as_(@label, :count => 2) : @core.label(:count => 2)
104
+ end
105
+
106
+ attr_writer :no_entries_message
107
+ def no_entries_message
108
+ @no_entries_message ? @no_entries_message : :no_entries
109
+ end
110
+
111
+ attr_writer :filtered_message
112
+ def filtered_message
113
+ @filtered_message ? @filtered_message : :filtered
114
+ end
115
+
116
+ attr_writer :always_show_search
117
+ def always_show_search
118
+ @always_show_search && !search_partial.blank?
119
+ end
120
+
121
+ def search_partial
122
+ return "search" if @core.actions.include?(:search)
123
+ return "field_search" if @core.actions.include?(:field_search)
124
+ end
125
+
126
+ # always show create
127
+ attr_writer :always_show_create
128
+ def always_show_create
129
+ @always_show_create && @core.actions.include?(:create)
130
+ end
131
+
132
+ # if list view is nested hide nested_column
133
+ attr_writer :hide_nested_column
134
+ def hide_nested_column
135
+ @hide_nested_column.nil? ? true : @hide_nested_column
136
+ end
137
+
138
+ # might be set to open nested_link automatically in view
139
+ # conf.nested.add_link(:players)
140
+ # conf.list.nested_auto_open = {:players => 2}
141
+ # will open nested players view if there are 2 or less records in parent
142
+ attr_accessor :nested_auto_open
143
+
144
+ class UserSettings < UserSettings
145
+ # This label has alread been localized.
146
+ def label
147
+ @session[:label] ? @session[:label] : @conf.label
148
+ end
149
+
150
+ def per_page
151
+ @session['per_page'] = @params['limit'].to_i if @params.has_key? 'limit'
152
+ @session['per_page'] || @conf.per_page
153
+ end
154
+
155
+ def page
156
+ @session['page'] = @params['page'] if @params.has_key? 'page'
157
+ @session['page'] || 1
158
+ end
159
+
160
+ def page=(value = nil)
161
+ @session['page'] = value
162
+ end
163
+
164
+ attr_reader :nested_default_sorting
165
+
166
+ def nested_default_sorting=(options)
167
+ @nested_default_sorting ||= @conf.sorting.clone
168
+ @nested_default_sorting.set_nested_sorting(options[:table_name], options[:default_sorting])
169
+ end
170
+
171
+ def default_sorting
172
+ nested_default_sorting.nil? ? @conf.sorting : nested_default_sorting
173
+ end
174
+
175
+ def sorting
176
+ # we want to store as little as possible in the session, but we want to return a Sorting data structure. so we recreate it each page load based on session data.
177
+ debugger
178
+ @session['sort'] = [@params['sort'], @params['sort_direction']] if @params['sort'] and @params['sort_direction']
179
+ @session['sort'] = nil if @params['sort_direction'] == 'reset'
180
+
181
+ if @session['sort']
182
+ sorting = @conf.sorting.clone
183
+ sorting.set(*@session['sort'])
184
+ return sorting
185
+ else
186
+ return default_sorting
187
+ end
188
+ end
189
+
190
+ def count_includes
191
+ @conf.count_includes
192
+ end
193
+ end
194
+ end
195
+ end
@@ -1,31 +1,28 @@
1
1
  module ActiveScaffold::DataStructures
2
2
  class NestedInfo
3
- def self.get(model, session_storage)
4
- if session_storage[:nested].nil?
5
- nil
6
- else
7
- session_info = session_storage[:nested].clone
8
- begin
9
- session_info[:parent_scaffold] = "#{session_info[:parent_scaffold].to_s.camelize}Controller".constantize
10
- session_info[:parent_model] = session_info[:parent_scaffold].active_scaffold_config.model
11
- session_info[:association] = session_info[:parent_model].reflect_on_association(session_info[:name])
12
- unless session_info[:association].nil?
13
- ActiveScaffold::DataStructures::NestedInfoAssociation.new(model, session_info)
14
- else
15
- ActiveScaffold::DataStructures::NestedInfoScope.new(model, session_info)
16
- end
17
- rescue ActiveScaffold::ControllerNotFound
18
- nil
3
+ def self.get(model, params)
4
+ nested_info = {}
5
+ begin
6
+ nested_info[:name] = (params[:association] || params[:named_scope]).to_sym
7
+ nested_info[:parent_scaffold] = "#{params[:parent_scaffold].to_s.camelize}Controller".constantize
8
+ nested_info[:parent_model] = nested_info[:parent_scaffold].active_scaffold_config.model
9
+ nested_info[:parent_id] = params[nested_info[:parent_model].name.foreign_key]
10
+ unless nested_info[:association].nil?
11
+ ActiveScaffold::DataStructures::NestedInfoAssociation.new(model, nested_info)
12
+ else
13
+ ActiveScaffold::DataStructures::NestedInfoScope.new(model, nested_info)
19
14
  end
15
+ rescue ActiveScaffold::ControllerNotFound
16
+ nil
20
17
  end
21
18
  end
22
19
 
23
20
  attr_accessor :association, :child_association, :parent_model, :parent_scaffold, :parent_id, :constrained_fields, :scope
24
21
 
25
- def initialize(model, session_info)
26
- @parent_model = session_info[:parent_model]
27
- @parent_id = session_info[:parent_id]
28
- @parent_scaffold = session_info[:parent_scaffold]
22
+ def initialize(model, nested_info)
23
+ @parent_model = nested_info[:parent_model]
24
+ @parent_id = nested_info[:parent_id]
25
+ @parent_scaffold = nested_info[:parent_scaffold]
29
26
  end
30
27
 
31
28
  def to_params
@@ -64,9 +61,9 @@ module ActiveScaffold::DataStructures
64
61
  end
65
62
 
66
63
  class NestedInfoAssociation < NestedInfo
67
- def initialize(model, session_info)
68
- super(model, session_info)
69
- @association = session_info[:association]
64
+ def initialize(model, nested_info)
65
+ super(model, nested_info)
66
+ @association = parent_model.reflect_on_association(nested_info[:name])
70
67
  iterate_model_associations(model)
71
68
  end
72
69
 
@@ -126,9 +123,9 @@ module ActiveScaffold::DataStructures
126
123
  end
127
124
 
128
125
  class NestedInfoScope < NestedInfo
129
- def initialize(model, session_info)
130
- super(model, session_info)
131
- @scope = session_info[:name]
126
+ def initialize(model, nested_info)
127
+ super(model, nested_info)
128
+ @scope = nested_info[:name]
132
129
  @constrained_fields = []
133
130
  end
134
131
 
@@ -1,31 +1,29 @@
1
1
  module ActiveScaffold::DataStructures
2
2
  class NestedInfo
3
- def self.get(model, session_storage)
4
- if session_storage[:nested].nil?
5
- nil
6
- else
7
- session_info = session_storage[:nested].clone
8
- begin
9
- session_info[:parent_scaffold] = "#{session_info[:parent_scaffold].to_s.camelize}Controller".constantize
10
- session_info[:parent_model] = session_info[:parent_scaffold].active_scaffold_config.model
11
- session_info[:association] = session_info[:parent_model].reflect_on_association(session_info[:name])
12
- unless session_info[:association].nil?
13
- ActiveScaffold::DataStructures::NestedInfoAssociation.new(model, session_info)
14
- else
15
- ActiveScaffold::DataStructures::NestedInfoScope.new(model, session_info)
16
- end
17
- rescue ActiveScaffold::ControllerNotFound
18
- nil
3
+ def self.get(model, params)
4
+ nested_info = {}
5
+ begin
6
+ nested_info[:name] = (params[:association] || params[:named_scope]).to_sym
7
+ nested_info[:parent_scaffold] = "#{params[:parent_scaffold].to_s.camelize}Controller".constantize
8
+ nested_info[:parent_model] = nested_info[:parent_scaffold].active_scaffold_config.model
9
+ unless nested_info[:association].nil?
10
+ nested_info[:parent_id] = params[nested_info[:parent_model].name.foreign_key]
11
+ ActiveScaffold::DataStructures::NestedInfoAssociation.new(model, nested_info)
12
+ else
13
+ nested_info[:parent_id] = params[:assoc_id]
14
+ ActiveScaffold::DataStructures::NestedInfoScope.new(model, nested_info)
19
15
  end
16
+ rescue ActiveScaffold::ControllerNotFound
17
+ nil
20
18
  end
21
19
  end
22
20
 
23
21
  attr_accessor :association, :child_association, :parent_model, :parent_scaffold, :parent_id, :constrained_fields, :scope
24
22
 
25
- def initialize(model, session_info)
26
- @parent_model = session_info[:parent_model]
27
- @parent_id = session_info[:parent_id]
28
- @parent_scaffold = session_info[:parent_scaffold]
23
+ def initialize(model, nested_info)
24
+ @parent_model = nested_info[:parent_model]
25
+ @parent_id = nested_info[:parent_id]
26
+ @parent_scaffold = nested_info[:parent_scaffold]
29
27
  end
30
28
 
31
29
  def to_params
@@ -61,15 +59,12 @@ module ActiveScaffold::DataStructures
61
59
  def sorted?
62
60
  false
63
61
  end
64
-
65
- def name
66
- end
67
62
  end
68
63
 
69
64
  class NestedInfoAssociation < NestedInfo
70
- def initialize(model, session_info)
71
- super(model, session_info)
72
- @association = session_info[:association]
65
+ def initialize(model, nested_info)
66
+ super(model, nested_info)
67
+ @association = parent_model.reflect_on_association(nested_info[:name])
73
68
  iterate_model_associations(model)
74
69
  end
75
70
 
@@ -129,9 +124,9 @@ module ActiveScaffold::DataStructures
129
124
  end
130
125
 
131
126
  class NestedInfoScope < NestedInfo
132
- def initialize(model, session_info)
133
- super(model, session_info)
134
- @scope = session_info[:name]
127
+ def initialize(model, nested_info)
128
+ super(model, nested_info)
129
+ @scope = nested_info[:name]
135
130
  @constrained_fields = []
136
131
  end
137
132
 
@@ -28,6 +28,20 @@ module ActionDispatch
28
28
  ActionDispatch::Routing::ACTIVE_SCAFFOLD_ASSOCIATION_ROUTING[:member].each {|name, type| send(type, name)}
29
29
  end
30
30
  end
31
+
32
+ def as_nested_resources(*resources)
33
+ options = resources.extract_options!
34
+ resources.each do |resource|
35
+ resources(resource, options.merge(:parent_scaffold => merge_module_scope(@scope[:module], parent_resource.plural), :association => resource)) { yield if block_given? }
36
+ end
37
+ end
38
+
39
+ def as_scoped_routes(*scopes)
40
+ options = scopes.extract_options!
41
+ scopes.each do |scope|
42
+ resources(scope, options.merge(:parent_scaffold => merge_module_scope(@scope[:module], parent_resource.plural), :named_scope => scope, :controller => parent_resource.plural)) { yield if block_given? }
43
+ end
44
+ end
31
45
  end
32
46
  end
33
47
  end
@@ -28,6 +28,20 @@ module ActionDispatch
28
28
  ActionDispatch::Routing::ACTIVE_SCAFFOLD_ASSOCIATION_ROUTING[:member].each {|name, type| send(type, name)}
29
29
  end
30
30
  end
31
+
32
+ def as_nested_resources(*resources)
33
+ options = resources.extract_options!
34
+ resources.each do |resource|
35
+ resources(resource, options.merge(:parent_scaffold => merge_module_scope(@scope[:module], parent_resource.plural), :association => resource)) { yield if block_given? }
36
+ end
37
+ end
38
+
39
+ def as_scoped_routes(*scopes)
40
+ options = scopes.extract_options!
41
+ scopes.each do |scope|
42
+ resources(parent_resource.plural, options.merge(:parent_scaffold => merge_module_scope(@scope[:module], parent_resource.plural), :named_scope => scope, :as => :scope)) { yield if block_given? }
43
+ end
44
+ end
31
45
  end
32
46
  end
33
47
  end
@@ -30,12 +30,12 @@ module ActiveScaffold
30
30
  parameters = {}
31
31
  if params[:parent_controller]
32
32
  parameters[:controller] = params[:parent_controller]
33
- parameters[:eid] = params[:parent_controller]
33
+ #parameters[:eid] = params[:parent_controller]
34
34
  end
35
35
  parameters.merge! nested.to_params if nested?
36
36
  if params[:parent_sti]
37
37
  parameters[:controller] = params[:parent_sti]
38
- parameters[:eid] = nil
38
+ #parameters[:eid] = nil
39
39
  end
40
40
  parameters[:parent_column] = nil
41
41
  parameters[:parent_id] = nil
@@ -30,11 +30,9 @@ module ActiveScaffold
30
30
  parameters = {}
31
31
  if params[:parent_controller]
32
32
  parameters[:controller] = params[:parent_controller]
33
- parameters[:eid] = params[:parent_controller]
34
- end
35
- if nested?
36
- parameters.merge! nested.to_params
33
+ #parameters[:eid] = params[:parent_controller]
37
34
  end
35
+ parameters.merge! nested.to_params if nested?
38
36
  if params[:parent_sti]
39
37
  parameters[:controller] = params[:parent_sti]
40
38
  parameters[:eid] = nil
@@ -297,7 +297,7 @@ module ActiveScaffold
297
297
  elsif inplace_edit_cloning?(column)
298
298
  tag_options['data-ie_mode'] = :clone
299
299
  elsif column.inplace_edit == :ajax
300
- url = url_for(:controller => params_for[:controller], :action => 'render_field', :id => '__id__', :column => column.name, :update_column => column.name, :in_place_editing => true, :escape => false)
300
+ url = url_for(:controller => params_for[:controller], :action => 'render_field', :id => '__id__', :column => column.name, :update_column => column.name, :in_place_editing => true)
301
301
  plural = column.plural_association? && !override_form_field?(column) && [:select, :record_select].include?(column.form_ui)
302
302
  tag_options['data-ie_render_url'] = url
303
303
  tag_options['data-ie_mode'] = :ajax
@@ -188,14 +188,10 @@ module ActiveScaffold
188
188
 
189
189
  def url_options_for_nested_link(column, record, link, url_options, options = {})
190
190
  if column && column.association
191
- url_options[:assoc_id] = url_options.delete(:id)
191
+ url_options[column.association.active_record.name.foreign_key.to_sym] = url_options.delete(:id)
192
192
  url_options[:id] = record.send(column.association.name).id if column.singular_association? && record.send(column.association.name).present?
193
- link.eid = "#{controller_id.from(3)}_#{record.id}_#{column.association.name}" unless options.has_key?(:reuse_eid)
194
- url_options[:eid] = link.eid
195
193
  elsif link.parameters && link.parameters[:named_scope]
196
- url_options[:assoc_id] = url_options.delete(:id)
197
- link.eid = "#{controller_id.from(3)}_#{record.id}_#{link.parameters[:named_scope]}" unless options.has_key?(:reuse_eid)
198
- url_options[:eid] = link.eid
194
+ url_options[active_scaffold_config.model.name.foreign_key.to_sym] = url_options.delete(:id)
199
195
  end
200
196
  end
201
197
 
@@ -188,14 +188,11 @@ module ActiveScaffold
188
188
 
189
189
  def url_options_for_nested_link(column, record, link, url_options, options = {})
190
190
  if column && column.association
191
- url_options[:assoc_id] = url_options.delete(:id)
191
+ url_options[column.association.active_record.name.foreign_key.to_sym] = url_options.delete(:id)
192
192
  url_options[:id] = record.send(column.association.name).id if column.singular_association? && record.send(column.association.name).present?
193
- link.eid = "#{controller_id.from(3)}_#{record.id}_#{column.association.name}" unless options.has_key?(:reuse_eid)
194
- url_options[:eid] = link.eid
195
193
  elsif link.parameters && link.parameters[:named_scope]
196
- url_options[:assoc_id] = url_options.delete(:id)
197
- link.eid = "#{controller_id.from(3)}_#{record.id}_#{link.parameters[:named_scope]}" unless options.has_key?(:reuse_eid)
198
- url_options[:eid] = link.eid
194
+ index = url_options[:parent_scaffold] ? url_options[:parent_scaffold].camelize.singularize.foreign_key.to_sym : :assoc_id
195
+ url_options[index] = url_options.delete(:id)
199
196
  end
200
197
  end
201
198
 
@@ -239,7 +236,7 @@ module ActiveScaffold
239
236
  end
240
237
 
241
238
  def as_main_div_class
242
- classes = ["active-scaffold", "active-scaffold-#{controller_id}", "#{params[:controller]}-view", "#{active_scaffold_config.theme}-theme"]
239
+ classes = ["active-scaffold", "active-scaffold-#{controller_id}", "#{id_from_controller params[:controller]}-view", "#{active_scaffold_config.theme}-theme"]
243
240
  classes << "as_touch" if touch_device?
244
241
  classes.join(' ')
245
242
  end
@@ -2,7 +2,7 @@ module ActiveScaffold
2
2
  module Version
3
3
  MAJOR = 3
4
4
  MINOR = 1
5
- PATCH = 14
5
+ PATCH = 15
6
6
 
7
7
  STRING = [MAJOR, MINOR, PATCH].compact.join('.')
8
8
  end
@@ -13,6 +13,7 @@ require 'active_scaffold/responds_to_parent'
13
13
 
14
14
  require 'active_scaffold/version'
15
15
  require 'active_scaffold/engine' unless defined? ACTIVE_SCAFFOLD_PLUGIN
16
+ require 'json' # for js_config
16
17
 
17
18
  module ActiveScaffold
18
19
  autoload :AttributeParams, 'active_scaffold/attribute_params'
@@ -131,6 +132,14 @@ module ActiveScaffold
131
132
  end
132
133
  end
133
134
 
135
+ def self.js_config=(config)
136
+ @@js_config = config
137
+ end
138
+
139
+ def self.js_config
140
+ @@js_config ||= {:scroll_on_close => true}
141
+ end
142
+
134
143
  # exclude bridges you do not need
135
144
  # name of bridge subdir should be used to exclude it
136
145
  # eg
@@ -85,8 +85,8 @@ module ActiveScaffold
85
85
 
86
86
  def active_scaffold_session_storage(id = (params[:eid] || params[:controller]))
87
87
  session_index = "as:#{id}"
88
- session[session_index] ||= {}
89
- session[session_index]
88
+ cookies[session_index] = {:value => {}, :expires => 1.hour.from_now} unless cookies[session_index].present?
89
+ cookies[session_index]
90
90
  end
91
91
 
92
92
  # at some point we need to pass the session and params into config. we'll just take care of that before any particular action occurs by passing those hashes off to the UserSettings class of each action.
@@ -95,6 +95,7 @@ module ActiveScaffold
95
95
  active_scaffold_config.actions.each do |action_name|
96
96
  conf_instance = active_scaffold_config.send(action_name) rescue next
97
97
  next if conf_instance.class::UserSettings == ActiveScaffold::Config::Base::UserSettings # if it hasn't been extended, skip it
98
+ debugger
98
99
  active_scaffold_session_storage[action_name] ||= {}
99
100
  conf_instance.user = conf_instance.class::UserSettings.new(conf_instance, active_scaffold_session_storage[action_name], params)
100
101
  end
@@ -266,7 +267,7 @@ module ActiveScaffold
266
267
  column.actions_for_association_links.delete :new unless actions.include? :create
267
268
  column.actions_for_association_links.delete :edit unless actions.include? :update
268
269
  column.actions_for_association_links.delete :show unless actions.include? :show
269
- ActiveScaffold::DataStructures::ActionLink.new(nil, options.merge({:crud_type => nil, :html_options => {:class => column.name}}))
270
+ ActiveScaffold::DataStructures::ActionLink.new(nil, options.merge(:html_options => {:class => column.name}))
270
271
  end
271
272
  end
272
273
  end
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: 31
4
+ hash: 29
5
5
  prerelease:
6
6
  segments:
7
7
  - 3
8
8
  - 1
9
- - 14
10
- version: 3.1.14
9
+ - 15
10
+ version: 3.1.15
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: 2012-01-12 00:00:00 Z
18
+ date: 2012-01-18 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  version_requirements: &id001 !ruby/object:Gem::Requirement
@@ -251,6 +251,7 @@ files:
251
251
  - lib/active_scaffold/config/search.rb~
252
252
  - lib/active_scaffold/config/nested.rb~
253
253
  - lib/active_scaffold/config/base.rb~
254
+ - lib/active_scaffold/config/list.rb~
254
255
  - lib/active_scaffold/configurable.rb
255
256
  - lib/active_scaffold/constraints.rb
256
257
  - lib/active_scaffold/data_structures/action_columns.rb
@@ -347,11 +348,11 @@ files:
347
348
  - lib/active_scaffold/extensions/unsaved_associated.rb
348
349
  - lib/active_scaffold/extensions/unsaved_record.rb
349
350
  - lib/active_scaffold/extensions/usa_state.rb
351
+ - lib/active_scaffold/extensions/routing_mapper.rb~
350
352
  - lib/active_scaffold/extensions/action_controller_rendering.rb~
351
353
  - lib/active_scaffold/extensions/action_view_rendering.rb~
352
354
  - lib/active_scaffold/extensions/cache_association.rb~
353
355
  - lib/active_scaffold/extensions/reverse_associations.rb~
354
- - lib/active_scaffold/extensions/routing_mapper.rb~
355
356
  - lib/active_scaffold/extensions/unsaved_associated.rb~
356
357
  - lib/active_scaffold/extensions/active_association_reflection.rb~
357
358
  - lib/active_scaffold/paginator.rb