active_scaffold_duplicate 1.3.0 → 2.0.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/app/assets/javascripts/active_scaffold_duplicate.js +39 -0
- data/lib/active_scaffold/actions/duplicate.rb +11 -0
- data/lib/active_scaffold/helpers/duplicate_helpers.rb +13 -0
- data/lib/active_scaffold_duplicate/engine.rb +3 -0
- data/lib/active_scaffold_duplicate/subform.rb +19 -0
- data/lib/active_scaffold_duplicate/version.rb +2 -2
- data/lib/active_scaffold_duplicate.rb +3 -0
- metadata +6 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 0fe10f1f6b25e8249a7284f9a49c560942fffb1f3e71cde9a7b032c023cf2321
|
|
4
|
+
data.tar.gz: 1bfec3896e826a60dea88d6ae4f3ae30ab0492dc7577e8ed296628a3a3a47538
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b5db393a4f336a7e7afb971e2f77f181f1edb289c86a1ea41bb8545e5adb00d2890b97418100db317f1a861556cc10a45781d0671a92445d37f9087ec7b8cc36
|
|
7
|
+
data.tar.gz: fd92b32577e294ec50758ce5b8788e1c52926cf3b4a56655163af470d4d0d910f72616f5277df8a180f70e054e2dcfc4aed7443a646c4b6659573af7e9ccfd02
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
(function() {
|
|
2
|
+
jQuery(document).ready(function () {
|
|
3
|
+
jQuery(document).on('ajax:beforeSend', '.sub-form-record .actions .dup', function (e, xhr, settings) {
|
|
4
|
+
if (e.detail && !xhr) {
|
|
5
|
+
xhr = e.detail[0];
|
|
6
|
+
settings = e.detail[1];
|
|
7
|
+
}
|
|
8
|
+
var link = jQuery(e.target), row = link.closest('.sub-form-record'), subform = row.closest('.sub-form'),
|
|
9
|
+
url = subform.find('.as_create_another:last').attr('href');
|
|
10
|
+
if (url) {
|
|
11
|
+
var params = {};
|
|
12
|
+
row.find(':input[name]').serializeArray().forEach(function(item) {
|
|
13
|
+
var newName = item.name.replace(/^record\[/, 'dup[');
|
|
14
|
+
params[newName] = item.value;
|
|
15
|
+
});
|
|
16
|
+
var paramString = jQuery.param(params);
|
|
17
|
+
// If URL already has ?, append with & otherwise with ?
|
|
18
|
+
settings.url = url + (url.indexOf('?') !== -1 ? '&' : '?') + paramString;
|
|
19
|
+
} else {
|
|
20
|
+
e.preventDefault();
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
ActiveScaffold.setup_callbacks.push(function(container) {
|
|
26
|
+
var container = jQuery(container), new_row_subform;
|
|
27
|
+
if (container.is('.sub-form-record')) { // adding a new row to a subform
|
|
28
|
+
new_row_subform = container.closest('.sub-form');
|
|
29
|
+
if (!new_row_subform.is(':has(.as_create_another)')) return;
|
|
30
|
+
}
|
|
31
|
+
jQuery('.sub-form:has(.as_create_another)', container).add(new_row_subform).each(function () {
|
|
32
|
+
var subform = this;
|
|
33
|
+
jQuery('.sub-form-record .actions .dup', this).filter(function () {
|
|
34
|
+
return $(this).closest('.sub-form').is(subform);
|
|
35
|
+
}).show();
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
})();
|
|
@@ -27,6 +27,17 @@ module ActiveScaffold::Actions
|
|
|
27
27
|
def duplicate_authorized?(record = nil)
|
|
28
28
|
(record || self).authorized_for?(crud_type: :create, action: :duplicate, reason: true)
|
|
29
29
|
end
|
|
30
|
+
|
|
31
|
+
def do_edit_associated
|
|
32
|
+
super
|
|
33
|
+
if params[:dup]
|
|
34
|
+
attributes = params.delete(:dup)
|
|
35
|
+
@scope&.slice(1..-2)&.split('][')&.each { |scope| attributes = attributes[scope] }
|
|
36
|
+
attributes = attributes[@column.name].values
|
|
37
|
+
cfg = active_scaffold_config_for(@record.class)
|
|
38
|
+
update_record_from_params(@record, cfg.subform.columns, attributes, true)
|
|
39
|
+
end
|
|
40
|
+
end
|
|
30
41
|
|
|
31
42
|
def duplicate_respond_to_html
|
|
32
43
|
if successful?
|
|
@@ -9,6 +9,19 @@ module ActiveScaffold
|
|
|
9
9
|
columns
|
|
10
10
|
end
|
|
11
11
|
end
|
|
12
|
+
|
|
13
|
+
def active_scaffold_subform_record_actions(association_column, record, locked, scope)
|
|
14
|
+
actions = super
|
|
15
|
+
return actions unless association_column.association.collection?
|
|
16
|
+
return actions unless (association_column.form_ui_options || association_column.options)[:duplicate]
|
|
17
|
+
|
|
18
|
+
safe_join(
|
|
19
|
+
[
|
|
20
|
+
link_to(as_(:duplicate), '#', class: 'dup', style: 'display: none;', remote: true, data: {scope: scope}),
|
|
21
|
+
actions
|
|
22
|
+
]
|
|
23
|
+
)
|
|
24
|
+
end
|
|
12
25
|
end
|
|
13
26
|
end
|
|
14
27
|
end
|
|
@@ -10,5 +10,8 @@ module ActiveScaffoldDuplicate
|
|
|
10
10
|
self::ACTIVE_SCAFFOLD_CORE_ROUTING[:member][:duplicate] = [:post, :get]
|
|
11
11
|
end
|
|
12
12
|
end
|
|
13
|
+
initializer 'active_scaffold_duplicate.extensions' do
|
|
14
|
+
ActiveScaffold::Actions::Subform.prepend ActiveScaffoldDuplicate::Subform
|
|
15
|
+
end
|
|
13
16
|
end
|
|
14
17
|
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
module ActiveScaffoldDuplicate
|
|
2
|
+
module Subform
|
|
3
|
+
protected
|
|
4
|
+
def do_edit_associated
|
|
5
|
+
super
|
|
6
|
+
if params[:dup]
|
|
7
|
+
attributes = params.delete(:dup)
|
|
8
|
+
@scope&.slice(1..-2)&.split('][')&.each { |scope| attributes = attributes[scope] }
|
|
9
|
+
attributes = attributes[@column.name].values[0]
|
|
10
|
+
duplicate_subform_row(@record, attributes)
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def duplicate_subform_row(record, attributes, columns = nil)
|
|
15
|
+
cfg = active_scaffold_config_for(record.class) unless columns
|
|
16
|
+
update_record_from_params(record, columns || cfg.subform.columns, attributes, true)
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -4,6 +4,7 @@ module ActiveScaffoldDuplicate
|
|
|
4
4
|
def self.root
|
|
5
5
|
File.dirname(__FILE__) + "/.."
|
|
6
6
|
end
|
|
7
|
+
autoload :Subform, 'active_scaffold_duplicate/subform'
|
|
7
8
|
end
|
|
8
9
|
|
|
9
10
|
module ActiveScaffold
|
|
@@ -19,3 +20,5 @@ module ActiveScaffold
|
|
|
19
20
|
ActiveScaffold.autoload_subdir('helpers', self, File.dirname(__FILE__))
|
|
20
21
|
end
|
|
21
22
|
end
|
|
23
|
+
|
|
24
|
+
ActiveScaffold.javascripts << 'active_scaffold_duplicate'
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: active_scaffold_duplicate
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version:
|
|
4
|
+
version: 2.0.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Sergio Cambra
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2026-02-09 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: active_scaffold
|
|
@@ -16,14 +16,14 @@ dependencies:
|
|
|
16
16
|
requirements:
|
|
17
17
|
- - ">="
|
|
18
18
|
- !ruby/object:Gem::Version
|
|
19
|
-
version: 4.
|
|
19
|
+
version: 4.2.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.2.0
|
|
27
27
|
description: Clone records using a method from model in ActiveScaffold
|
|
28
28
|
email: activescaffold@googlegroups.com
|
|
29
29
|
executables: []
|
|
@@ -34,6 +34,7 @@ extra_rdoc_files:
|
|
|
34
34
|
files:
|
|
35
35
|
- LICENSE.txt
|
|
36
36
|
- README.textile
|
|
37
|
+
- app/assets/javascripts/active_scaffold_duplicate.js
|
|
37
38
|
- app/views/active_scaffold_overrides/duplicate.js.erb
|
|
38
39
|
- config/locales/en.yml
|
|
39
40
|
- config/locales/es.yml
|
|
@@ -42,6 +43,7 @@ files:
|
|
|
42
43
|
- lib/active_scaffold/helpers/duplicate_helpers.rb
|
|
43
44
|
- lib/active_scaffold_duplicate.rb
|
|
44
45
|
- lib/active_scaffold_duplicate/engine.rb
|
|
46
|
+
- lib/active_scaffold_duplicate/subform.rb
|
|
45
47
|
- lib/active_scaffold_duplicate/version.rb
|
|
46
48
|
homepage: http://github.com/activescaffold/active_scaffold_duplicate
|
|
47
49
|
licenses:
|