active_scaffold_batch 3.2.2 → 3.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,13 +1,13 @@
1
1
  <% scope ||= nil %>
2
2
  <dl>
3
3
  <dt>
4
- <label for="<%= active_scaffold_input_options(column, scope)[:id] %>"><%= column.label %></label>
4
+ <label for="<%= (options = active_scaffold_input_options(column, scope, :object => record))[:id] %>"><%= column.label %></label>
5
5
  </dt>
6
6
  <dd>
7
7
  <% if column == batch_create_by_column.to_sym %>
8
- <%= active_scaffold_batch_create_by_column column, scope %>
8
+ <%= active_scaffold_batch_create_by_column column, scope, :object => record %>
9
9
  <% else %>
10
- <%= active_scaffold_input_for column, scope %>
10
+ <%= active_scaffold_input_for column, scope, options %>
11
11
  <% if column.update_columns -%>
12
12
  <%= loading_indicator_tag(:action => :render_field, :id => params[:id]) %>
13
13
  <% end -%>
@@ -18,8 +18,8 @@
18
18
  <% else
19
19
  renders_as = :field if renders_as == :subform -%>
20
20
  <li class="form-element <%= column.css_class unless column.css_class.nil? %>">
21
- <%= render :partial => 'batch_create_form_attribute', :locals => { :column => column } -%>
21
+ <%= render :partial => 'batch_create_form_attribute', :locals => { :column => column, :record => @record } -%>
22
22
  </li>
23
23
  <% end -%>
24
24
  <% end -%>
25
- </ol>
25
+ </ol>
@@ -1,12 +1,11 @@
1
1
  <div class="form sub-form horizontal-sub-form">
2
2
  <table cellpadding="0" cellspacing="0">
3
- <% @record = records.first -%>
4
- <%= render :partial => 'batch_create_form_horizontal_header', :locals => {:columns => columns, :record => @record} %>
3
+ <%= render :partial => 'batch_create_form_horizontal_header', :locals => {:columns => columns, :record => records.first} %>
5
4
 
6
5
  <tbody id="<%= element_form_id :action => form_action %>-content" class="multiple">
7
6
  <% first = true -%>
8
- <% records.each do |scope, @record| %>
9
- <%= render :partial => 'batch_create_form_horizontal_record', :locals => { :columns => columns, :form_action => form_action, :scope => "[#{scope}]", :first => first } %>
7
+ <% records.each do |scope, record| %>
8
+ <%= render :partial => 'batch_create_form_horizontal_record', :locals => { :columns => columns, :form_action => form_action, :scope => "[#{scope}]", :first => first, :record => record } %>
10
9
  <% first = false -%>
11
10
  <% end -%>
12
11
  </tbody>
@@ -1,8 +1,8 @@
1
1
  <% first = true unless local_assigns.has_key? :first -%>
2
- <% if @record.errors.count -%>
2
+ <% if record.errors.count -%>
3
3
  <tr class="form_record-errors">
4
- <td colspan="<%= columns.length + 1 %>" id="<%= element_messages_id :action => @record.class.name.underscore %>">
5
- <%= active_scaffold_error_messages_for :record, :object_name => @record.class.model_name.human.downcase %>
4
+ <td colspan="<%= columns.length + 1 %>" id="<%= element_messages_id :action => record.class.name.underscore %>">
5
+ <%= active_scaffold_error_messages_for :record, :object_name => record.class.model_name.human.downcase %>
6
6
  </td>
7
7
  </tr>
8
8
  <% end %>
@@ -10,7 +10,7 @@
10
10
  <% columns.each :flatten => true do |column| -%>
11
11
  <%
12
12
  next if column_renders_as(column) == :hidden
13
- next unless @record.authorized_for?(:crud_type => :create, :column => column.name)
13
+ next unless record.authorized_for?(:crud_type => :create, :column => column.name)
14
14
  column = column.clone
15
15
  column.form_ui ||= :select if column.association
16
16
 
@@ -19,7 +19,7 @@
19
19
  col_class << column.css_class unless column.css_class.nil?
20
20
  -%>
21
21
  <td class="<%= col_class.join(' ') %>">
22
- <%= render :partial => form_partial_for_column(column), :locals => { :column => column, :scope => scope } -%>
22
+ <%= render :partial => form_partial_for_column(column), :locals => { :column => column, :scope => scope, :record => record } -%>
23
23
  </td>
24
24
  <% end -%>
25
25
  <td><%= batch_create_multiple_remove_link unless first %></td>
@@ -1,7 +1,7 @@
1
1
  <div id="<%= element_form_id :action => form_action %>-content" class="multiple">
2
2
  <% first = true -%>
3
- <% records.each do |scope, @record| -%>
4
- <%= render :partial => 'batch_create_form_vertical_record', :locals => { :columns => columns, :form_action => form_action, :scope => "[#{scope}]", :first => first } %>
3
+ <% records.each do |scope, record| -%>
4
+ <%= render :partial => 'batch_create_form_vertical_record', :locals => { :columns => columns, :form_action => form_action, :scope => "[#{scope}]", :first => first, :record => record } %>
5
5
  <% first = false -%>
6
6
  <% end -%>
7
7
  </div>
@@ -4,9 +4,9 @@
4
4
  <label for="<%= active_scaffold_input_options(column, scope)[:id] %>"><%= column.label %></label>
5
5
  </dt>
6
6
  <dd>
7
- <%= active_scaffold_update_for column, scope %>
7
+ <%= active_scaffold_update_for column, scope, :object => record %>
8
8
  <% if column.description -%>
9
9
  <span class="description"><%= column.description %></span>
10
10
  <% end -%>
11
11
  </dd>
12
- </dl>
12
+ </dl>
@@ -10,15 +10,15 @@
10
10
  <% subsection_id = sub_section_id(:sub_section => column.label) %>
11
11
  <li class="sub-section">
12
12
  <h5><%= column.label %></h5>
13
- <%= render :partial => 'form', :locals => { :columns => column, :subsection_id => subsection_id} %>
14
- <%= link_to_visibility_toggle(subsection_id, {:default_visible => !column.collapsed}) -%>
13
+ <%= render :partial => 'form', :locals => { :columns => column, :subsection_id => subsection_id } %>
14
+ <%= link_to_visibility_toggle(subsection_id, :default_visible => !column.collapsed) -%>
15
15
  </li>
16
16
  <% elsif column.readonly_association?
17
17
  next %>
18
18
  <% else
19
19
  renders_as = :field if renders_as == :subform -%>
20
20
  <li class="form-element <%= column.css_class unless column.css_class.nil? %>">
21
- <%= render :partial => 'batch_update_form_attribute', :locals => { :column => column } -%>
21
+ <%= render :partial => 'batch_update_form_attribute', :locals => { :column => column, :record => @record } -%>
22
22
  </li>
23
23
  <% end -%>
24
24
  <% end -%>
@@ -1,5 +1,5 @@
1
1
  <% html = ''.html_safe -%>
2
- <% @records.each do |scope, @record| -%>
3
- <% html << render(:partial => "#{batch_create_multiple_layout}_record", :locals => { :columns => active_scaffold_config.batch_create.columns, :form_action => :batch_create, :scope => "[#{scope}]", :first => false }) %>
2
+ <% @records.each do |scope, record| -%>
3
+ <% html << render(:partial => "#{batch_create_multiple_layout}_record", :locals => { :columns => active_scaffold_config.batch_create.columns, :form_action => :batch_create, :scope => "[#{scope}]", :first => false, :record => record }) %>
4
4
  <% end %>
5
5
  ActiveScaffold.create_associated_record_form('<%= element_form_id(:action => :batch_create) %>-content','<%= escape_javascript(html) %>', <%= {:singular => false}.to_json.html_safe %>);
@@ -57,7 +57,7 @@ module ActiveScaffold::Actions
57
57
 
58
58
  def process_batch
59
59
  send("before_do_#{action_name}")
60
- send("#{action_name}_#{batch_scope.downcase}") if !batch_scope.nil? && respond_to?("#{action_name}_#{batch_scope.downcase}")
60
+ send("#{action_name}_#{batch_scope.downcase}") if !batch_scope.nil? && respond_to?("#{action_name}_#{batch_scope.downcase}", true)
61
61
  prepare_error_record unless batch_successful?
62
62
  end
63
63
 
@@ -76,7 +76,7 @@ module ActiveScaffold::Actions
76
76
  end
77
77
 
78
78
  def batch_base_respond_to_html
79
- if respond_to? "#{action_name}_respond_to_html"
79
+ if respond_to? "#{action_name}_respond_to_html", true
80
80
  send("#{action_name}_respond_to_html")
81
81
  else
82
82
  if params[:iframe]=='true' # was this an iframe post ?
@@ -92,7 +92,7 @@ module ActiveScaffold::Actions
92
92
  end
93
93
 
94
94
  def batch_base_respond_to_js
95
- if respond_to? "#{action_name}_respond_to_js"
95
+ if respond_to? "#{action_name}_respond_to_js", true
96
96
  send("#{action_name}_respond_to_js")
97
97
  else
98
98
  do_refresh_list
@@ -101,7 +101,7 @@ module ActiveScaffold::Actions
101
101
  end
102
102
 
103
103
  def batch_base_respond_to_xml
104
- if respond_to? "#{action_name}_respond_to_xml"
104
+ if respond_to? "#{action_name}_respond_to_xml", true
105
105
  send("#{action_name}_respond_to_xml")
106
106
  else
107
107
  render :xml => response_object.to_xml(:only => active_scaffold_config.send(action_name).columns.names), :content_type => Mime::XML, :status => response_status
@@ -109,7 +109,7 @@ module ActiveScaffold::Actions
109
109
  end
110
110
 
111
111
  def batch_base_respond_to_json
112
- if respond_to? "#{action_name}_respond_to_json"
112
+ if respond_to? "#{action_name}_respond_to_json", true
113
113
  send("#{action_name}_respond_to_json")
114
114
  else
115
115
  render :text => response_object.to_json(:only => active_scaffold_config.send(action_name).columns.names), :content_type => Mime::JSON, :status => response_status
@@ -117,7 +117,7 @@ module ActiveScaffold::Actions
117
117
  end
118
118
 
119
119
  def batch_base_respond_to_yaml
120
- if respond_to? "#{action_name}_respond_to_yaml"
120
+ if respond_to? "#{action_name}_respond_to_yaml", true
121
121
  send("#{action_name}_respond_to_yaml")
122
122
  else
123
123
  render :text => Hash.from_xml(response_object.to_xml(:only => active_scaffold_config.send(action_name).columns.names)).to_yaml, :content_type => Mime::YAML, :status => response_status
@@ -125,7 +125,7 @@ module ActiveScaffold::Actions
125
125
  end
126
126
 
127
127
  def batch_base_formats
128
- if respond_to? "#{action_name}_formats"
128
+ if respond_to? "#{action_name}_formats", true
129
129
  send("#{action_name}_formats")
130
130
  else
131
131
  (default_formats + active_scaffold_config.formats + active_scaffold_config.send(action_name).formats).uniq
@@ -50,9 +50,9 @@ module ActiveScaffold::Actions
50
50
  if marked_records_parent
51
51
  column = active_scaffold_config.columns[batch_create_by_column.to_sym]
52
52
  @batch_create_by_records = if column.polymorphic_association?
53
- active_scaffold_config_for(params[:batch_create_by].singularize).model.find(marked_records_parent.to_a)
53
+ active_scaffold_config_for(params[:batch_create_by].singularize).model.find(marked_records_parent.keys)
54
54
  else
55
- column_plural_assocation_value_from_value(column, marked_records_parent)
55
+ column_plural_assocation_value_from_value(column, marked_records_parent.keys)
56
56
  end
57
57
  end
58
58
  end
@@ -101,7 +101,7 @@ module ActiveScaffold::Actions
101
101
  if @marked_records_parent.nil?
102
102
  @marked_records_parent = if params[:batch_create_by]
103
103
  session_parent = active_scaffold_session_storage(params[:batch_create_by])
104
- session_parent[:marked_records] || Set.new
104
+ session_parent[:marked_records] || {}
105
105
  else
106
106
  false
107
107
  end
@@ -184,7 +184,7 @@ module ActiveScaffold::Actions
184
184
  def create_record_in_batch(created_by)
185
185
  @successful = nil
186
186
  @record = new_batch_create_record(created_by)
187
- @record.send("#{batch_create_by_column.to_s}=", created_by)
187
+ @record.send("#{batch_create_by_column}=", created_by)
188
188
  batch_create_values.each do |attribute, value|
189
189
  set_record_attribute(value[:column], attribute, value[:value])
190
190
  end
@@ -192,7 +192,7 @@ module ActiveScaffold::Actions
192
192
  if authorized_for_job?(@record)
193
193
  create_save(@record)
194
194
  if successful?
195
- marked_records_parent.delete(created_by.id) if batch_scope == 'MARKED' && marked_records_parent
195
+ marked_records_parent.delete(created_by.id.to_s) if batch_scope == 'MARKED' && marked_records_parent
196
196
  end
197
197
  error_records << @record unless successful? && !run_in_transaction?
198
198
  end
@@ -207,13 +207,21 @@ module ActiveScaffold::Actions
207
207
  columns.each :for => active_scaffold_config.model, :crud_type => :create, :flatten => true do |column|
208
208
  next unless attributes.has_key?(column.name)
209
209
  if column == batch_create_by_column.to_sym
210
- @batch_create_by_records = column_plural_assocation_value_from_value(column, attributes[column.name])
210
+ @batch_create_by_records = batch_values_for_column(column, attributes[column.name])
211
211
  else
212
212
  values[column.name] = {:column => column, :value => column_value_from_param_value(nil, column, attributes[column.name])}
213
213
  end
214
214
  end
215
215
  values
216
216
  end
217
+
218
+ def batch_values_for_column(column, value)
219
+ if column.association
220
+ column_plural_assocation_value_from_value(column, value)
221
+ else
222
+ value.split("\n")
223
+ end
224
+ end
217
225
 
218
226
  # The default security delegates to ActiveRecordPermissions.
219
227
  # You may override the method to customize.
@@ -227,7 +235,7 @@ module ActiveScaffold::Actions
227
235
 
228
236
  def override_batch_create_value(form_ui)
229
237
  method = "batch_create_value_for_#{form_ui}"
230
- method if respond_to? method
238
+ method if respond_to? method, true
231
239
  end
232
240
 
233
241
  def create_ignore?
@@ -22,7 +22,7 @@ module ActiveScaffold::Actions
22
22
  destroy_record(record) if authorized_for_job?(record)
23
23
  end
24
24
  when :delete_all then
25
- do_search if respond_to? :do_search
25
+ do_search if respond_to? :do_search, true
26
26
  # dummy condition cause we have to call delete_all on relation not on association
27
27
  beginning_of_chain.where('1=1').delete_all(all_conditions)
28
28
  else
@@ -93,7 +93,7 @@ module ActiveScaffold::Actions
93
93
  when :update_all then
94
94
  updates = updates_for_update_all
95
95
  unless updates.first.empty?
96
- do_search if respond_to? :do_search
96
+ do_search if respond_to? :do_search, true
97
97
  # all_conditions might fail cause joins are not working in update_all
98
98
  active_scaffold_config.model.update_all(updates, all_conditions)
99
99
  end
@@ -260,12 +260,12 @@ module ActiveScaffold::Actions
260
260
 
261
261
  def override_batch_update_value(form_ui)
262
262
  method = "batch_update_value_for_#{form_ui}"
263
- method if respond_to? method
263
+ method if respond_to? method, true
264
264
  end
265
265
 
266
266
  def override_batch_update_all_value(form_ui)
267
267
  method = "batch_update_all_value_for_#{form_ui}"
268
- method if respond_to? method
268
+ method if respond_to? method, true
269
269
  end
270
270
 
271
271
  private
@@ -9,8 +9,10 @@ module ActiveScaffold
9
9
 
10
10
  if column.form_ui == :record_select
11
11
  active_scaffold_record_select(column, options, batch_create_by_records, true)
12
- else
12
+ elsif column.association
13
13
  active_scaffold_batch_create_singular_association(column, options)
14
+ else
15
+ text_area_tag(column.name, params[:record] ? params[:record][column.name] : '', options.merge(column.options[:html_options] || {}))
14
16
  end
15
17
 
16
18
  end
@@ -6,10 +6,11 @@ module ActiveScaffold
6
6
  # It does not do any rendering. It only decides which method is responsible for rendering.
7
7
  def active_scaffold_update_for(column, scope = nil, options = {})
8
8
  options = active_scaffold_input_options(column, scope, options)
9
+ options.delete(:required)
9
10
 
10
11
  # first, check if the dev has created an override for this specific field for search
11
12
  if (method = override_update_field(column))
12
- send(method, @record, options)
13
+ send(method, options[:object], options)
13
14
  # second, check if the dev has specified a valid form_ui for this column, using specific ui for searches
14
15
  elsif column.form_ui and (method = override_update(column.form_ui))
15
16
  send(method, column, options)
@@ -1,8 +1,8 @@
1
1
  module ActiveScaffoldBatch
2
2
  module Version
3
3
  MAJOR = 3
4
- MINOR = 2
5
- PATCH = 2
4
+ MINOR = 3
5
+ PATCH = 0
6
6
 
7
7
  STRING = [MAJOR, MINOR, PATCH].compact.join('.')
8
8
  end
metadata CHANGED
@@ -5,9 +5,9 @@ version: !ruby/object:Gem::Version
5
5
  prerelease:
6
6
  segments:
7
7
  - 3
8
- - 2
9
- - 2
10
- version: 3.2.2
8
+ - 3
9
+ - 0
10
+ version: 3.3.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Sergio Cambra
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2013-02-19 00:00:00 Z
19
+ date: 2014-09-22 00:00:00 Z
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
22
  type: :runtime
@@ -25,16 +25,15 @@ dependencies:
25
25
  requirements:
26
26
  - - ">="
27
27
  - !ruby/object:Gem::Version
28
- hash: -225653461
28
+ hash: 11
29
29
  segments:
30
30
  - 3
31
31
  - 3
32
32
  - 0
33
- - rc
34
- version: 3.3.0.rc
33
+ version: 3.3.0
35
34
  version_requirements: *id001
36
- prerelease: false
37
35
  name: active_scaffold
36
+ prerelease: false
38
37
  description: You want to destroy/update many records at once with activescaffold?
39
38
  email: activescaffold@googlegroups.com
40
39
  executables: []
@@ -117,7 +116,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
117
116
  requirements: []
118
117
 
119
118
  rubyforge_project:
120
- rubygems_version: 1.8.23
119
+ rubygems_version: 1.8.29
121
120
  signing_key:
122
121
  specification_version: 3
123
122
  summary: Batch Processing for ActiveScaffold