active_scaffold_duplicate 2.0.0 → 2.1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0fe10f1f6b25e8249a7284f9a49c560942fffb1f3e71cde9a7b032c023cf2321
4
- data.tar.gz: 1bfec3896e826a60dea88d6ae4f3ae30ab0492dc7577e8ed296628a3a3a47538
3
+ metadata.gz: f5f1c4cf45f2d3b19627b5455855e465444dda860be61435783d4bf0343bc370
4
+ data.tar.gz: 1d38a8e4e5e7a9463308c23f4c0f7327acc5264b8318211c84381fd48f78ed84
5
5
  SHA512:
6
- metadata.gz: b5db393a4f336a7e7afb971e2f77f181f1edb289c86a1ea41bb8545e5adb00d2890b97418100db317f1a861556cc10a45781d0671a92445d37f9087ec7b8cc36
7
- data.tar.gz: fd92b32577e294ec50758ce5b8788e1c52926cf3b4a56655163af470d4d0d910f72616f5277df8a180f70e054e2dcfc4aed7443a646c4b6659573af7e9ccfd02
6
+ metadata.gz: de1f1f6928cc3e14d9582c3965f4d5494c683429a69e738c230ca8edd3684a68490c500f9df8219eab6a35eea864ac81f0a048c78d8c316611ec28b78c8510f9
7
+ data.tar.gz: '09bb16ccb13496eef1d29a5c035fb6f769f5ec4075283a9db5964df63be60713f5478a82441aeb6bf43d752f705c84ce2b9331477eb8e6d41a7b7aa979e22698'
data/README.md ADDED
@@ -0,0 +1,149 @@
1
+ # Duplicate Action for ActiveScaffold
2
+
3
+ Currently, this gem is compatible with ActiveScaffold >= 4.4.0.
4
+
5
+ ## Overview
6
+
7
+ This gem adds an action to clone records. By default will only set attributes and belongs_to associations. You must override `initialize_dup` in your model or define a method to clone the record and set in `conf.duplicate.method`.
8
+
9
+ Also, adds support to duplicate rows in a subform, setting the `:duplicate` setting in the column's options, or `form_ui_options`.
10
+
11
+ ## Installation
12
+
13
+ You'll need ActiveScaffold 4.4.0 or newer.
14
+
15
+ ```bash
16
+ gem install active_scaffold_duplicate
17
+ ```
18
+
19
+ ## Usage
20
+
21
+ #### Step 1
22
+
23
+ Override `initialize_dup` in the model to set some attributes or copy associations:
24
+
25
+ ```ruby
26
+ # app/models/bill.rb
27
+ class Bill < ActiveRecord::Base
28
+ belongs_to :customer
29
+ has_many :items
30
+
31
+ def initialize_dup(other)
32
+ super
33
+ self.items = other.items.map(&:dup)
34
+ end
35
+ end
36
+ ```
37
+
38
+ #### Step 2
39
+
40
+ Add duplicate action.
41
+
42
+ ```ruby
43
+ class BillsController < ApplicationController
44
+ active_scaffold do |conf|
45
+ conf.actions << :duplicate
46
+ end
47
+ end
48
+ ```
49
+
50
+ #### Step 3
51
+
52
+ Change method to `:get` in link if you want to display create form instead of cloning record. Set position to `:replace` or `:after` for inline display, or enable page rendering.
53
+
54
+ ```ruby
55
+ class BillsController < ApplicationController
56
+ active_scaffold do |conf|
57
+ conf.duplicate.link.method = :get
58
+ conf.duplicate.link.position = :after
59
+ #conf.duplicate.link.page = true # for new page rendering
60
+ end
61
+ end
62
+ ```
63
+
64
+ Also you can change it globally.
65
+
66
+ ```ruby
67
+ class ApplicationController < ActionController::Base
68
+ active_scaffold.set_defaults do |conf|
69
+ conf.duplicate.link.method = :get
70
+ conf.duplicate.link.position = :after
71
+ #conf.duplicate.link.page = true # for new page rendering
72
+ end
73
+ end
74
+ ```
75
+
76
+ You can access to record which is being duplicated in your form overrides with `@old_record` variable.
77
+
78
+ If you use `:post` method, you can enable `refresh_list` to refresh the list instead of only adding new record at top, or set `action_after_clone` to open edit form for example:
79
+
80
+ ```ruby
81
+ conf.duplicate.refresh_list = true
82
+ conf.duplicate.action_after_clone = :edit
83
+ ```
84
+
85
+ ## Before/after controller methods
86
+
87
+ It's possible to define some methods to add some custom code which require access to session or request params:
88
+
89
+ * For `:post` method, `before_duplicate_save(record)` and `after_duplicate_save(record)` can be defined, which will be called before and after saving the record respectively.
90
+ * For `:new` method, `before_duplicate_new(record)` can be defined, which will be called before rendering.
91
+
92
+ ## Duplicate record in subforms
93
+
94
+ Set the `:duplicate` setting in the column's options, or `form_ui_options`.
95
+
96
+ ```ruby
97
+ conf.columns[:lines].form_ui = nil, {duplicate: true} # set in the options for form_ui only, leaving UI as nil so subform is used
98
+ conf.columns[:lines].options = {duplicate: true} # set in the column options, would be available to other UI (list, show, search), although won't affect probably
99
+ ```
100
+
101
+ Cloning the record will send a request to `edit_associated` action in the parent controller, same as adding a new record.
102
+
103
+ ### UI adapter support
104
+
105
+ The duplicate link rendered for a subform row exposes the
106
+ `subform_record_duplicate` UI element. UI framework adapters can add or replace
107
+ its HTML attributes without overriding the helper:
108
+
109
+ ```ruby
110
+ ActiveScaffold.add_element_attributes :subform_record_duplicate,
111
+ class: 'btn btn-sm btn-secondary'
112
+ ```
113
+
114
+ The plugin keeps the `dup` class used by its JavaScript and merges it with
115
+ classes supplied by the adapter.
116
+
117
+ If you want to make changes to the cloned record before added to the subform, you can override `duplicate_subform_record` method in your controller, call `super` to leave active_scaffold_duplicate to copy the submitted attributes, and then make your changes. You can check what subform was called for with `@column` variable:
118
+
119
+ ```ruby
120
+ def duplicate_subform_row(record, ...)
121
+ super
122
+ if @column == :travel_line_items
123
+ record.financial_month = nil # don't copy financial month
124
+ record.compute_totals
125
+ end
126
+ end
127
+ ```
128
+
129
+ ## Support
130
+
131
+ If you have issues installing the gem, search / post to the [Active Scaffold](http://groups.google.com/group/activescaffold) forum or [Create an issue](http://github.com/activescaffold/active_scaffold_duplicate/issues)
132
+
133
+ ## Contributing
134
+
135
+ Fork, hack, push, and request a pull:
136
+
137
+ <http://github.com/activescaffold/active_scaffold_duplicate/>
138
+
139
+ ## License
140
+
141
+ Released under the MIT license (included).
142
+
143
+ ## Author
144
+
145
+ Contact me:
146
+
147
+ ```ruby
148
+ Sergio Cambra - irb(main):001:0> ( 'sergioATenpijama._see_s'.gsub('_see_', 'e').gsub('AT', '@') )
149
+ ```
@@ -12,12 +12,23 @@ module ActiveScaffold
12
12
 
13
13
  def active_scaffold_subform_record_actions(association_column, record, locked, scope)
14
14
  actions = super
15
+ return actions if association_column.nil?
15
16
  return actions unless association_column.association.collection?
16
17
  return actions unless (association_column.form_ui_options || association_column.options)[:duplicate]
17
18
 
18
19
  safe_join(
19
20
  [
20
- link_to(as_(:duplicate), '#', class: 'dup', style: 'display: none;', remote: true, data: {scope: scope}),
21
+ link_to(
22
+ as_(:duplicate),
23
+ '#',
24
+ as_element_attributes(
25
+ :subform_record_duplicate,
26
+ class: 'dup',
27
+ style: 'display: none;',
28
+ remote: true,
29
+ data: {scope: scope}
30
+ )
31
+ ),
21
32
  actions
22
33
  ]
23
34
  )
@@ -1,7 +1,7 @@
1
1
  module ActiveScaffoldDuplicate
2
2
  module Version
3
3
  MAJOR = 2
4
- MINOR = 0
4
+ MINOR = 1
5
5
  PATCH = 0
6
6
 
7
7
  STRING = [MAJOR, MINOR, PATCH].compact.join('.')
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_scaffold_duplicate
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sergio Cambra
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2026-02-09 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: active_scaffold
@@ -16,24 +15,24 @@ dependencies:
16
15
  requirements:
17
16
  - - ">="
18
17
  - !ruby/object:Gem::Version
19
- version: 4.2.0
18
+ version: 4.4.0
20
19
  type: :runtime
21
20
  prerelease: false
22
21
  version_requirements: !ruby/object:Gem::Requirement
23
22
  requirements:
24
23
  - - ">="
25
24
  - !ruby/object:Gem::Version
26
- version: 4.2.0
25
+ version: 4.4.0
27
26
  description: Clone records using a method from model in ActiveScaffold
28
27
  email: activescaffold@googlegroups.com
29
28
  executables: []
30
29
  extensions: []
31
30
  extra_rdoc_files:
32
31
  - LICENSE.txt
33
- - README.textile
32
+ - README.md
34
33
  files:
35
34
  - LICENSE.txt
36
- - README.textile
35
+ - README.md
37
36
  - app/assets/javascripts/active_scaffold_duplicate.js
38
37
  - app/views/active_scaffold_overrides/duplicate.js.erb
39
38
  - config/locales/en.yml
@@ -49,7 +48,6 @@ homepage: http://github.com/activescaffold/active_scaffold_duplicate
49
48
  licenses:
50
49
  - MIT
51
50
  metadata: {}
52
- post_install_message:
53
51
  rdoc_options: []
54
52
  require_paths:
55
53
  - lib
@@ -64,8 +62,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
64
62
  - !ruby/object:Gem::Version
65
63
  version: '0'
66
64
  requirements: []
67
- rubygems_version: 3.5.11
68
- signing_key:
65
+ rubygems_version: 3.6.9
69
66
  specification_version: 4
70
67
  summary: Clone record gem for Activescaffold
71
68
  test_files: []
data/README.textile DELETED
@@ -1,111 +0,0 @@
1
- h1. Duplicate Action for ActiveScaffold
2
-
3
- Currently, this gem is compatible with ActiveScaffold >= 3.3.x gems and rails >= 4.0.
4
- Use 1.0.x for rails >= 3.x versions.
5
-
6
- h2. Overview
7
-
8
- This gem adds an action to clone records. By default will only set attributes and belongs_to associations. You must override initialize_dup in your model or define a method to clone the record and set in conf.duplicate.method.
9
-
10
- h2. Installation
11
-
12
- You'll need at least ActiveScaffold 3.3.x to use this, and rails 3.x
13
-
14
-
15
- <pre>
16
- gem install active_scaffold_duplicate
17
- </pre>
18
-
19
- h2. Usage
20
-
21
- h4. Step 1
22
-
23
- Override initialize_dup in the model to set some attributes or copy associations:
24
-
25
- <pre>
26
- # app/models/bill.rb
27
- class Bill < ActiveRecord::Base
28
- belongs_to :customer
29
- has_many :items
30
-
31
- def initialize_dup(other)
32
- super
33
- self.items = other.items.map(&:dup)
34
- end
35
- end
36
- </pre>
37
-
38
- h4. Step 2
39
-
40
- Add duplicate action.
41
-
42
- <pre>
43
- class BillsController < ApplicationController
44
- active_scaffold do |conf|
45
- conf.actions << :duplicate
46
- end
47
- end
48
- </pre>
49
-
50
- h4. Step 3
51
-
52
- Change method to :get in link if you want to display create form instead of cloning record. Set position to :replace or :after for inline display, or enable page rendering.
53
-
54
- <pre>
55
- class BillsController < ApplicationController
56
- active_scaffold do |conf|
57
- conf.duplicate.link.method = :get
58
- conf.duplicate.link.position = :after
59
- #conf.duplicate.link.page = true # for new page rendering
60
- end
61
- end
62
- </pre>
63
-
64
- Also you can change it globally.
65
-
66
- <pre>
67
- class ApplicationController < ActionController::Base
68
- active_scaffold.set_defaults do |conf|
69
- conf.duplicate.link.method = :get
70
- conf.duplicate.link.position = :after
71
- #conf.duplicate.link.page = true # for new page rendering
72
- end
73
- end
74
- </pre>
75
-
76
- You can access to record which is being duplicated in your form overrides with @old_record variable.
77
-
78
- If you use :post method, you can enable refresh_list to refresh the list instead of only adding new record at top, or set action_after_clone to open edit form for example:
79
-
80
- <pre>
81
- conf.duplicate.refresh_list = true
82
- conf.duplicate.action_after_clone = :edit
83
- </pre>
84
-
85
- h2. Before/after controller methods
86
-
87
- It's possible to define some methods to add some custom code which require access to session or request params:
88
-
89
- * For :post method, before_duplicate_save(record) and after_duplicate_save(record) can be defined, which will be called before and after saving the record respectively.
90
- * For :new method, before_duplicate_new(record) can be defined, which will be called before rendering.
91
-
92
- h2. Support
93
-
94
- If you have issues installing the gem, search / post to the "Active Scaffold":http://groups.google.com/group/activescaffold forum or "Create an issue":http://github.com/activescaffold/active_scaffold_duplicate/issues
95
-
96
- h2. Contributing
97
-
98
- Fork, hack, push, and request a pull:
99
-
100
- http://github.com/activescaffold/active_scaffold_duplicate/
101
-
102
- h2. License
103
-
104
- Released under the MIT license (included).
105
-
106
- h2. Author
107
-
108
- Contact me:
109
- <pre>
110
- Sergio Cambra - irb(main):001:0> ( 'sergioATprogramatica._see_s'.gsub('_see_', 'e').gsub('AT', '@') )
111
- </pre>