active_scaffold_batch 3.7.3 → 3.9.0

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.
Files changed (42) hide show
  1. checksums.yaml +4 -4
  2. data/README +101 -5
  3. data/app/assets/javascripts/active_scaffold_batch.js +10 -10
  4. data/app/assets/stylesshets/active_scaffold_batch.scss +4 -13
  5. data/app/views/active_scaffold_overrides/_batch_create_form.html.erb +8 -8
  6. data/app/views/active_scaffold_overrides/_batch_create_form_attribute.html.erb +7 -19
  7. data/app/views/active_scaffold_overrides/_batch_create_form_body.html.erb +24 -23
  8. data/app/views/active_scaffold_overrides/_batch_create_form_footer.html.erb +11 -2
  9. data/app/views/active_scaffold_overrides/_batch_create_form_horizontal.html.erb +24 -9
  10. data/app/views/active_scaffold_overrides/_batch_create_form_horizontal_record.html.erb +11 -26
  11. data/app/views/active_scaffold_overrides/_batch_create_form_multiple.html.erb +1 -1
  12. data/app/views/active_scaffold_overrides/_batch_create_form_vertical.html.erb +12 -3
  13. data/app/views/active_scaffold_overrides/_batch_create_form_vertical_record.html.erb +5 -5
  14. data/app/views/active_scaffold_overrides/_batch_update_form.html.erb +6 -6
  15. data/app/views/active_scaffold_overrides/_batch_update_form_attribute.html.erb +1 -11
  16. data/app/views/active_scaffold_overrides/_batch_update_form_attribute_scope.html.erb +7 -12
  17. data/app/views/active_scaffold_overrides/_batch_update_form_body.html.erb +24 -23
  18. data/app/views/active_scaffold_overrides/_form_messages.html.erb +16 -4
  19. data/app/views/active_scaffold_overrides/batch_add.js.erb +16 -3
  20. data/app/views/active_scaffold_overrides/batch_create.html.erb +1 -1
  21. data/app/views/active_scaffold_overrides/batch_update.html.erb +1 -1
  22. data/app/views/active_scaffold_overrides/on_batch_base.js.erb +14 -4
  23. data/app/views/active_scaffold_overrides/on_batch_create.js.erb +10 -5
  24. data/app/views/active_scaffold_overrides/on_batch_update.js.erb +6 -4
  25. data/config/locales/de.yml +2 -1
  26. data/config/locales/en.yml +2 -1
  27. data/config/locales/es.yml +2 -1
  28. data/lib/active_scaffold/actions/batch_base.rb +23 -28
  29. data/lib/active_scaffold/actions/batch_create.rb +78 -44
  30. data/lib/active_scaffold/actions/batch_destroy.rb +16 -15
  31. data/lib/active_scaffold/actions/batch_update.rb +129 -104
  32. data/lib/active_scaffold/config/batch_create.rb +17 -19
  33. data/lib/active_scaffold/config/batch_destroy.rb +24 -14
  34. data/lib/active_scaffold/config/batch_update.rb +21 -20
  35. data/lib/active_scaffold/helpers/batch_create_column_helpers.rb +17 -18
  36. data/lib/active_scaffold/helpers/datepicker_update_column_helpers.rb +48 -17
  37. data/lib/active_scaffold/helpers/update_column_helpers.rb +91 -33
  38. data/lib/active_scaffold_batch/engine.rb +10 -12
  39. data/lib/active_scaffold_batch/extensions.rb +16 -0
  40. data/lib/active_scaffold_batch/version.rb +4 -2
  41. data/lib/active_scaffold_batch.rb +5 -15
  42. metadata +7 -5
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4dcf0ccf9b1cef674df1dd5825858b46d601a57e028670925e381f589ab02d65
4
- data.tar.gz: 04e4c10f0cc4abed7e4023dd317bc2995a15e25bba6a94851bb4a8b928cfa03e
3
+ metadata.gz: a1e1ce7c79235a8e002895fd16c2e61dfd2f9446bdae44dd8b8911b3e3476b1f
4
+ data.tar.gz: d2c9a00ae21cb124dc52eca08773a0731d024b2ee164344eb1f4d403c4f82b12
5
5
  SHA512:
6
- metadata.gz: ea894c83e3b5a0b65b2b654f2cfc2b6afbf3658d96d062513c7ad79db3f4adf10462bd3f93775b0884965553469131b3ed600fedf87eb492f28ace5af1988055
7
- data.tar.gz: 250d0794c5b6193a44fffcec5061041fd12d89bec343dd1d1c3d120f105e5442f9add00f68707bc383fc3e987bc072159ec23061eb8a6d7ac38f10fb85b0df11
6
+ metadata.gz: ddbcd3f617626824a33eb523aa7b84b88f2db4be98163694b8c42c98496f930f3ef077105e5b868e805b6a7dd1d0a7bf17c94efcb9cc3fa136a0124ea2a096ee
7
+ data.tar.gz: 52939666dbfa33f70637eb77d2ee0b2344de7130609e3957c8e2b5bbb2f135b6119a36a6d2238295519b9d6d747216e883103be468de270293a3527252be7113
data/README CHANGED
@@ -1,12 +1,108 @@
1
- ActiveScaffold batch is a gem which adds batch_update, batch_create and batch_destroy actions to ActiveScaffold, which means you can perform operations on more than just one record.
1
+ # ActiveScaffold Batch
2
2
 
3
+ ActiveScaffold Batch adds actions for creating, updating, and deleting multiple records from an ActiveScaffold list.
4
+
5
+ ## Requirements
6
+
7
+ The upcoming 3.8 release requires ActiveScaffold 4.4 or newer. Use ActiveScaffold Batch 3.7.x with older ActiveScaffold releases.
8
+
9
+ ## Installation
10
+
11
+ Add the gem to your `Gemfile`:
12
+
13
+ ```ruby
3
14
  gem 'active_scaffold_batch'
15
+ ```
4
16
 
5
- It works with ActiveScaffold >= 3.4.18 and rails >= 4.0.
6
- Use 3.3.x for rails 3.2.x.
17
+ Then run `bundle install`.
7
18
 
8
- In the config block of an activescaffold you can add any of the following lines:
19
+ ## Enable actions
9
20
 
10
- config.actions.add :batch_create
21
+ Enable only the actions an application needs:
22
+
23
+ ```ruby
24
+ class UsersController < ApplicationController
25
+ active_scaffold :user do |config|
11
26
  config.actions.add :batch_update
12
27
  config.actions.add :batch_destroy
28
+ end
29
+ end
30
+ ```
31
+
32
+ The plugin provides `batch_create`, `batch_update`, and `batch_destroy`. Batch Update and Batch Destroy can operate on every record in the current filtered list. When the `mark` action is enabled, they can also operate only on marked records.
33
+
34
+ ## Batch Create
35
+
36
+ Batch Create has two distinct modes.
37
+
38
+ With no `default_batch_by_column`, it is a multiple-row create form. It initially displays one new record and lets the user add more blank rows before submitting them together:
39
+
40
+ ```ruby
41
+ config.actions.add :batch_create
42
+ config.batch_create.layout = :vertical # or :horizontal
43
+ ```
44
+
45
+ With `default_batch_by_column`, one form is applied once for every selected value of that column. For example, the following configuration creates one player for each selected team while sharing the other entered player attributes:
46
+
47
+ ```ruby
48
+ config.actions.add :batch_create
49
+ config.batch_create.default_batch_by_column = :team
50
+ ```
51
+
52
+ The batch column may be a `belongs_to` association or a scalar column. For a scalar column, enter one value per line.
53
+
54
+ By default, Batch Create validates and saves all records in one transaction and rolls everything back when any record fails. The supported settings are:
55
+
56
+ ```ruby
57
+ config.batch_create.run_in_transaction = true
58
+ config.batch_create.layout = :vertical
59
+ config.batch_create.list_mode_enabled = true
60
+ ```
61
+
62
+ Set `run_in_transaction` to `false` to retain successful records when another row fails, or to `:validate_first` to validate every record before saving any of them.
63
+
64
+ ## Batch Update
65
+
66
+ Batch Update presents an operator for each editable column. `NO_UPDATE` leaves the column unchanged and `REPLACE` assigns the entered value. Numeric columns also support addition, subtraction, multiplication, and division with absolute or percentage operands. Date columns support addition and subtraction.
67
+
68
+ ```ruby
69
+ config.actions.add :batch_update
70
+ config.batch_update.list_mode_enabled = true
71
+ config.batch_update.process_mode = :update
72
+ ```
73
+
74
+ The default `:update` mode instantiates every record and runs authorization, validations, and callbacks. `:update_all` performs direct SQL updates and skips those model callbacks and validations.
75
+
76
+ ## Batch Destroy
77
+
78
+ ```ruby
79
+ config.actions.add :batch_destroy
80
+ config.batch_destroy.process_mode = :delete
81
+ ```
82
+
83
+ The default `:delete` mode processes records individually through ActiveScaffold. `:delete_all` uses direct SQL and skips model callbacks. Both modes expose separate links for the current filtered list and, when marking is enabled, marked records.
84
+
85
+ ## UI adapter support
86
+
87
+ Version 3.8 reuses ActiveScaffold 4.4's standard form elements. Refer to ActiveScaffold's UI element reference for `form`, `form_title`, `fields_container`, `form_element`, `form_attribute`, `form_control`, form footer controls, and the other shared elements.
88
+
89
+ Batch defines only one plugin-specific element:
90
+
91
+ | Element | Type | Used for |
92
+ |---|---|---|
93
+ | `batch_create_add_rows` | Attributes only | Remote link that adds blank rows to a multiple-row Batch Create form. |
94
+
95
+ For example, an adapter can customize the Batch-specific add-row link without replacing its template:
96
+
97
+ ```ruby
98
+ ActiveScaffold.add_element_attributes :batch_create_add_rows,
99
+ class: 'btn btn-sm btn-secondary'
100
+ ```
101
+
102
+ Batch-specific inputs use the shared `form_control` element. Its proc receives the usual `column` and `form_ui` context plus `batch_role`, which identifies `batch_scope`, `batch_update_operator`, `batch_update_value`, `batch_update_numeric_option`, `batch_update_date_amount`, `batch_update_date_unit`, or `batch_create_row_count`. This lets an adapter distinguish the controls when necessary without adding a separate registry element for each one.
103
+
104
+ The shared elements use the same definitions as ActiveScaffold's ordinary forms, so one adapter configuration keeps core and Batch forms consistent.
105
+
106
+ ## Safety
107
+
108
+ List-scoped actions affect the complete filtered result, not only the visible page. Prefer marked-record scope for destructive operations when the user should explicitly select every affected record. Use the per-record processing modes when callbacks, validations, or authorization checks are required.
@@ -4,16 +4,16 @@ jQuery(document).ready(function() {
4
4
  if (num_records) settings.url += (settings.url.indexOf('?') != -1 ? '&' : '?') + 'num_records=' + num_records;
5
5
  return true;
6
6
  });
7
- jQuery(document).on('click', '.multiple .form_record a.remove', function(event) {
8
- event.preventDefault();
9
- var record = jQuery(this).closest('.form_record');
10
- record.prev('.form_record-errors').remove();
11
- record.remove();
7
+ jQuery(document).on('change', '.as_update_date_operator, .as_batch_update_operator, .as_update_numeric_option', function(event) {
8
+ var $op = jQuery(this), method,
9
+ fields = $op.closest('.form-element').find(':input, .mceEditor + div').not(this).filter(function() {
10
+ return jQuery(this).closest('.search-date-trend').length === 0;
11
+ });
12
+ if ($op.is('.as_update_date_operator')) method = $op.val() === 'REPLACE' ? 'show' : 'hide';
13
+ else method = ['NO_UPDATE', 'NULL'].indexOf(jQuery(this).val()) !== -1 ? 'hide' : 'show';
14
+ ActiveScaffold[method](fields);
12
15
  });
13
- jQuery(document).on('change', 'select.as_update_date_operator, select.as_batch_update_operator', function(event) {
14
- ActiveScaffold[jQuery(this).val() === 'REPLACE' ? 'show' : 'hide'](jQuery(this).next());
15
- });
16
- jQuery(document).on('change', 'select.as_update_date_operator', function(event) {
17
- ActiveScaffold[['REPLACE', 'NO_UPDATE', 'NULL'].indexOf(jQuery(this).val()) !== -1 ? 'hide' : 'show'](jQuery(this).next().next());
16
+ jQuery(document).on('change', '.as_update_date_operator', function(event) {
17
+ ActiveScaffold[['REPLACE', 'NO_UPDATE', 'NULL'].indexOf(jQuery(this).val()) !== -1 ? 'hide' : 'show'](jQuery(this).closest('.form-element').find('.search-date-trend'));
18
18
  });
19
19
  });
@@ -1,23 +1,14 @@
1
- .active-scaffold .multiple .form_record .errorExplanation {
1
+ .active-scaffold .multiple .sub-form-record .errorExplanation {
2
2
  clear: left;
3
3
  margin-top: 10px;
4
4
  }
5
- .active-scaffold .multiple .form_record {
5
+ .active-scaffold .multiple .sub-form-record {
6
6
  border-top: 1px solid #7FCF00;
7
7
  }
8
- .active-scaffold .multiple .form_record:first-child {
8
+ .active-scaffold .multiple thead + .sub-form-record,
9
+ .active-scaffold .multiple .sub-form-record:first-child {
9
10
  border-top: 0;
10
11
  }
11
- .active-scaffold .multiple .form_record a.remove {
12
- background-image: image-url("active_scaffold/cross.png");
13
- display: block;
14
- font-weight: bold;
15
- height: 16px;
16
- padding: 0;
17
- text-indent: -4000px;
18
- width: 16px;
19
- margin: 0 5px 10px;
20
- }
21
12
  .batch-create-rows {
22
13
  float: right;
23
14
  }
@@ -1,9 +1,9 @@
1
- <%= render :partial => "base_form", :locals => {:xhr => xhr ||= nil,
2
- :form_action => form_action ||= :batch_create,
3
- :method => method ||= :post,
4
- :cancel_link => cancel_link ||= true,
5
- :body_partial => batch_create_by_column ? 'batch_create_form_body' : 'batch_create_form_multiple',
6
- :footer_extension => ('batch_create_form_footer' unless batch_create_by_column),
7
- :scope => @scope,
8
- :headline => headline ||= active_scaffold_config.batch_create.label} %>
1
+ <%= render 'base_form', {xhr: local_assigns.fetch(:xhr, nil),
2
+ form_action: local_assigns.fetch(:form_action, :batch_create),
3
+ method: local_assigns.fetch(:method, :post),
4
+ cancel_link: local_assigns.fetch(:cancel_link, true),
5
+ body_partial: batch_create_by_column ? 'batch_create_form_body' : 'batch_create_form_multiple',
6
+ footer_extension: ('batch_create_form_footer' unless batch_create_by_column),
7
+ scope: @scope,
8
+ headline: local_assigns.fetch(:headline, active_scaffold_config.batch_create.label)} %>
9
9
 
@@ -1,19 +1,7 @@
1
- <% scope ||= nil %>
2
- <dl>
3
- <dt>
4
- <label for="<%= (options = active_scaffold_input_options(column, scope, :object => record))[:id] %>"><%= column.label %></label>
5
- </dt>
6
- <dd>
7
- <% if column == batch_create_by_column.to_sym %>
8
- <%= active_scaffold_batch_create_by_column column, scope, :object => record %>
9
- <% else %>
10
- <%= active_scaffold_input_for column, scope, options %>
11
- <% if column.update_columns -%>
12
- <%= loading_indicator_tag(:action => :render_field, :id => params[:id]) %>
13
- <% end -%>
14
- <% end %>
15
- <% if column.description -%>
16
- <span class="description"><%= column.description %></span>
17
- <% end -%>
18
- </dd>
19
- </dl>
1
+ <%
2
+ scope ||= nil
3
+ if column == batch_create_by_column.to_sym
4
+ field = active_scaffold_batch_create_by_column column, scope, object: record
5
+ end
6
+ %>
7
+ <%= form_attribute(column, record, scope, field: field) %>
@@ -1,25 +1,26 @@
1
- <% subsection_id ||= nil %>
2
- <ol class="form" <%= "id=#{subsection_id}" unless subsection_id.nil? %> <%= 'style="display: none;"' if columns.collapsed -%>>
3
- <li class="form-element">
4
- <%= hidden_field_tag("batch_scope", (batch_scope || 'LISTED')) %>
5
- </li>
1
+ <%
2
+ ol_attrs = {}
3
+ ol_attrs[:id] = subsection_id unless local_assigns[:subsection_id].nil?
4
+ ol_attrs[:style] = 'display: none;' if columns.collapsed
5
+ %>
6
+ <%= as_element :fields_container, class: 'form', **ol_attrs do %>
7
+ <%= as_element :form_element, hidden_field_tag('batch_scope', batch_scope || 'LISTED') %>
8
+
6
9
  <% columns.each_column(for: @record) do |column| %>
7
- <% next unless column.association.nil? || column.association.belongs_to? %>
8
- <% renders_as = column_renders_as(column) %>
9
- <% if renders_as == :subsection -%>
10
- <% subsection_id = sub_section_id(:sub_section => column.label) %>
11
- <li class="sub-section">
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}) -%>
15
- </li>
16
- <% elsif column.association.try(:readonly?)
17
- next %>
18
- <% else
19
- renders_as = :field if renders_as == :subform -%>
20
- <li class="form-element <%= column.css_class unless column.css_class.nil? %>">
21
- <%= render :partial => 'batch_create_form_attribute', :locals => { :column => column, :record => @record } -%>
22
- </li>
10
+ <% next unless column.association.nil? || column.association.belongs_to? %>
11
+
12
+ <% column_css_class = column.css_class unless column.css_class.is_a?(Proc) %>
13
+ <% renders_as = column_renders_as(column) %>
14
+ <% if renders_as == :subsection -%>
15
+ <%= as_element :form_subsection, class: column_css_class do %>
16
+ <%= render_subsection(column, @record, scope, form_action) %>
17
+ <% end %>
18
+ <% elsif column.association.try(:readonly?) %>
19
+ <% next %>
20
+ <% else %>
21
+ <%= as_element :form_element, class: "form-element #{column_css_class}" do %>
22
+ <%= render 'batch_create_form_attribute', column: column, record: @record %>
23
+ <% end -%>
24
+ <% end -%>
23
25
  <% end -%>
24
- <% end -%>
25
- </ol>
26
+ <% end %>
@@ -1,4 +1,13 @@
1
1
  <span class='batch-create-rows'>
2
- <%= as_(:add_some_records, :model => active_scaffold_config.label(:count => 2), :number_input => text_field_tag(:num_records, 1, :id => nil)).html_safe %>
3
- <%= link_to as_(:add), params_for(:action => :batch_add), :remote => true %>
2
+ <%
3
+ number_attributes = active_scaffold_batch_control_attributes(nil, :number, :batch_create_row_count, id: nil)
4
+ number_input = text_field_tag(:num_records, 1, active_scaffold_input_text_options(number_attributes))
5
+ add_records_text = as_(
6
+ :add_some_records,
7
+ model: active_scaffold_config.label(count: 2),
8
+ number_input: number_input
9
+ )
10
+ %>
11
+ <%= add_records_text %>
12
+ <%= link_to as_(:add), params_for(action: :batch_add), as_element_attributes(:batch_create_add_rows, remote: true) %>
4
13
  </span>
@@ -1,13 +1,28 @@
1
1
  <div class="form sub-form horizontal-sub-form">
2
- <table cellpadding="0" cellspacing="0">
3
- <%= render :partial => 'batch_create_form_horizontal_header', :locals => {:columns => columns, :record => records.first} %>
2
+ <table cellpadding="0" cellspacing="0" id="<%= element_form_id action: form_action %>-content" class="multiple">
3
+ <%
4
+ header_locals = {
5
+ columns: columns,
6
+ scope: nil,
7
+ record_class: records.values.first.class,
8
+ crud_type: columns.action.crud_type,
9
+ parent_record: nil,
10
+ parent_column: nil
11
+ }
12
+ %>
13
+ <%= render 'horizontal_subform_header', header_locals %>
4
14
 
5
- <tbody id="<%= element_form_id :action => form_action %>-content" class="multiple">
6
- <% first = true -%>
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 } %>
9
- <% first = false -%>
10
- <% end -%>
11
- </tbody>
15
+ <% records.each.with_index do |(scope, record), index| %>
16
+ <%
17
+ record_locals = {
18
+ columns: columns,
19
+ form_action: form_action,
20
+ scope: "[#{scope}]",
21
+ first: index.zero?,
22
+ record: record
23
+ }
24
+ %>
25
+ <%= render 'batch_create_form_horizontal_record', record_locals %>
26
+ <% end -%>
12
27
  </table>
13
28
  </div>
@@ -1,27 +1,12 @@
1
- <% first = true unless local_assigns.has_key? :first -%>
2
- <% if record.errors.count -%>
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 %>
6
- </td>
7
- </tr>
8
- <% end %>
9
- <tr class="form_record">
10
- <% columns.each_column(flatten: true) do |column| -%>
11
1
  <%
12
- renders_as = column_renders_as(column)
13
- next if renders_as == :hidden
14
- next unless record.authorized_for?(:crud_type => :create, :column => column.name)
15
- column = column.clone
16
- column.form_ui ||= :select if column.association
17
-
18
- col_class = []
19
- col_class << 'required' if column.required?
20
- col_class << column.css_class unless column.css_class.nil?
21
- -%>
22
- <td class="<%= col_class.join(' ') %>">
23
- <%= render_column(column, record, renders_as, scope) %>
24
- </td>
25
- <% end -%>
26
- <td><%= batch_create_multiple_remove_link unless first %></td>
27
- </tr>
2
+ association_locals = {
3
+ scope: scope,
4
+ column: nil,
5
+ parent_record: nil,
6
+ columns: columns,
7
+ layout: :horizontal,
8
+ locked: first,
9
+ record: record
10
+ }
11
+ %>
12
+ <%= render 'form_association_record', association_locals %>
@@ -5,4 +5,4 @@
5
5
  {scope => @record}
6
6
  end
7
7
  -%>
8
- <%= render :partial => batch_create_multiple_layout, :locals => { :columns => columns, :form_action => form_action, :records => records } %>
8
+ <%= render batch_create_multiple_layout, columns: columns, form_action: form_action, records: records %>
@@ -1,12 +1,21 @@
1
- <div id="<%= element_form_id :action => form_action %>-content" class="multiple">
1
+ <div id="<%= element_form_id action: form_action %>-content" class="multiple">
2
2
  <%
3
3
  first = true
4
4
  original_record = @record
5
5
  -%>
6
6
  <% records.each do |scope, record| -%>
7
7
  <% @record = record %>
8
- <%= render :partial => 'batch_create_form_vertical_record', :locals => { :columns => columns, :form_action => form_action, :scope => "[#{scope}]", :first => first, :record => record } %>
8
+ <%
9
+ record_locals = {
10
+ columns: columns,
11
+ form_action: form_action,
12
+ scope: "[#{scope}]",
13
+ first: first,
14
+ record: record
15
+ }
16
+ %>
17
+ <%= render 'batch_create_form_vertical_record', record_locals %>
9
18
  <% first = false -%>
10
19
  <% end -%>
11
20
  </div>
12
- <% @record = original_record %>
21
+ <% @record = original_record %>
@@ -1,6 +1,6 @@
1
- <% first = true unless local_assigns.has_key? :first -%>
2
- <div class="form_record">
3
- <%= render :partial => 'form_messages' %>
4
- <%= render :partial => 'form', :locals => { :columns => columns, :form_action => form_action, :scope => scope } %>
5
- <%= batch_create_multiple_remove_link unless first %>
1
+ <% first = true unless local_assigns.key? :first -%>
2
+ <div class="sub-form-record">
3
+ <%= render 'form_messages' %>
4
+ <%= render 'form', {columns: columns, form_action: form_action, scope: scope} %>
5
+ <%= link_to(as_(:remove), '#', as_element_attributes(:subform_record_remove, class: 'destroy')) unless first %>
6
6
  </div>
@@ -1,7 +1,7 @@
1
- <%= render :partial => "base_form", :locals => {:xhr => xhr ||= nil,
2
- :form_action => form_action ||= :batch_update,
3
- :method => method ||= :post,
4
- :cancel_link => cancel_link ||= true,
5
- :body_partial => 'batch_update_form_body',
6
- :headline => headline ||= active_scaffold_config.batch_update.label} %>
1
+ <%= render 'base_form', {xhr: local_assigns.fetch(:xhr, nil),
2
+ form_action: local_assigns.fetch(:form_action, :batch_update),
3
+ method: local_assigns.fetch(:method, :post),
4
+ cancel_link: local_assigns.fetch(:cancel_link, true),
5
+ body_partial: 'batch_update_form_body',
6
+ headline: local_assigns.fetch(:headline, active_scaffold_config.batch_update.label)} %>
7
7
 
@@ -1,12 +1,2 @@
1
1
  <% scope ||= nil %>
2
- <dl>
3
- <dt>
4
- <label for="<%= active_scaffold_input_options(column, scope)[:id] %>"><%= column.label %></label>
5
- </dt>
6
- <dd>
7
- <%= active_scaffold_update_for column, scope, :object => record %>
8
- <% if column.description -%>
9
- <span class="description"><%= column.description %></span>
10
- <% end -%>
11
- </dd>
12
- </dl>
2
+ <%= form_attribute(column, record, scope, field: active_scaffold_update_for(column, scope, object: record)) %>
@@ -1,14 +1,9 @@
1
- <% scope ||= nil
2
- scope_select_options = active_scaffold_update_scope_select_options %>
3
- <% if scope_select_options.length < 2 %>
4
- <%= active_scaffold_update_scope_select(scope_select_options) %>
1
+ <%
2
+ scope_select_options = active_scaffold_update_scope_select_options
3
+ field = active_scaffold_update_scope_select(scope_select_options)
4
+ %>
5
+ <% if active_scaffold_update_scope_select_hidden? %>
6
+ <%= field %>
5
7
  <% else %>
6
- <dl>
7
- <dt>
8
- <label for="record_batch_scope"><%= as_(:records) %></label>
9
- </dt>
10
- <dd>
11
- <%= active_scaffold_update_scope_select(scope_select_options) %>
12
- </dd>
13
- </dl>
8
+ <%= form_attribute_html(nil, label_tag('record_batch_scope', as_(:records)), field, nil, {}) %>
14
9
  <% end %>
@@ -1,25 +1,26 @@
1
- <% subsection_id ||= nil %>
2
- <ol class="form" <%= "id=#{subsection_id}" unless subsection_id.nil? %> <%= 'style="display: none;"' if columns.collapsed -%>>
3
- <li class="form-element">
4
- <%= render :partial => 'batch_update_form_attribute_scope' -%>
5
- </li>
1
+ <%
2
+ ol_attrs = {}
3
+ ol_attrs[:id] = subsection_id unless local_assigns[:subsection_id].nil?
4
+ ol_attrs[:style] = 'display: none;' if columns.collapsed
5
+ %>
6
+ <%= as_element :fields_container, class: 'form', **ol_attrs do %>
7
+ <%= as_element :form_element, render('batch_update_form_attribute_scope'), class: 'form-element' %>
8
+
6
9
  <% columns.each_column(for: @record) do |column| %>
7
- <% next unless column.association.nil? || column.association.belongs_to? %>
8
- <% renders_as = column_renders_as(column) %>
9
- <% if renders_as == :subsection -%>
10
- <% subsection_id = sub_section_id(:sub_section => column.label) %>
11
- <li class="sub-section">
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) -%>
15
- </li>
16
- <% elsif column.association.try(:readonly?)
17
- next %>
18
- <% else
19
- renders_as = :field if renders_as == :subform -%>
20
- <li class="form-element <%= column.css_class unless column.css_class.nil? %>">
21
- <%= render :partial => 'batch_update_form_attribute', :locals => { :column => column, :record => @record } -%>
22
- </li>
10
+ <% next unless column.association.nil? || column.association.belongs_to? %>
11
+
12
+ <% column_css_class = column.css_class unless column.css_class.is_a?(Proc) %>
13
+ <% renders_as = column_renders_as(column) %>
14
+ <% if renders_as == :subsection -%>
15
+ <%= as_element :form_subsection, class: column_css_class do %>
16
+ <%= render_subsection(column, @record, scope, form_action) %>
17
+ <% end %>
18
+ <% elsif column.association.try(:readonly?) %>
19
+ <% next %>
20
+ <% else %>
21
+ <%= as_element :form_element, class: "form-element #{column_css_class}" do %>
22
+ <%= render 'batch_update_form_attribute', column: column, record: @record %>
23
+ <% end -%>
24
+ <% end -%>
23
25
  <% end -%>
24
- <% end -%>
25
- </ol>
26
+ <% end %>
@@ -1,10 +1,22 @@
1
1
  <% if @error_records.present? && @error_records.is_a?(Array) -%>
2
- <%= render :partial => 'messages' unless request.xhr? %>
2
+ <%= render 'messages' unless request.xhr? %>
3
3
 
4
- <% id_column = active_scaffold_config.model.human_attribute_name(batch_create_by_column) if batch_create_by_column && active_scaffold_config.columns[batch_create_by_column].association.nil? %>
4
+ <%
5
+ if batch_create_by_column && active_scaffold_config.columns[batch_create_by_column].association.nil?
6
+ id_column = active_scaffold_config.model.human_attribute_name(batch_create_by_column)
7
+ end
8
+ %>
5
9
  <% @error_records.each do |record| %>
6
- <% record_title = record.new_record? ? (id_column ? "(#{id_column} #{record.send(batch_create_by_column)})" : '') : record.to_label %>
7
- <%= active_scaffold_error_messages_for record, :object_name => "#{record.class.model_name.human.downcase} #{record_title}" %>
10
+ <%
11
+ record_title =
12
+ if record.new_record?
13
+ id_column ? "(#{id_column} #{record.send(batch_create_by_column)})" : ''
14
+ else
15
+ record.to_label
16
+ end
17
+ object_name = "#{record.class.model_name.human.downcase} #{record_title}"
18
+ %>
19
+ <%= active_scaffold_error_messages_for record, object_name: object_name %>
8
20
  <% end %>
9
21
  <% else %>
10
22
  <%= render :super %>
@@ -1,5 +1,18 @@
1
- <% html = ''.html_safe -%>
1
+ <% rows = [] -%>
2
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 }) %>
3
+ <%
4
+ record_locals = {
5
+ columns: active_scaffold_config.batch_create.columns,
6
+ form_action: :batch_create,
7
+ scope: "[#{scope}]",
8
+ first: false,
9
+ record: record
10
+ }
11
+ rows << render("#{batch_create_multiple_layout}_record", record_locals)
12
+ %>
4
13
  <% end %>
5
- ActiveScaffold.create_associated_record_form('<%= element_form_id(:action => :batch_create) %>-content','<%= escape_javascript(html) %>', <%= {:singular => false}.to_json.html_safe %>);
14
+ ActiveScaffold.create_associated_record_form(
15
+ '<%= element_form_id(action: :batch_create) %>-content',
16
+ '<%= escape_javascript(safe_join(rows)) %>',
17
+ {singular: false}
18
+ );
@@ -1,5 +1,5 @@
1
1
  <div class="active-scaffold">
2
2
  <div class="batch-create-view <%= "#{params[:controller]}-view" %> view">
3
- <%= render :partial => 'batch_create_form' -%>
3
+ <%= render 'batch_create_form' -%>
4
4
  </div>
5
5
  </div>
@@ -1,5 +1,5 @@
1
1
  <div class="active-scaffold">
2
2
  <div class="batch-update-view <%= "#{params[:controller]}-view" %> view">
3
- <%= render :partial => 'batch_update_form' -%>
3
+ <%= render 'batch_update_form' -%>
4
4
  </div>
5
5
  </div>
@@ -2,9 +2,19 @@
2
2
  if @error_records.empty?
3
3
  flash[:info] = as_(:batch_processing_successful) if flash[:info].blank?
4
4
  else
5
- flash[:error] = @error_records.collect do |_, record|
6
- 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)
7
- end.join.html_safe
5
+ messages = @error_records.collect do |_, record|
6
+ record_name = record.class.model_name.human.downcase
7
+ record_name += ": #{record.to_label}" unless record.new_record?
8
+ active_scaffold_error_messages_for(
9
+ record,
10
+ object_name: record_name,
11
+ header_message: '',
12
+ message: record_name,
13
+ container_tag: nil,
14
+ list_type: :br
15
+ )
16
+ end
17
+ flash[:error] = safe_join(messages)
8
18
  end
9
19
  %>
10
- ActiveScaffold.replace_html('<%= active_scaffold_content_id%>','<%=escape_javascript(render(:partial => 'list', :layout => false))%>');
20
+ ActiveScaffold.replace_html('<%= active_scaffold_content_id%>', '<%=escape_javascript(render('list'))%>');