active_scaffold_duplicate 2.1.1 → 2.1.2
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/views/active_scaffold_overrides/duplicate.js.erb +7 -7
- data/lib/active_scaffold/actions/duplicate.rb +17 -25
- data/lib/active_scaffold/config/duplicate.rb +14 -13
- data/lib/active_scaffold/helpers/duplicate_helpers.rb +2 -0
- data/lib/active_scaffold_duplicate/engine.rb +4 -2
- data/lib/active_scaffold_duplicate/extensions.rb +16 -0
- data/lib/active_scaffold_duplicate/subform.rb +9 -6
- data/lib/active_scaffold_duplicate/version.rb +3 -1
- data/lib/active_scaffold_duplicate.rb +6 -17
- metadata +5 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 89da6472dfe4e19f1651d5dc91ae4da84279c63ba93533b15a1fbe3cc6bc60e7
|
|
4
|
+
data.tar.gz: 842eaca461d05accc132cde56440938a28ab50e37aa023db802acf90dfd4165b
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 8c9610ffe574f0ce21f05d0a7f203579c77aae94295471d2a33da1a8861a1e9dae670f95dffca343d3fbba957389d231c077927ad1dba1acec49640c083a0385
|
|
7
|
+
data.tar.gz: 8f223d048ebc1808f4869f195600861373d588dde5171b62d565ae8bcfe8fda78d8a484596b28eda4fa34deb5e5bac94766754817ad42e22a15ac472da166d98
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
try {
|
|
2
2
|
<% insert_at ||= :top %>
|
|
3
|
-
<%= render :
|
|
3
|
+
<%= render partial: 'update_messages', locals: {messages_id: active_scaffold_messages_id} %>
|
|
4
4
|
<% if controller.send :successful? %>
|
|
5
|
-
<% if
|
|
6
|
-
<%= render :
|
|
5
|
+
<% if active_scaffold_config.duplicate.refresh_list %>
|
|
6
|
+
<%= render partial: 'refresh_list' %>
|
|
7
7
|
<% else %>
|
|
8
|
-
<% new_row = render :
|
|
9
|
-
ActiveScaffold.create_record_row('<%= active_scaffold_id %>','<%= escape_javascript(new_row) %>', <%= {:
|
|
10
|
-
<%= render :
|
|
8
|
+
<% new_row = render partial: 'list_record', locals: {record: @record} %>
|
|
9
|
+
ActiveScaffold.create_record_row('<%= active_scaffold_id %>','<%= escape_javascript(new_row) %>', <%= javascript_literal({insert_at: insert_at}) %>);
|
|
10
|
+
<%= render partial: 'update_calculations', formats: [:js] %>
|
|
11
11
|
<% end %>
|
|
12
|
-
<% if
|
|
12
|
+
<% if active_scaffold_config.duplicate.action_after_clone %>
|
|
13
13
|
var link = ActiveScaffold.find_action_link('<%= action_link_id active_scaffold_config.duplicate.action_after_clone, @record.id %>');
|
|
14
14
|
if (link) link.open();
|
|
15
15
|
<% end %>
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module ActiveScaffold::Actions
|
|
2
4
|
module Duplicate
|
|
3
5
|
def self.included(base)
|
|
4
|
-
base.before_action :duplicate_authorized_filter, :
|
|
6
|
+
base.before_action :duplicate_authorized_filter, only: :duplicate
|
|
5
7
|
end
|
|
6
|
-
|
|
8
|
+
|
|
7
9
|
def duplicate
|
|
8
10
|
@old_record = find_if_allowed(params[:id], crud_type: :read, action: :duplicate)
|
|
9
11
|
@record = @old_record.send(active_scaffold_config.duplicate.method)
|
|
@@ -18,8 +20,9 @@ module ActiveScaffold::Actions
|
|
|
18
20
|
respond_to_action(active_scaffold_config.duplicate.action_view)
|
|
19
21
|
end
|
|
20
22
|
end
|
|
21
|
-
|
|
23
|
+
|
|
22
24
|
protected
|
|
25
|
+
|
|
23
26
|
def before_duplicate_save(record); end
|
|
24
27
|
def before_duplicate_new(record); end
|
|
25
28
|
def after_duplicate_save(record); end
|
|
@@ -28,22 +31,11 @@ module ActiveScaffold::Actions
|
|
|
28
31
|
(record || self).authorized_for?(crud_type: :create, action: :duplicate, reason: true)
|
|
29
32
|
end
|
|
30
33
|
|
|
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, avoid_changes: true)
|
|
39
|
-
end
|
|
40
|
-
end
|
|
41
|
-
|
|
42
34
|
def duplicate_respond_to_html
|
|
43
35
|
if successful?
|
|
44
|
-
flash[:info] = as_(:created_model, :
|
|
45
|
-
if action = active_scaffold_config.duplicate.action_after_clone
|
|
46
|
-
redirect_to params_for(:
|
|
36
|
+
flash[:info] = as_(:created_model, model: @record.to_label)
|
|
37
|
+
if (action = active_scaffold_config.duplicate.action_after_clone)
|
|
38
|
+
redirect_to params_for(action: action, id: @record.id)
|
|
47
39
|
else
|
|
48
40
|
return_to_main
|
|
49
41
|
end
|
|
@@ -51,29 +43,29 @@ module ActiveScaffold::Actions
|
|
|
51
43
|
return_to_main
|
|
52
44
|
end
|
|
53
45
|
end
|
|
54
|
-
|
|
46
|
+
|
|
55
47
|
def duplicate_respond_to_js
|
|
56
48
|
do_refresh_list if successful? && active_scaffold_config.duplicate.refresh_list
|
|
57
|
-
render :
|
|
49
|
+
render action: 'duplicate'
|
|
58
50
|
end
|
|
59
51
|
|
|
60
52
|
def duplicate_respond_to_xml
|
|
61
|
-
render :
|
|
53
|
+
render xml: response_object.to_xml(only: active_scaffold_config.create.columns.visible_columns_names),
|
|
54
|
+
content_type: Mime[:xml], status: response_status, location: response_location
|
|
62
55
|
end
|
|
63
56
|
|
|
64
57
|
def duplicate_respond_to_json
|
|
65
|
-
render :
|
|
58
|
+
render text: response_object.to_json(only: active_scaffold_config.create.columns.visible_columns_names),
|
|
59
|
+
content_type: Mime[:json], status: response_status, location: response_location
|
|
66
60
|
end
|
|
67
61
|
|
|
68
|
-
def duplicate_respond_to_yaml
|
|
69
|
-
render :text => Hash.from_xml(response_object.to_xml(:only => active_scaffold_config.create.columns.visible_columns_names)).to_yaml, :content_type => Mime::YAML, :status => response_status, :location => response_location
|
|
70
|
-
end
|
|
71
|
-
|
|
72
62
|
private
|
|
63
|
+
|
|
73
64
|
def duplicate_authorized_filter
|
|
74
65
|
link = active_scaffold_config.duplicate.link || active_scaffold_config.duplicate.class.link
|
|
75
66
|
raise ActiveScaffold::ActionNotAllowed unless Array(send(link.security_method))[0]
|
|
76
67
|
end
|
|
68
|
+
|
|
77
69
|
def duplicate_formats
|
|
78
70
|
(default_formats + active_scaffold_config.formats + active_scaffold_config.duplicate.formats).uniq
|
|
79
71
|
end
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module ActiveScaffold::Config
|
|
2
4
|
class Duplicate < Base
|
|
3
5
|
self.crud_type = :create
|
|
4
|
-
|
|
6
|
+
|
|
5
7
|
def initialize(core_config)
|
|
6
8
|
super
|
|
7
9
|
self.method = self.class.method
|
|
@@ -11,31 +13,30 @@ module ActiveScaffold::Config
|
|
|
11
13
|
end
|
|
12
14
|
|
|
13
15
|
# the method to clone records
|
|
14
|
-
cattr_accessor :method
|
|
15
|
-
|
|
16
|
-
|
|
16
|
+
cattr_accessor :method, instance_accessor: false, default: :dup
|
|
17
|
+
|
|
17
18
|
# which action render after clone with post
|
|
18
|
-
cattr_accessor :action_after_clone
|
|
19
|
-
@@action_after_clone = nil
|
|
19
|
+
cattr_accessor :action_after_clone, instance_accessor: false, default: nil
|
|
20
20
|
|
|
21
21
|
# which view render when method is :get (used as respond_to_action argument)
|
|
22
|
-
cattr_accessor :action_view
|
|
23
|
-
@@action_view = :new
|
|
22
|
+
cattr_accessor :action_view, instance_accessor: false, default: :new
|
|
24
23
|
|
|
25
24
|
# whether we should refresh list after clone or not
|
|
26
|
-
cattr_accessor :refresh_list
|
|
27
|
-
@@refresh_list = false
|
|
25
|
+
cattr_accessor :refresh_list, instance_accessor: false, default: false
|
|
28
26
|
|
|
29
27
|
# the ActionLink for this action
|
|
30
|
-
cattr_accessor :link
|
|
31
|
-
|
|
28
|
+
cattr_accessor :link, instance_accessor: false,
|
|
29
|
+
default: ActiveScaffold::DataStructures::ActionLink.new(
|
|
30
|
+
:duplicate, type: :member, method: :post, position: false,
|
|
31
|
+
security_method: :duplicate_authorized?, ignore_method: :duplicate_ignore?
|
|
32
|
+
)
|
|
32
33
|
|
|
33
34
|
# instance-level configuration
|
|
34
35
|
# ----------------------------
|
|
35
36
|
|
|
36
37
|
# the ActionLink for this action
|
|
37
38
|
attr_accessor :link
|
|
38
|
-
|
|
39
|
+
|
|
39
40
|
# the method to clone records
|
|
40
41
|
attr_accessor :method
|
|
41
42
|
|
|
@@ -1,13 +1,15 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module ActiveScaffoldDuplicate
|
|
2
4
|
class Engine < ::Rails::Engine
|
|
3
|
-
initializer
|
|
5
|
+
initializer 'active_scaffold_duplicate.action_view' do |_app|
|
|
4
6
|
ActiveSupport.on_load :action_view do
|
|
5
7
|
include ActiveScaffold::Helpers::DuplicateHelpers
|
|
6
8
|
end
|
|
7
9
|
end
|
|
8
10
|
initializer 'active_scaffold_duplicate.routes' do
|
|
9
11
|
ActiveSupport.on_load :active_scaffold_routing do
|
|
10
|
-
self::ACTIVE_SCAFFOLD_CORE_ROUTING[:member][:duplicate] = [
|
|
12
|
+
self::ACTIVE_SCAFFOLD_CORE_ROUTING[:member][:duplicate] = %i[post get]
|
|
11
13
|
end
|
|
12
14
|
end
|
|
13
15
|
initializer 'active_scaffold_duplicate.extensions' do
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# ActiveScaffold extension namespaces provided by the duplicate plugin.
|
|
4
|
+
module ActiveScaffold
|
|
5
|
+
module Actions
|
|
6
|
+
ActiveScaffold.autoload_subdir('actions', self, File.expand_path('..', __dir__))
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
module Config
|
|
10
|
+
ActiveScaffold.autoload_subdir('config', self, File.expand_path('..', __dir__))
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
module Helpers
|
|
14
|
+
ActiveScaffold.autoload_subdir('helpers', self, File.expand_path('..', __dir__))
|
|
15
|
+
end
|
|
16
|
+
end
|
|
@@ -1,14 +1,17 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module ActiveScaffoldDuplicate
|
|
2
4
|
module Subform
|
|
3
5
|
protected
|
|
6
|
+
|
|
4
7
|
def do_edit_associated
|
|
5
8
|
super
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
return unless params[:dup]
|
|
10
|
+
|
|
11
|
+
attributes = params.delete(:dup)
|
|
12
|
+
@scope[1..-2]&.split('][')&.each { |scope| attributes = attributes[scope] } if @scope
|
|
13
|
+
attributes = attributes[@column.name].values[0]
|
|
14
|
+
duplicate_subform_row(@record, attributes)
|
|
12
15
|
end
|
|
13
16
|
|
|
14
17
|
def duplicate_subform_row(record, attributes, columns = nil)
|
|
@@ -1,24 +1,13 @@
|
|
|
1
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'active_scaffold_duplicate/engine'
|
|
4
|
+
require 'active_scaffold_duplicate/extensions'
|
|
2
5
|
|
|
3
6
|
module ActiveScaffoldDuplicate
|
|
4
7
|
def self.root
|
|
5
|
-
File.dirname(__FILE__)
|
|
8
|
+
"#{File.dirname(__FILE__)}/.."
|
|
6
9
|
end
|
|
7
10
|
autoload :Subform, 'active_scaffold_duplicate/subform'
|
|
8
11
|
end
|
|
9
12
|
|
|
10
|
-
|
|
11
|
-
module Actions
|
|
12
|
-
ActiveScaffold.autoload_subdir('actions', self, File.dirname(__FILE__))
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
module Config
|
|
16
|
-
ActiveScaffold.autoload_subdir('config', self, File.dirname(__FILE__))
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
module Helpers
|
|
20
|
-
ActiveScaffold.autoload_subdir('helpers', self, File.dirname(__FILE__))
|
|
21
|
-
end
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
ActiveScaffold.javascripts << 'active_scaffold_duplicate'
|
|
13
|
+
ActiveScaffold.javascripts << 'active_scaffold_duplicate'
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: active_scaffold_duplicate
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 2.1.
|
|
4
|
+
version: 2.1.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Sergio Cambra
|
|
@@ -42,12 +42,14 @@ files:
|
|
|
42
42
|
- lib/active_scaffold/helpers/duplicate_helpers.rb
|
|
43
43
|
- lib/active_scaffold_duplicate.rb
|
|
44
44
|
- lib/active_scaffold_duplicate/engine.rb
|
|
45
|
+
- lib/active_scaffold_duplicate/extensions.rb
|
|
45
46
|
- lib/active_scaffold_duplicate/subform.rb
|
|
46
47
|
- lib/active_scaffold_duplicate/version.rb
|
|
47
48
|
homepage: http://github.com/activescaffold/active_scaffold_duplicate
|
|
48
49
|
licenses:
|
|
49
50
|
- MIT
|
|
50
|
-
metadata:
|
|
51
|
+
metadata:
|
|
52
|
+
rubygems_mfa_required: 'true'
|
|
51
53
|
rdoc_options: []
|
|
52
54
|
require_paths:
|
|
53
55
|
- lib
|
|
@@ -55,7 +57,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
55
57
|
requirements:
|
|
56
58
|
- - ">="
|
|
57
59
|
- !ruby/object:Gem::Version
|
|
58
|
-
version: '
|
|
60
|
+
version: '3.2'
|
|
59
61
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
60
62
|
requirements:
|
|
61
63
|
- - ">="
|