effective_bootstrap 0.9.10 → 0.9.11

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5092faff38f399976a16a668ef167ca4b9f2103db81cb03617a5165a05731c6b
4
- data.tar.gz: 3168ab3c1c38bff6e1f6020a0aea2dadc5e6f2917ffef79827054415cb6b1198
3
+ metadata.gz: dfccd40b53981bf152c50dbcf01e94ba572c9647f7bbdd089a458eb84c18aa6a
4
+ data.tar.gz: 765eab4d79769e5a8bb970a95fcf8275dcd978ebb2aca709869590349cf8db71
5
5
  SHA512:
6
- metadata.gz: ff0e00b34d8101166e8eb0d895634e2e5099366953232fa4063c20dd504bfe10641738fb5ed90c99599de0c9f3f3d6a3d029d1cc35548ef8eab0fdb7fcbb27c6
7
- data.tar.gz: e24803d6584be1ff0a1aea39a6790528186c5189974a1a69af5ef95a295665b932e74af3734ec1735a2a82e5ee75ed9d5dbf98af4e6352f71971d250590a68fa
6
+ metadata.gz: 758307b2718b798b6b5827f8628ed66c037d30612d889edb88f39b79c44028e9a29b0ed7880dc1a79f2321fb62b80bd415d0920642ba44a6e758525fb6df1cbf
7
+ data.tar.gz: 9587c02c77dfbbdf5a454ff1122acca628af9a5556dcca2d6e6780b624d483560fb7f996f8c72e645f0b7beb6c50c2ccb563f16d28bc28fc2178a26384bde0c1
data/README.md CHANGED
@@ -388,20 +388,26 @@ and
388
388
  = fb.date_field :published_at
389
389
  ```
390
390
 
391
- If `Book` has an integer `position` field, there will be reorder buttons to drag & drop reorder the items.
391
+ If `:books` can be destroyed, a hidden field `_destroy` will automatically be added to each set of fields and a Remove button will be displayed to remove the item.
392
392
 
393
- If `allow_destroy: true` there will be remove buttons.
393
+ If the `Book` model has an integer `position` attribute, a hidden field `position` will automatically be added to each set of fields and a Reorder button will be displayed to drag&drop reorder items.
394
394
 
395
- You can customize the has many behaviour by passing the following:
395
+ If the has_many collection is blank?, `.build()` will be automatically called, unless `build: false` is passed.
396
+
397
+ Any errors on the has_many name will be displayed unless `errors: false` is passed.
398
+
399
+ You can customize this behaviour by passing the following:
396
400
 
397
401
  ```haml
398
- = f.has_many :books, add: true, remove: true, reorder: true
402
+ = f.has_many :books, add: true, remove: true, reorder: true, build: true, errors: true do |fb|
403
+ = fb.text_field :title
399
404
  ```
400
405
 
401
406
  or add an html class:
402
407
 
403
408
  ```haml
404
- = f.has_many :books, class: 'tight'
409
+ = f.has_many :books, class: 'tight' do |fb|
410
+ = fb.text_field :title
405
411
  ```
406
412
 
407
413
  ## Custom percent_field
@@ -37,7 +37,7 @@ $(document).on 'click', '[data-effective-form-has-many-add]', (event) ->
37
37
  uid = (new Date).valueOf()
38
38
  template = $obj.data('effective-form-has-many-template').replace(/HASMANYINDEX/g, uid)
39
39
 
40
- $fields = $(template).hide().fadeIn('slow')
40
+ $fields = $(template).hide().fadeIn('fast')
41
41
  EffectiveBootstrap.initialize($fields)
42
42
  $obj.closest('.has-many-links').before($fields)
43
43
 
@@ -56,9 +56,9 @@ $(document).on 'click', '[data-effective-form-has-many-remove]', (event) ->
56
56
 
57
57
  if $input.length > 0
58
58
  $input.val('true')
59
- $fields.addClass('marked-for-destruction').fadeOut('slow')
59
+ $fields.addClass('marked-for-destruction').fadeOut('fast')
60
60
  else
61
- $fields.fadeOut('slow', -> this.remove())
61
+ $fields.fadeOut('fast', -> this.remove())
62
62
 
63
63
  assignPositions($hasMany)
64
64
  true
@@ -70,5 +70,8 @@ $(document).on 'click', '[data-effective-form-has-many-reorder]', (event) ->
70
70
  $hasMany = $obj.closest('.form-has-many')
71
71
  return unless $hasMany.length > 0
72
72
 
73
+ $fields = $hasMany.children('.has-many-fields:not(.marked-for-destruction)')
74
+ return unless $fields.length > 1
75
+
73
76
  $hasMany.toggleClass('reordering')
74
77
  true
@@ -4,5 +4,5 @@
4
4
  font-size: 0.75rem;
5
5
  margin: 0.25rem 0;
6
6
 
7
- a { padding: 0.25rem 0; }
7
+ a { padding: 0.5rem 0; }
8
8
  }
@@ -50,18 +50,29 @@ module Effective
50
50
  end
51
51
 
52
52
  def build_label
53
- return BLANK if options[:label] == false
53
+ return BLANK if options[:label] == false && !actions?
54
54
  return BLANK if name.kind_of?(NilClass)
55
55
 
56
- text = (options[:label].delete(:text) || (object.class.human_attribute_name(name) if object) || BLANK).html_safe
56
+ text = begin
57
+ if options[:label] == false
58
+ nil
59
+ elsif options[:label].key?(:text)
60
+ options[:label].delete(:text)
61
+ elsif object.present?
62
+ object.class.human_attribute_name(name)
63
+ end || BLANK
64
+ end.html_safe
65
+
66
+ actions = if !disabled? && actions?
67
+ content_tag(:div, class: 'effective-checks-actions text-muted') do
68
+ link_to('Select All', '#', 'data-effective-checks-all': true) + ' - ' + link_to('Select None', '#', 'data-effective-checks-none': true)
69
+ end
70
+ end
57
71
 
58
72
  content_tag(:label, options[:label]) do
59
- text + content_tag(:div, class: 'effective-checks-actions text-muted') do
60
- unless disabled? || !actions?
61
- link_to('Select All', '#', 'data-effective-checks-all': true) + ' - ' + link_to('Select None', '#', 'data-effective-checks-none': true)
62
- end
63
- end
73
+ [text, actions].compact.join.html_safe
64
74
  end
75
+
65
76
  end
66
77
 
67
78
  def build_item(builder)
@@ -91,7 +102,7 @@ module Effective
91
102
 
92
103
  def actions? # default true
93
104
  return @actions unless @actions.nil?
94
- @actions = (options.delete(:actions) != false)
105
+ @actions = (options[:input].delete(:actions) != false)
95
106
  end
96
107
 
97
108
  end
@@ -4,7 +4,11 @@ module Effective
4
4
  BLANK = ''.html_safe
5
5
 
6
6
  def to_html(&block)
7
- content_tag(:div, options[:input]) do
7
+ object.send(name).build() if build? && collection.blank?
8
+
9
+ errors = (@builder.error(name) if errors?) || BLANK
10
+
11
+ errors + content_tag(:div, options[:input]) do
8
12
  has_many_fields_for(block) + has_many_links_for(block)
9
13
  end
10
14
  end
@@ -21,12 +25,22 @@ module Effective
21
25
  Array(options[:input][:collection] || object.send(name))
22
26
  end
23
27
 
24
- # cards: true
28
+ # cards: false
25
29
  def display
26
30
  @display ||= (options[:input].delete(:cards) ? :cards : :rows)
27
31
  end
28
32
 
29
- # add: false
33
+ # build: true
34
+ def build?
35
+ return @build unless @build.nil?
36
+
37
+ @build ||= begin
38
+ build = options[:input].delete(:build)
39
+ build.nil? ? true : build
40
+ end
41
+ end
42
+
43
+ # add: true
30
44
  def add?
31
45
  return @add unless @add.nil?
32
46
 
@@ -36,7 +50,17 @@ module Effective
36
50
  end
37
51
  end
38
52
 
39
- # remove: false
53
+ # errors: true
54
+ def errors?
55
+ return @errors unless @errors.nil?
56
+
57
+ @errors ||= begin
58
+ errors = options[:input].delete(:errors)
59
+ errors.nil? ? true : errors
60
+ end
61
+ end
62
+
63
+ # remove: true
40
64
  def remove?
41
65
  return @remove unless @remove.nil?
42
66
 
@@ -77,7 +101,7 @@ module Effective
77
101
  return BLANK unless add? || reorder?
78
102
 
79
103
  content_tag(:div, class: 'has-many-links text-center mt-2') do
80
- [(link_to_add(block) if add?), (link_to_reorder(block) if reorder?)].compact.join(' ').html_safe
104
+ [*(link_to_add(block) if add?), *(link_to_reorder(block) if reorder?)].join(' ').html_safe
81
105
  end
82
106
  end
83
107
 
@@ -115,9 +139,14 @@ module Effective
115
139
 
116
140
  def render_template(block)
117
141
  resource = build_resource()
118
- index = object.send(name).index(resource)
142
+ index = collection.length
119
143
 
120
144
  html = render_resource(resource, block)
145
+
146
+ unless html.include?("#{name}_attributes][#{index}]")
147
+ raise('unexpected index. unable to render resource template.')
148
+ end
149
+
121
150
  html.gsub!("#{name}_attributes][#{index}]", "#{name}_attributes][HASMANYINDEX]")
122
151
  html.gsub!("#{name}_attributes_#{index}_", "#{name}_attributes_HASMANYINDEX_")
123
152
 
@@ -167,7 +196,10 @@ module Effective
167
196
  end
168
197
 
169
198
  def build_resource
170
- @build_resource ||= object.send(name).build().tap { |resource| object.send(name).delete(resource) }
199
+ # Using .new() here seems like it should work but it doesn't. It changes the index
200
+ @build_resource ||= object.send(name).build().tap do |resource|
201
+ object.send(name).delete(resource)
202
+ end
171
203
  end
172
204
 
173
205
  end
@@ -1,3 +1,3 @@
1
1
  module EffectiveBootstrap
2
- VERSION = '0.9.10'.freeze
2
+ VERSION = '0.9.11'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: effective_bootstrap
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.10
4
+ version: 0.9.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Code and Effect
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-01-12 00:00:00.000000000 Z
11
+ date: 2021-01-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -94,6 +94,20 @@ dependencies:
94
94
  - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: haml
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
97
111
  description: Everything you need to get set up with bootstrap 4.
98
112
  email:
99
113
  - info@codeandeffect.com