active_scaffold_child_memberships 0.1.1 → 0.1.3

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: 3ed22261d2b7d6a07b9f61b19b419bf4ff53491b57671aa5e702f629f41d1b25
4
- data.tar.gz: f70a457b8bdfbfe185141a861ee6e1b91cd4960953148e8cdffbff273ec8e56c
3
+ metadata.gz: b649df8c43f1291d6321ddd9399fb0b2522208163c649dd5073463458fa12002
4
+ data.tar.gz: f34614f1f6a891df4ebe7bfdf04c9b9872e87341303983683ce890f5a452555b
5
5
  SHA512:
6
- metadata.gz: 6a183a7b1b809c43b2513aba3b85f595c7f3a559bd5d1cd86004dd572639b4b1473cd2745cf8b32a21c61c02a21d14e3ef9162d6e109ac0803dbc19fe7aa299a
7
- data.tar.gz: 78bc6ea3fc431364211180efbc05524eba8e1215d807853447034af896fe17422dbc243559151f651ea242f35247e221553632aa66f96154113061e781c7c45e
6
+ metadata.gz: 78b1bf92785b1ff4ad1157440897de668fa7d3de80784fc457ad7716a8da3a22521eb84774e3bc8e8867a6b6c3ac097c58f8f44be50536ceada9839a97a47669
7
+ data.tar.gz: d4d02ff3cde0c73b149598f017827aa03dd62b892f6e8fbea1702cc047dc19a0b66a3b4d688f8189e8bea1c7682c59d2cfdc74a8a383589825bfd6904dc3c679
data/README.md CHANGED
@@ -89,7 +89,7 @@ If new columns are not allowed, it can be disabled using `add_label: false`:
89
89
 
90
90
  ## Overriding Helpers
91
91
 
92
- The helper `active_scaffold_child_memberships_helper` can be overrided to change the default columns rendered, instead of the assigned records only. For example to render all available roles:
92
+ The helper `active_scaffold_child_memberships_members` can be overrided to change the default columns rendered, instead of the assigned records only. For example to render all available roles:
93
93
 
94
94
  ```ruby
95
95
  def active_scaffold_child_memberships_helper(column, row_records)
@@ -118,3 +118,15 @@ end
118
118
  ```
119
119
 
120
120
  Also, the available records can be changed with the usual methods, `options_for_association_conditions` and `association_klass_scoped`, they receive the source association of the has_many through association (`:roles` in the example), and an empty record of the through association.
121
+
122
+ To change how checkboxes are rendered, for example, adding extra content, the helper `active_scaffold_child_memberships_checkbox` can be overrided. It supports model prefix too. The argument child is the record of the row, and member is the record of the column.
123
+
124
+ ```ruby
125
+ def active_scaffold_child_memberships_checkbox(column, source_column, child, member, name:, value:)
126
+ if column == :roles
127
+ safe_join [super, content_tag(:span, member.state_for(child))]
128
+ else
129
+ super
130
+ end
131
+ end
132
+ ```
@@ -1,11 +1,11 @@
1
1
  module ActiveScaffoldChildMemberships
2
2
  module AttributeParams
3
3
  protected
4
- def update_column_association(parent_record, column, attribute, value, avoid_changes = false)
4
+ def update_column_association(parent_record, column, attribute, value, ...)
5
5
  if column.form_ui == :child_memberships
6
6
  source_col = active_scaffold_config_for(column.association.through_reflection.klass).columns[column.association.source_reflection.name]
7
7
  value.each do |child, members|
8
- update_column_association(child, source_col, attribute, members, avoid_changes)
8
+ update_column_association(child, source_col, attribute, members, ...)
9
9
  end
10
10
  else
11
11
  super
@@ -15,9 +15,11 @@ module ActiveScaffoldChildMemberships
15
15
  end
16
16
  header.unshift content_tag(:th, through_col.label)
17
17
 
18
+ checkbox_helper = override_helper_per_model(:active_scaffold_child_membership_checkbox, column.active_record_class)
18
19
  rows = children.map do |record|
20
+ checkbox_name = "#{options[:name]}[memberships][#{record.id}][]"
19
21
  columns = column_records.map.with_index do |member, i|
20
- content_tag(:td, check_box_tag("#{options[:name]}[memberships][#{record.id}][]", i, record.send(source_col.name).include?(member), id: nil))
22
+ content_tag(:td, send(checkbox_helper, column, source_col, record, member, name: checkbox_name, value: i))
21
23
  end
22
24
  label = record.send(ui_options[:child_label_method] || :to_label)
23
25
  columns.unshift content_tag(:td, h(label))
@@ -44,6 +46,10 @@ module ActiveScaffoldChildMemberships
44
46
  row_records.flat_map(&column.association.source_reflection.name).uniq
45
47
  end
46
48
 
49
+ def active_scaffold_child_membership_checkbox(column, source_column, child, member, name:, value:)
50
+ check_box_tag(name, value, child.send(source_column.name).include?(member), id: nil)
51
+ end
52
+
47
53
  def active_scaffold_child_memberships_new_column(column, name, source_col, ui_options)
48
54
  inplace_options = {object: source_col.active_record_class.new, id: '', disabled: true, associated: nil, class: 'inplace_field', name: name}
49
55
  form_ui, form_ui_options = ui_options[:add_column_ui]
@@ -2,7 +2,7 @@ module ActiveScaffoldChildMemberships
2
2
  module Version
3
3
  MAJOR = 0
4
4
  MINOR = 1
5
- PATCH = 1
5
+ PATCH = 3
6
6
 
7
7
  STRING = [MAJOR, MINOR, PATCH].compact.join('.')
8
8
  end
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_scaffold_child_memberships
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sergio Cambra
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2025-01-16 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,14 +15,14 @@ dependencies:
16
15
  requirements:
17
16
  - - ">="
18
17
  - !ruby/object:Gem::Version
19
- version: 4.0.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.0.0
25
+ version: 4.4.0
27
26
  description: A form UI for ActiveScaffold, allowing to edit membership association
28
27
  for multiple children
29
28
  email: activescaffold@googlegroups.com
@@ -46,7 +45,6 @@ homepage: https://activescaffold.eu
46
45
  licenses:
47
46
  - MIT
48
47
  metadata: {}
49
- post_install_message:
50
48
  rdoc_options: []
51
49
  require_paths:
52
50
  - lib
@@ -61,8 +59,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
61
59
  - !ruby/object:Gem::Version
62
60
  version: '0'
63
61
  requirements: []
64
- rubygems_version: 3.5.11
65
- signing_key:
62
+ rubygems_version: 3.6.9
66
63
  specification_version: 4
67
64
  summary: Form UI :child_memberships for ActiveScaffold
68
65
  test_files: []