active_scaffold_batch 3.7.3 → 3.8.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.
- checksums.yaml +4 -4
- data/README +101 -5
- data/app/assets/javascripts/active_scaffold_batch.js +10 -10
- data/app/assets/stylesshets/active_scaffold_batch.scss +4 -13
- data/app/views/active_scaffold_overrides/_batch_create_form.html.erb +8 -8
- data/app/views/active_scaffold_overrides/_batch_create_form_attribute.html.erb +7 -19
- data/app/views/active_scaffold_overrides/_batch_create_form_body.html.erb +24 -23
- data/app/views/active_scaffold_overrides/_batch_create_form_footer.html.erb +6 -2
- data/app/views/active_scaffold_overrides/_batch_create_form_horizontal.html.erb +5 -9
- data/app/views/active_scaffold_overrides/_batch_create_form_horizontal_record.html.erb +1 -27
- data/app/views/active_scaffold_overrides/_batch_create_form_multiple.html.erb +1 -1
- data/app/views/active_scaffold_overrides/_batch_create_form_vertical.html.erb +2 -2
- data/app/views/active_scaffold_overrides/_batch_create_form_vertical_record.html.erb +5 -5
- data/app/views/active_scaffold_overrides/_batch_update_form.html.erb +6 -6
- data/app/views/active_scaffold_overrides/_batch_update_form_attribute.html.erb +1 -11
- data/app/views/active_scaffold_overrides/_batch_update_form_attribute_scope.html.erb +7 -12
- data/app/views/active_scaffold_overrides/_batch_update_form_body.html.erb +24 -23
- data/app/views/active_scaffold_overrides/_form_messages.html.erb +2 -2
- data/app/views/active_scaffold_overrides/batch_add.js.erb +2 -2
- data/app/views/active_scaffold_overrides/batch_create.html.erb +1 -1
- data/app/views/active_scaffold_overrides/batch_update.html.erb +1 -1
- data/app/views/active_scaffold_overrides/on_batch_base.js.erb +2 -2
- data/app/views/active_scaffold_overrides/on_batch_create.js.erb +5 -5
- data/app/views/active_scaffold_overrides/on_batch_update.js.erb +4 -4
- data/lib/active_scaffold/actions/batch_base.rb +6 -14
- data/lib/active_scaffold/actions/batch_create.rb +10 -10
- data/lib/active_scaffold/actions/batch_destroy.rb +2 -2
- data/lib/active_scaffold/actions/batch_update.rb +10 -10
- data/lib/active_scaffold/config/batch_create.rb +3 -3
- data/lib/active_scaffold/config/batch_destroy.rb +2 -2
- data/lib/active_scaffold/config/batch_update.rb +3 -3
- data/lib/active_scaffold/helpers/batch_create_column_helpers.rb +4 -14
- data/lib/active_scaffold/helpers/datepicker_update_column_helpers.rb +32 -9
- data/lib/active_scaffold/helpers/update_column_helpers.rb +50 -16
- data/lib/active_scaffold_batch/engine.rb +1 -1
- data/lib/active_scaffold_batch/version.rb +2 -2
- data/lib/active_scaffold_batch.rb +1 -0
- metadata +3 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 0cd0607f90b8564989b6b045ad113aba536de9dd1bcc3666530844ac6c50ae05
|
|
4
|
+
data.tar.gz: 59f831ce5ea56dbb9d1164b9d65aaa057681535e5f3bcb20573a4b95f387310a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 7d0c431c67074d94a293058fe354bcfd509ce5777b3a9ee6aea3b97a15be7c09aaa2ae45dd38b81accf4ccb81645a51fd270a54ed5032289eabc4157f77a1551
|
|
7
|
+
data.tar.gz: 27eec227ee3c75aae239d97af1c9444b32f64924ac2c6133b724081cacf22ade956dcf6d3b621dc462135fc3fbaf7ed4f53d9badbed24e8a240b51cefaec5f6a
|
data/README
CHANGED
|
@@ -1,12 +1,108 @@
|
|
|
1
|
-
|
|
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
|
-
|
|
6
|
-
Use 3.3.x for rails 3.2.x.
|
|
17
|
+
Then run `bundle install`.
|
|
7
18
|
|
|
8
|
-
|
|
19
|
+
## Enable actions
|
|
9
20
|
|
|
10
|
-
|
|
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('
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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', '
|
|
14
|
-
ActiveScaffold[jQuery(this).val()
|
|
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 .
|
|
1
|
+
.active-scaffold .multiple .sub-form-record .errorExplanation {
|
|
2
2
|
clear: left;
|
|
3
3
|
margin-top: 10px;
|
|
4
4
|
}
|
|
5
|
-
.active-scaffold .multiple .
|
|
5
|
+
.active-scaffold .multiple .sub-form-record {
|
|
6
6
|
border-top: 1px solid #7FCF00;
|
|
7
7
|
}
|
|
8
|
-
.active-scaffold .multiple .
|
|
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
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
<%= render 'base_form', {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} %>
|
|
9
9
|
|
|
@@ -1,19 +1,7 @@
|
|
|
1
|
-
<%
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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
|
-
<%
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
<%
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
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
|
-
|
|
25
|
-
</ol>
|
|
26
|
+
<% end %>
|
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
<span class='batch-create-rows'>
|
|
2
|
-
|
|
3
|
-
|
|
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
|
+
%>
|
|
6
|
+
<%= as_(:add_some_records, model: active_scaffold_config.label(count: 2), number_input: number_input).html_safe %>
|
|
7
|
+
<%= link_to as_(:add), params_for(action: :batch_add), as_element_attributes(:batch_create_add_rows, remote: true) %>
|
|
4
8
|
</span>
|
|
@@ -1,13 +1,9 @@
|
|
|
1
1
|
<div class="form sub-form horizontal-sub-form">
|
|
2
|
-
<table cellpadding="0" cellspacing="0">
|
|
3
|
-
<%= render :
|
|
2
|
+
<table cellpadding="0" cellspacing="0" id="<%= element_form_id action: form_action %>-content" class="multiple">
|
|
3
|
+
<%= render 'horizontal_subform_header', {columns: columns, scope: nil, record_class: records.values.first.class, crud_type: columns.action.crud_type, parent_record: nil, parent_column: nil} %>
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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>
|
|
5
|
+
<% records.each.with_index do |(scope, record), index| %>
|
|
6
|
+
<%= render 'batch_create_form_horizontal_record', {columns: columns, form_action: form_action, scope: "[#{scope}]", first: index == 0, record: record} %>
|
|
7
|
+
<% end -%>
|
|
12
8
|
</table>
|
|
13
9
|
</div>
|
|
@@ -1,27 +1 @@
|
|
|
1
|
-
|
|
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
|
-
<%
|
|
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>
|
|
1
|
+
<%= render 'form_association_record', scope: scope, column: nil, parent_record: nil, columns: columns, layout: :horizontal, locked: first, record: record %>
|
|
@@ -5,4 +5,4 @@
|
|
|
5
5
|
{scope => @record}
|
|
6
6
|
end
|
|
7
7
|
-%>
|
|
8
|
-
<%= render
|
|
8
|
+
<%= render batch_create_multiple_layout, columns: columns, form_action: form_action, records: records %>
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
<div id="<%= element_form_id :
|
|
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
|
|
8
|
+
<%= render 'batch_create_form_vertical_record', {columns: columns, form_action: form_action, scope: "[#{scope}]", first: first, record: record} %>
|
|
9
9
|
<% first = false -%>
|
|
10
10
|
<% end -%>
|
|
11
11
|
</div>
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
<% first = true unless local_assigns.
|
|
2
|
-
<div class="
|
|
3
|
-
<%= render
|
|
4
|
-
<%= render
|
|
5
|
-
<%=
|
|
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
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
<%= render 'base_form', {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} %>
|
|
7
7
|
|
|
@@ -1,12 +1,2 @@
|
|
|
1
1
|
<% scope ||= nil %>
|
|
2
|
-
|
|
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
|
-
<%
|
|
2
|
-
scope_select_options = active_scaffold_update_scope_select_options
|
|
3
|
-
|
|
4
|
-
|
|
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
|
-
|
|
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
|
-
<%
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
<%
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
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
|
-
|
|
25
|
-
</ol>
|
|
26
|
+
<% end %>
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
<% if @error_records.present? && @error_records.is_a?(Array) -%>
|
|
2
|
-
<%= render
|
|
2
|
+
<%= render 'messages' unless request.xhr? %>
|
|
3
3
|
|
|
4
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? %>
|
|
5
5
|
<% @error_records.each do |record| %>
|
|
6
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, :
|
|
7
|
+
<%= active_scaffold_error_messages_for record, object_name: "#{record.class.model_name.human.downcase} #{record_title}" %>
|
|
8
8
|
<% end %>
|
|
9
9
|
<% else %>
|
|
10
10
|
<%= render :super %>
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<% html = ''.html_safe -%>
|
|
2
2
|
<% @records.each do |scope, record| -%>
|
|
3
|
-
<% html << render(
|
|
3
|
+
<% html << render("#{batch_create_multiple_layout}_record", {columns: active_scaffold_config.batch_create.columns, form_action: :batch_create, scope: "[#{scope}]", first: false, record: record}) %>
|
|
4
4
|
<% end %>
|
|
5
|
-
ActiveScaffold.create_associated_record_form('<%= element_form_id(:
|
|
5
|
+
ActiveScaffold.create_associated_record_form('<%= element_form_id(action: :batch_create) %>-content', '<%= escape_javascript(html) %>', <%= {singular: false}.to_json.html_safe %>);
|
|
@@ -3,8 +3,8 @@ if @error_records.empty?
|
|
|
3
3
|
flash[:info] = as_(:batch_processing_successful) if flash[:info].blank?
|
|
4
4
|
else
|
|
5
5
|
flash[:error] = @error_records.collect do |_, record|
|
|
6
|
-
active_scaffold_error_messages_for(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
7
|
end.join.html_safe
|
|
8
8
|
end
|
|
9
9
|
%>
|
|
10
|
-
ActiveScaffold.replace_html('<%= active_scaffold_content_id%>','<%=escape_javascript(render(
|
|
10
|
+
ActiveScaffold.replace_html('<%= active_scaffold_content_id%>', '<%=escape_javascript(render('list'))%>');
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
<% form_selector = "#{element_form_id(:
|
|
1
|
+
<% form_selector = "#{element_form_id(action: :batch_create)}" %>
|
|
2
2
|
|
|
3
3
|
<% if controller.send :batch_successful? %>
|
|
4
4
|
<% called_by_controller = params.delete(:batch_create_by) %>
|
|
5
5
|
<% if called_by_controller.nil? %>
|
|
6
|
-
ActiveScaffold.replace_html('<%= active_scaffold_content_id %>','<%= escape_javascript(render(
|
|
6
|
+
ActiveScaffold.replace_html('<%= active_scaffold_content_id %>', '<%= escape_javascript(render('list')) %>');
|
|
7
7
|
<% else %>
|
|
8
|
-
ActiveScaffold.mark_records('<%= "#{controller_id(called_by_controller)}-tbody" %>', <%= {:
|
|
8
|
+
ActiveScaffold.mark_records('<%= "#{controller_id(called_by_controller)}-tbody" %>', <%= {checked: false, include_checkboxes: true}.to_json.html_safe %>);
|
|
9
9
|
<% end %>
|
|
10
10
|
ActiveScaffold.find_action_link('<%= form_selector %>').close();
|
|
11
11
|
<% else %>
|
|
12
|
-
ActiveScaffold.find_action_link('<%= form_selector %>').update_flash_messages('<%= escape_javascript(render(
|
|
13
|
-
ActiveScaffold.replace('<%= form_selector %>', '<%= escape_javascript(render(
|
|
12
|
+
ActiveScaffold.find_action_link('<%= form_selector %>').update_flash_messages('<%= escape_javascript(render('messages')) %>');
|
|
13
|
+
ActiveScaffold.replace('<%= form_selector %>', '<%= escape_javascript(render('batch_create_form', {xhr: true})) %>');
|
|
14
14
|
ActiveScaffold.scroll_to('<%= form_selector %>', true);
|
|
15
15
|
<% end %>
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
<% form_selector = "#{element_form_id(:
|
|
1
|
+
<% form_selector = "#{element_form_id(action: :batch_update)}" %>
|
|
2
2
|
|
|
3
3
|
<% if controller.send :batch_successful? %>
|
|
4
|
-
ActiveScaffold.replace_html('<%= active_scaffold_content_id %>','<%= escape_javascript(render(
|
|
4
|
+
ActiveScaffold.replace_html('<%= active_scaffold_content_id %>', '<%= escape_javascript(render('list')) %>');
|
|
5
5
|
ActiveScaffold.find_action_link('<%= form_selector %>').close();
|
|
6
6
|
<% else %>
|
|
7
|
-
ActiveScaffold.find_action_link('<%= form_selector %>').update_flash_messages('<%= escape_javascript(render(
|
|
8
|
-
ActiveScaffold.replace('<%= form_selector %>', '<%= escape_javascript(render(
|
|
7
|
+
ActiveScaffold.find_action_link('<%= form_selector %>').update_flash_messages('<%= escape_javascript(render('messages')) %>');
|
|
8
|
+
ActiveScaffold.replace('<%= form_selector %>', '<%= escape_javascript(render('batch_update_form', {xhr: true})) %>');
|
|
9
9
|
ActiveScaffold.scroll_to('<%= form_selector %>', true);
|
|
10
10
|
<% end %>
|
|
@@ -62,10 +62,10 @@ module ActiveScaffold::Actions
|
|
|
62
62
|
end
|
|
63
63
|
|
|
64
64
|
def authorized_for_job?(record)
|
|
65
|
-
if record.authorized_for?(:
|
|
65
|
+
if record.authorized_for?(crud_type: active_scaffold_config.send(action_name).crud_type)
|
|
66
66
|
true
|
|
67
67
|
else
|
|
68
|
-
record.errors.add(:base, as_(:no_authorization_for_action, :
|
|
68
|
+
record.errors.add(:base, as_(:no_authorization_for_action, action: action_name))
|
|
69
69
|
error_records << record
|
|
70
70
|
false
|
|
71
71
|
end
|
|
@@ -82,7 +82,7 @@ module ActiveScaffold::Actions
|
|
|
82
82
|
if params[:iframe]=='true' # was this an iframe post ?
|
|
83
83
|
do_refresh_list
|
|
84
84
|
responds_to_parent do
|
|
85
|
-
render :
|
|
85
|
+
render action: 'on_batch_base.js', layout: false
|
|
86
86
|
end
|
|
87
87
|
else # just a regular post
|
|
88
88
|
flash[:info] = as_(:batch_processing_successful) if batch_successful?
|
|
@@ -96,7 +96,7 @@ module ActiveScaffold::Actions
|
|
|
96
96
|
send("#{action_name}_respond_to_js")
|
|
97
97
|
else
|
|
98
98
|
do_refresh_list
|
|
99
|
-
render :
|
|
99
|
+
render action: "on_batch_base"
|
|
100
100
|
end
|
|
101
101
|
end
|
|
102
102
|
|
|
@@ -104,7 +104,7 @@ module ActiveScaffold::Actions
|
|
|
104
104
|
if respond_to? "#{action_name}_respond_to_xml", true
|
|
105
105
|
send("#{action_name}_respond_to_xml")
|
|
106
106
|
else
|
|
107
|
-
|
|
107
|
+
response_to_api(:xml, active_scaffold_config.send(action_name).columns.visible_columns_names)
|
|
108
108
|
end
|
|
109
109
|
end
|
|
110
110
|
|
|
@@ -112,15 +112,7 @@ module ActiveScaffold::Actions
|
|
|
112
112
|
if respond_to? "#{action_name}_respond_to_json", true
|
|
113
113
|
send("#{action_name}_respond_to_json")
|
|
114
114
|
else
|
|
115
|
-
|
|
116
|
-
end
|
|
117
|
-
end
|
|
118
|
-
|
|
119
|
-
def batch_base_respond_to_yaml
|
|
120
|
-
if respond_to? "#{action_name}_respond_to_yaml", true
|
|
121
|
-
send("#{action_name}_respond_to_yaml")
|
|
122
|
-
else
|
|
123
|
-
render :text => Hash.from_xml(response_object.to_xml(:only => active_scaffold_config.send(action_name).columns.visible_columns_names)).to_yaml, :content_type => Mime::YAML, :status => response_status
|
|
115
|
+
response_to_api(:json, active_scaffold_config.send(action_name).columns.visible_columns_names)
|
|
124
116
|
end
|
|
125
117
|
end
|
|
126
118
|
|
|
@@ -3,7 +3,7 @@ module ActiveScaffold::Actions
|
|
|
3
3
|
|
|
4
4
|
def self.included(base)
|
|
5
5
|
base.send :include, ActiveScaffold::Actions::BatchBase unless base < ActiveScaffold::Actions::BatchBase
|
|
6
|
-
base.before_action :batch_create_authorized_filter, :
|
|
6
|
+
base.before_action :batch_create_authorized_filter, only: [:batch_new, :batch_create]
|
|
7
7
|
base.helper_method :batch_create_values
|
|
8
8
|
base.helper_method :batch_create_by_column
|
|
9
9
|
base.helper_method :batch_create_by_records
|
|
@@ -27,14 +27,14 @@ module ActiveScaffold::Actions
|
|
|
27
27
|
protected
|
|
28
28
|
def batch_new_respond_to_html
|
|
29
29
|
if batch_successful?
|
|
30
|
-
render(:
|
|
30
|
+
render(action: 'batch_create')
|
|
31
31
|
else
|
|
32
32
|
return_to_main
|
|
33
33
|
end
|
|
34
34
|
end
|
|
35
35
|
|
|
36
36
|
def batch_new_respond_to_js
|
|
37
|
-
render(:
|
|
37
|
+
render(partial: 'batch_create_form')
|
|
38
38
|
end
|
|
39
39
|
|
|
40
40
|
def batch_add_respond_to_js
|
|
@@ -63,20 +63,20 @@ module ActiveScaffold::Actions
|
|
|
63
63
|
if params[:iframe]=='true' # was this an iframe post ?
|
|
64
64
|
do_refresh_list
|
|
65
65
|
responds_to_parent do
|
|
66
|
-
render :
|
|
66
|
+
render action: 'on_batch_create.js', layout: false
|
|
67
67
|
end
|
|
68
68
|
else # just a regular post
|
|
69
69
|
if batch_successful?
|
|
70
70
|
return_to_main
|
|
71
71
|
else
|
|
72
|
-
render(:
|
|
72
|
+
render(action: 'batch_create')
|
|
73
73
|
end
|
|
74
74
|
end
|
|
75
75
|
end
|
|
76
76
|
|
|
77
77
|
def batch_create_respond_to_js
|
|
78
78
|
do_refresh_list
|
|
79
|
-
render :
|
|
79
|
+
render action: 'on_batch_create'
|
|
80
80
|
end
|
|
81
81
|
|
|
82
82
|
def do_batch_new
|
|
@@ -142,7 +142,7 @@ module ActiveScaffold::Actions
|
|
|
142
142
|
else
|
|
143
143
|
processed_records, created_records = yield
|
|
144
144
|
end
|
|
145
|
-
flash[:info] = as_(:some_records_created, :
|
|
145
|
+
flash[:info] = as_(:some_records_created, count: created_records, model: active_scaffold_config.label(count: created_records)) if batch_successful? || created_records > 0
|
|
146
146
|
end
|
|
147
147
|
|
|
148
148
|
def batch_create_listed
|
|
@@ -168,7 +168,7 @@ module ActiveScaffold::Actions
|
|
|
168
168
|
@error_records = {}
|
|
169
169
|
processed_records = created_records = 0
|
|
170
170
|
params[:record].each do |scope, record_hash|
|
|
171
|
-
do_create(:
|
|
171
|
+
do_create(attributes: record_hash, skip_save: validate_first?)
|
|
172
172
|
error_records[scope] = @record unless successful? && !run_in_transaction?
|
|
173
173
|
created_records += 1 if successful?
|
|
174
174
|
processed_records += 1
|
|
@@ -220,7 +220,7 @@ module ActiveScaffold::Actions
|
|
|
220
220
|
@batch_create_by_records = batch_values_for_column(column, attributes[column.name])
|
|
221
221
|
else
|
|
222
222
|
value = column_value_from_param_value(parent_record, column, attributes[column.name])
|
|
223
|
-
values[column.name] = {:
|
|
223
|
+
values[column.name] = {column: column, value: value}
|
|
224
224
|
end
|
|
225
225
|
end
|
|
226
226
|
values
|
|
@@ -237,7 +237,7 @@ module ActiveScaffold::Actions
|
|
|
237
237
|
# The default security delegates to ActiveRecordPermissions.
|
|
238
238
|
# You may override the method to customize.
|
|
239
239
|
def batch_create_authorized?(record = nil)
|
|
240
|
-
authorized_for?(:
|
|
240
|
+
authorized_for?(crud_type: :create)
|
|
241
241
|
end
|
|
242
242
|
|
|
243
243
|
def batch_create_ignore?(record = nil)
|
|
@@ -3,7 +3,7 @@ module ActiveScaffold::Actions
|
|
|
3
3
|
|
|
4
4
|
def self.included(base)
|
|
5
5
|
base.send :include, ActiveScaffold::Actions::BatchBase unless base < ActiveScaffold::Actions::BatchBase
|
|
6
|
-
base.before_action :batch_destroy_authorized_filter, :
|
|
6
|
+
base.before_action :batch_destroy_authorized_filter, only: [:batch_destroy]
|
|
7
7
|
end
|
|
8
8
|
|
|
9
9
|
def batch_destroy
|
|
@@ -60,7 +60,7 @@ module ActiveScaffold::Actions
|
|
|
60
60
|
# The default security delegates to ActiveRecordPermissions.
|
|
61
61
|
# You may override the method to customize.
|
|
62
62
|
def batch_destroy_authorized?(record = nil)
|
|
63
|
-
authorized_for?(:
|
|
63
|
+
authorized_for?(crud_type: :delete)
|
|
64
64
|
end
|
|
65
65
|
|
|
66
66
|
def batch_destroy_marked_ignore?(record = nil)
|
|
@@ -23,7 +23,7 @@ module ActiveScaffold::Actions
|
|
|
23
23
|
|
|
24
24
|
def self.included(base)
|
|
25
25
|
base.send :include, ActiveScaffold::Actions::BatchBase unless base < ActiveScaffold::Actions::BatchBase
|
|
26
|
-
base.before_action :batch_update_authorized_filter, :
|
|
26
|
+
base.before_action :batch_update_authorized_filter, only: [:batch_edit, :batch_update]
|
|
27
27
|
base.helper_method :batch_update_values
|
|
28
28
|
end
|
|
29
29
|
|
|
@@ -40,14 +40,14 @@ module ActiveScaffold::Actions
|
|
|
40
40
|
protected
|
|
41
41
|
def batch_edit_respond_to_html
|
|
42
42
|
if batch_successful?
|
|
43
|
-
render(:
|
|
43
|
+
render(action: 'batch_update')
|
|
44
44
|
else
|
|
45
45
|
return_to_main
|
|
46
46
|
end
|
|
47
47
|
end
|
|
48
48
|
|
|
49
49
|
def batch_edit_respond_to_js
|
|
50
|
-
render(:
|
|
50
|
+
render(partial: 'batch_update_form')
|
|
51
51
|
end
|
|
52
52
|
|
|
53
53
|
def batch_update_values
|
|
@@ -59,14 +59,14 @@ module ActiveScaffold::Actions
|
|
|
59
59
|
flash[:info] = as_(:batch_processing_successful) if batch_successful?
|
|
60
60
|
do_refresh_list
|
|
61
61
|
responds_to_parent do
|
|
62
|
-
render :
|
|
62
|
+
render action: 'on_batch_update.js', layout: false
|
|
63
63
|
end
|
|
64
64
|
else # just a regular post
|
|
65
65
|
if batch_successful?
|
|
66
|
-
flash[:info] = as_(:updated_model, :
|
|
66
|
+
flash[:info] = as_(:updated_model, model: @record.to_label)
|
|
67
67
|
return_to_main
|
|
68
68
|
else
|
|
69
|
-
render(:
|
|
69
|
+
render(action: 'batch_update')
|
|
70
70
|
end
|
|
71
71
|
end
|
|
72
72
|
end
|
|
@@ -74,7 +74,7 @@ module ActiveScaffold::Actions
|
|
|
74
74
|
def batch_update_respond_to_js
|
|
75
75
|
flash[:info] = as_(:batch_processing_successful) if batch_successful?
|
|
76
76
|
do_refresh_list
|
|
77
|
-
render :
|
|
77
|
+
render action: 'on_batch_update'
|
|
78
78
|
end
|
|
79
79
|
|
|
80
80
|
def do_batch_edit
|
|
@@ -139,7 +139,7 @@ module ActiveScaffold::Actions
|
|
|
139
139
|
set_record_attribute(value[:column], attribute, value[:value])
|
|
140
140
|
end
|
|
141
141
|
|
|
142
|
-
update_save(:
|
|
142
|
+
update_save(no_record_param_update: true)
|
|
143
143
|
if successful?
|
|
144
144
|
@record.as_marked = false if batch_scope == 'MARKED'
|
|
145
145
|
else
|
|
@@ -178,7 +178,7 @@ module ActiveScaffold::Actions
|
|
|
178
178
|
next unless params_hash?(attributes[column.name]) && attributes[column.name][:operator] != 'NO_UPDATE'
|
|
179
179
|
value = attributes[column.name]
|
|
180
180
|
value[:value] = value[:operator] == 'NULL' ? nil : column_value_from_param_value(nil, column, value[:value])
|
|
181
|
-
values[column.name] = {:
|
|
181
|
+
values[column.name] = {column: column, value: value}
|
|
182
182
|
end
|
|
183
183
|
values
|
|
184
184
|
end
|
|
@@ -186,7 +186,7 @@ module ActiveScaffold::Actions
|
|
|
186
186
|
# The default security delegates to ActiveRecordPermissions.
|
|
187
187
|
# You may override the method to customize.
|
|
188
188
|
def batch_update_authorized?(record = nil)
|
|
189
|
-
authorized_for?(:
|
|
189
|
+
authorized_for?(crud_type: :update)
|
|
190
190
|
end
|
|
191
191
|
|
|
192
192
|
def batch_update_ignore?(record = nil)
|
|
@@ -19,7 +19,7 @@ module ActiveScaffold::Config
|
|
|
19
19
|
def self.link=(val)
|
|
20
20
|
@@link = val
|
|
21
21
|
end
|
|
22
|
-
@@link = ActiveScaffold::DataStructures::ActionLink.new('batch_new', :
|
|
22
|
+
@@link = ActiveScaffold::DataStructures::ActionLink.new('batch_new', label: :create, type: :collection, security_method: :batch_create_authorized?, ignore_method: :batch_create_ignore?)
|
|
23
23
|
|
|
24
24
|
# configures where the plugin itself is located. there is no instance version of this.
|
|
25
25
|
cattr_accessor :plugin_directory
|
|
@@ -72,8 +72,8 @@ module ActiveScaffold::Config
|
|
|
72
72
|
|
|
73
73
|
# the label= method already exists in the Form base class
|
|
74
74
|
def label(model = nil, core: @core)
|
|
75
|
-
model ||= core.label(:
|
|
76
|
-
@label ? as_(@label) : as_(:create_model, :
|
|
75
|
+
model ||= core.label(count: 2)
|
|
76
|
+
@label ? as_(@label) : as_(:create_model, model: model)
|
|
77
77
|
end
|
|
78
78
|
end
|
|
79
79
|
end
|
|
@@ -17,8 +17,8 @@ module ActiveScaffold::Config
|
|
|
17
17
|
def self.link=(val)
|
|
18
18
|
@@link = val
|
|
19
19
|
end
|
|
20
|
-
@@link = [ ActiveScaffold::DataStructures::ActionLink.new('batch_destroy', :
|
|
21
|
-
ActiveScaffold::DataStructures::ActionLink.new('batch_destroy', :
|
|
20
|
+
@@link = [ ActiveScaffold::DataStructures::ActionLink.new('batch_destroy', label: :listed, type: :collection, method: :delete, position: false, crud_type: :delete, confirm: :are_you_sure_to_delete, parameters: {batch_scope: 'LISTED'}, security_method: :batch_destroy_authorized?),
|
|
21
|
+
ActiveScaffold::DataStructures::ActionLink.new('batch_destroy', label: :marked, type: :collection, method: :delete, position: false, crud_type: :delete, confirm: :are_you_sure_to_delete, parameters: {batch_scope: 'MARKED'}, security_method: :batch_destroy_authorized?, ignore_method: :batch_destroy_marked_ignore?)]
|
|
22
22
|
|
|
23
23
|
# configures where the plugin itself is located. there is no instance version of this.
|
|
24
24
|
cattr_accessor :plugin_directory
|
|
@@ -17,7 +17,7 @@ module ActiveScaffold::Config
|
|
|
17
17
|
def self.link=(val)
|
|
18
18
|
@@link = val
|
|
19
19
|
end
|
|
20
|
-
@@link = ActiveScaffold::DataStructures::ActionLink.new('batch_edit', :
|
|
20
|
+
@@link = ActiveScaffold::DataStructures::ActionLink.new('batch_edit', label: :edit, type: :collection, security_method: :batch_update_authorized?, ignore_method: :batch_update_ignore?)
|
|
21
21
|
|
|
22
22
|
# configures where the plugin itself is located. there is no instance version of this.
|
|
23
23
|
cattr_accessor :plugin_directory
|
|
@@ -45,8 +45,8 @@ module ActiveScaffold::Config
|
|
|
45
45
|
|
|
46
46
|
# the label= method already exists in the Form base class
|
|
47
47
|
def label(model = nil, core: @core)
|
|
48
|
-
model ||= core.label(:
|
|
49
|
-
@label ? as_(@label) : as_(:update_model, :
|
|
48
|
+
model ||= core.label(count: 2)
|
|
49
|
+
@label ? as_(@label) : as_(:update_model, model: model)
|
|
50
50
|
end
|
|
51
51
|
end
|
|
52
52
|
end
|
|
@@ -7,30 +7,20 @@ module ActiveScaffold
|
|
|
7
7
|
def active_scaffold_batch_create_by_column(column, scope = nil, options = {})
|
|
8
8
|
options = active_scaffold_input_options(column, scope, options)
|
|
9
9
|
|
|
10
|
+
ui_options = column.form_ui_options || column.options
|
|
10
11
|
if column.form_ui == :record_select
|
|
11
|
-
ui_options = column.form_ui_options || column.options
|
|
12
12
|
active_scaffold_record_select(options[:object], column, options, batch_create_by_records, true, ui_options: ui_options)
|
|
13
13
|
elsif column.association
|
|
14
|
-
active_scaffold_batch_create_singular_association(column, options)
|
|
14
|
+
active_scaffold_batch_create_singular_association(column, options, ui_options: ui_options)
|
|
15
15
|
else
|
|
16
16
|
text_area_tag(column.name, params[:record] ? params[:record][column.name] : '', options.merge(column.options[:html_options] || {}))
|
|
17
17
|
end
|
|
18
18
|
|
|
19
19
|
end
|
|
20
20
|
|
|
21
|
-
def active_scaffold_batch_create_singular_association(column, html_options)
|
|
21
|
+
def active_scaffold_batch_create_singular_association(column, html_options, ui_options: column.options)
|
|
22
22
|
associated_options = batch_create_by_records.collect {|r| r.id}
|
|
23
|
-
|
|
24
|
-
html_options.update(column.options[:html_options] || {})
|
|
25
|
-
options = {}
|
|
26
|
-
options.update(column.options)
|
|
27
|
-
html_options[:name] = "#{html_options[:name]}[]"
|
|
28
|
-
html_options[:multiple] = true
|
|
29
|
-
select_tag(column.name, options_from_collection_for_select(select_options.uniq, :id, column.options[:label_method] || :to_label, associated_options), html_options)
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
def batch_create_multiple_remove_link
|
|
33
|
-
link_to as_(:remove), '#', :class => 'remove'
|
|
23
|
+
active_scaffold_input_singular_association(column, html_options.merge(multiple: true, associated: associated_options), {include_blank: false}, ui_options: ui_options)
|
|
34
24
|
end
|
|
35
25
|
|
|
36
26
|
def batch_create_multiple_layout
|
|
@@ -2,26 +2,49 @@ module ActiveScaffold
|
|
|
2
2
|
module Helpers
|
|
3
3
|
module DatepickerUpdateColumnHelpers
|
|
4
4
|
def active_scaffold_update_date_picker(column, options)
|
|
5
|
-
current_params = {:
|
|
5
|
+
current_params = {value: nil, number: nil, unit: nil, operator: 'NO_UPDATE'}
|
|
6
6
|
current_params.merge!(batch_update_values[column.name][:value].symbolize_keys) if batch_update_values.dig(column.name, :value)
|
|
7
7
|
operator_options = active_scaffold_update_generic_operators(column)
|
|
8
8
|
operator_options.concat(ActiveScaffold::Actions::BatchUpdate::DateOperators.collect {|comp| [as_(comp.downcase.to_sym), comp]}) if active_scaffold_config.batch_update.process_mode == :update
|
|
9
|
-
options = options.merge(:
|
|
9
|
+
options = options.merge(show: ['PLUS', 'MINUS'].exclude?(current_params[:operator]))
|
|
10
|
+
operator_attributes = active_scaffold_batch_control_attributes(
|
|
11
|
+
column, :select, :batch_update_operator,
|
|
12
|
+
id: "#{options[:id]}_operator",
|
|
13
|
+
class: 'text-input as_update_date_operator'
|
|
14
|
+
)
|
|
10
15
|
tags = []
|
|
11
16
|
tags << select_tag("#{options[:name]}[operator]",
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
:class => "text-input as_update_date_operator")
|
|
17
|
+
options_for_select(operator_options, current_params[:operator]),
|
|
18
|
+
operator_attributes)
|
|
15
19
|
tags << active_scaffold_search_date_picker_field(column, options.merge(show: current_params[:operator] == 'REPLACE'), current_params[:value], 'value')
|
|
16
20
|
tags << active_scaffold_update_date_bridge_trend_tag(column, current_params, options)
|
|
17
21
|
tags.join(" ").html_safe
|
|
18
22
|
end
|
|
19
23
|
|
|
20
24
|
def active_scaffold_update_date_bridge_trend_tag(column, current_params, options)
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
+
number_attributes = active_scaffold_batch_control_attributes(
|
|
26
|
+
column, :text, :batch_update_date_amount,
|
|
27
|
+
class: 'text-input', size: 10, autocomplete: 'off'
|
|
28
|
+
)
|
|
29
|
+
unit_attributes = active_scaffold_batch_control_attributes(
|
|
30
|
+
column, :select, :batch_update_date_unit,
|
|
31
|
+
class: 'text-input'
|
|
32
|
+
)
|
|
33
|
+
controls = [
|
|
34
|
+
text_field_tag("#{options[:name]}[number]", current_params[:number], number_attributes),
|
|
35
|
+
select_tag(
|
|
36
|
+
"#{options[:name]}[unit]",
|
|
37
|
+
options_for_select(active_scaffold_search_datetime_trend_units(column), current_params[:unit]),
|
|
38
|
+
unit_attributes
|
|
39
|
+
)
|
|
40
|
+
]
|
|
41
|
+
content_tag(
|
|
42
|
+
:span,
|
|
43
|
+
safe_join(controls, ' '),
|
|
44
|
+
id: "#{options[:id]}_trend",
|
|
45
|
+
class: 'search-date-trend',
|
|
46
|
+
style: ('display: none' unless ['PLUS', 'MINUS'].include?(current_params[:operator]))
|
|
47
|
+
)
|
|
25
48
|
end
|
|
26
49
|
end
|
|
27
50
|
end
|
|
@@ -32,44 +32,78 @@ module ActiveScaffold
|
|
|
32
32
|
end
|
|
33
33
|
|
|
34
34
|
def active_scaffold_update_generic_operators_select(column, options)
|
|
35
|
-
current = {:
|
|
35
|
+
current = {operator: 'NO_UPDATE'}
|
|
36
36
|
current.merge!(batch_update_values[column.name][:value].symbolize_keys) if batch_update_values.dig(column.name, :value)
|
|
37
|
+
attributes = active_scaffold_batch_control_attributes(
|
|
38
|
+
column, :select, :batch_update_operator,
|
|
39
|
+
id: "#{options[:id]}_operator",
|
|
40
|
+
class: 'as_batch_update_operator text-input'
|
|
41
|
+
)
|
|
37
42
|
select_tag("record[#{column.name}][operator]",
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
:class => "as_batch_update_operator text_input")
|
|
43
|
+
options_for_select(active_scaffold_update_generic_operators(column), current[:operator]),
|
|
44
|
+
attributes)
|
|
41
45
|
end
|
|
42
46
|
|
|
43
47
|
def active_scaffold_update_numeric(column, options)
|
|
44
|
-
current = {:
|
|
48
|
+
current = {value: nil, opt: 'ABSOLUTE', operator: 'NO_UPDATE'}
|
|
45
49
|
current.merge!(batch_update_values[column.name][:value].symbolize_keys) if batch_update_values[column.name] && batch_update_values[column.name][:value]
|
|
46
50
|
operator_options = active_scaffold_update_generic_operators(column) + ActiveScaffold::Actions::BatchUpdate::NumericOperators.collect {|comp| [as_(comp.downcase.to_sym), comp]}
|
|
47
51
|
select_options = ActiveScaffold::Actions::BatchUpdate::NumericOptions.collect {|comp| [as_(comp.downcase.to_sym), comp]}
|
|
52
|
+
style = current[:operator] == 'NO_UPDATE' ? 'display: none;' : nil
|
|
53
|
+
operator_attributes = active_scaffold_batch_control_attributes(
|
|
54
|
+
column, :select, :batch_update_operator,
|
|
55
|
+
id: "#{options[:id]}_operator",
|
|
56
|
+
class: 'as_update_numeric_option'
|
|
57
|
+
)
|
|
58
|
+
value_attributes = active_scaffold_batch_control_attributes(
|
|
59
|
+
column, column.form_ui || column.column&.type, :batch_update_value,
|
|
60
|
+
id: "#{options[:id]}_value",
|
|
61
|
+
style: style
|
|
62
|
+
)
|
|
63
|
+
value_attributes = active_scaffold_input_text_options(value_attributes)
|
|
64
|
+
option_attributes = active_scaffold_batch_control_attributes(
|
|
65
|
+
column, :select, :batch_update_numeric_option,
|
|
66
|
+
id: "#{options[:id]}_opt",
|
|
67
|
+
class: 'as_update_numeric_option',
|
|
68
|
+
style: style
|
|
69
|
+
)
|
|
48
70
|
html = select_tag("record[#{column.name}][operator]",
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
html << ' ' << text_field_tag("record[#{column.name}][value]", current[:value], active_scaffold_input_text_options)
|
|
71
|
+
options_for_select(operator_options, current[:operator]),
|
|
72
|
+
operator_attributes)
|
|
73
|
+
html << ' ' << text_field_tag("record[#{column.name}][value]", current[:value], value_attributes)
|
|
53
74
|
html << ' ' << select_tag("record[#{column.name}][opt]",
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
:class => "as_update_numeric_option")
|
|
75
|
+
options_for_select(select_options, current[:opt]),
|
|
76
|
+
option_attributes)
|
|
57
77
|
html
|
|
58
78
|
end
|
|
59
79
|
alias_method :active_scaffold_update_integer, :active_scaffold_update_numeric
|
|
60
80
|
alias_method :active_scaffold_update_decimal, :active_scaffold_update_numeric
|
|
61
81
|
alias_method :active_scaffold_update_float, :active_scaffold_update_numeric
|
|
82
|
+
alias_method :active_scaffold_update_number, :active_scaffold_update_numeric
|
|
62
83
|
|
|
63
84
|
def active_scaffold_update_scope_select(select_options = active_scaffold_update_scope_select_options)
|
|
64
|
-
if select_options
|
|
85
|
+
if active_scaffold_update_scope_select_hidden?(select_options)
|
|
86
|
+
hidden_field_tag("batch_scope", select_options.first[1]) unless select_options.empty?
|
|
87
|
+
else
|
|
88
|
+
attributes = active_scaffold_batch_control_attributes(nil, :select, :batch_scope, class: 'text-input')
|
|
65
89
|
select_tag("batch_scope",
|
|
66
90
|
options_for_select(select_options, batch_scope || select_options.last[1]),
|
|
67
|
-
|
|
68
|
-
else
|
|
69
|
-
hidden_field_tag("batch_scope", select_options.first[1]) unless select_options.empty?
|
|
91
|
+
attributes)
|
|
70
92
|
end
|
|
71
93
|
end
|
|
72
94
|
|
|
95
|
+
def active_scaffold_batch_control_attributes(column, form_ui, batch_role, **attributes)
|
|
96
|
+
as_element_attributes(
|
|
97
|
+
:form_control,
|
|
98
|
+
proc_options: {column: column, form_ui: form_ui, batch_role: batch_role},
|
|
99
|
+
**attributes
|
|
100
|
+
)
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
def active_scaffold_update_scope_select_hidden?(select_options = active_scaffold_update_scope_select_options)
|
|
104
|
+
select_options.length < 2
|
|
105
|
+
end
|
|
106
|
+
|
|
73
107
|
def active_scaffold_update_scope_select_options
|
|
74
108
|
select_options = []
|
|
75
109
|
select_options << [as_(:listed), 'LISTED'] if active_scaffold_config.batch_update.list_mode_enabled
|
|
@@ -10,7 +10,7 @@ module ActiveScaffoldBatch
|
|
|
10
10
|
#not working because routing picks show route instead
|
|
11
11
|
#self::ACTIVE_SCAFFOLD_CORE_ROUTING[:collection][:batch_destroy] = :get
|
|
12
12
|
#you may define a route for your controller before resource routes
|
|
13
|
-
#match 'players/batch_destroy' => 'players#batch_destroy', :
|
|
13
|
+
#match 'players/batch_destroy' => 'players#batch_destroy', via: [:get]
|
|
14
14
|
self::ACTIVE_SCAFFOLD_CORE_ROUTING[:collection][:batch_destroy] = :delete
|
|
15
15
|
end
|
|
16
16
|
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: active_scaffold_batch
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 3.
|
|
4
|
+
version: 3.8.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Sergio Cambra
|
|
@@ -16,14 +16,14 @@ dependencies:
|
|
|
16
16
|
requirements:
|
|
17
17
|
- - ">="
|
|
18
18
|
- !ruby/object:Gem::Version
|
|
19
|
-
version: 4.
|
|
19
|
+
version: 4.4.0
|
|
20
20
|
type: :runtime
|
|
21
21
|
prerelease: false
|
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
|
23
23
|
requirements:
|
|
24
24
|
- - ">="
|
|
25
25
|
- !ruby/object:Gem::Version
|
|
26
|
-
version: 4.
|
|
26
|
+
version: 4.4.0
|
|
27
27
|
description: You want to destroy/update many records at once with activescaffold?
|
|
28
28
|
email: activescaffold@googlegroups.com
|
|
29
29
|
executables: []
|