effective_bootstrap 0.9.10 → 0.9.15
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +11 -5
- data/app/assets/javascripts/effective_bootstrap.js +1 -0
- data/app/assets/javascripts/effective_bootstrap/other.js.coffee +7 -0
- data/app/assets/javascripts/effective_has_many/initialize.js.coffee +8 -3
- data/app/assets/javascripts/effective_password/initialize.js.coffee +9 -0
- data/app/assets/javascripts/effective_password/input.js +1 -0
- data/app/assets/stylesheets/effective_checks/input.scss +1 -1
- data/app/helpers/effective_form_builder_helper.rb +2 -2
- data/app/models/effective/form_inputs/checks.rb +19 -8
- data/app/models/effective/form_inputs/has_many.rb +40 -8
- data/app/models/effective/form_inputs/password_field.rb +16 -2
- data/app/models/effective/form_inputs/text_field.rb +5 -0
- data/lib/effective_bootstrap/version.rb +1 -1
- metadata +18 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3caddfef38f42c46b1fa8f9349a123b92cb993e49e833b2273b5feb7777a9996
|
4
|
+
data.tar.gz: '09b0e3add6de331cee37ad5d81ec5ddb91a3d226f7bd9436aff17c89d2251d64'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: de8a09444cc218dde3206eeb6653a7b029529a7502e7714b0ae62c2325780290846e3fc379cd80921485e0a3fbfab08d23a7b558fd6fec9a899298b9e4bce254
|
7
|
+
data.tar.gz: 847970f4ea44074b4e374b97a0e4e89220e0d9892d18d69605372e929e1be2119f63ae67035fbcc0222b54c6a67046ce99308756e944d603ac08f6e8b80a2e03
|
data/README.md
CHANGED
@@ -388,20 +388,26 @@ and
|
|
388
388
|
= fb.date_field :published_at
|
389
389
|
```
|
390
390
|
|
391
|
-
If `
|
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 `
|
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
|
-
|
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
|
@@ -18,6 +18,7 @@
|
|
18
18
|
//= require ./effective_has_many/input
|
19
19
|
//= require ./effective_integer/input
|
20
20
|
//= require ./effective_number_text/input
|
21
|
+
//= require ./effective_password/input
|
21
22
|
//= require ./effective_percent/input
|
22
23
|
//= require ./effective_phone/input
|
23
24
|
//= require ./effective_price/input
|
@@ -2,3 +2,10 @@
|
|
2
2
|
$(document).on 'cocoon:before-remove', (event, $obj) ->
|
3
3
|
$(event.target).data('remove-timeout', 1000)
|
4
4
|
$obj.fadeOut('slow')
|
5
|
+
|
6
|
+
# Open all external trix links in a new window.
|
7
|
+
$(document).on 'click', '.trix-content a', (event) ->
|
8
|
+
obj = event.currentTarget
|
9
|
+
|
10
|
+
if obj.host != window.location.host && !obj.isContentEditable
|
11
|
+
obj.setAttribute('target', '_blank')
|
@@ -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('
|
40
|
+
$fields = $(template).hide().fadeIn('fast')
|
41
41
|
EffectiveBootstrap.initialize($fields)
|
42
42
|
$obj.closest('.has-many-links').before($fields)
|
43
43
|
|
@@ -48,6 +48,8 @@ $(document).on 'click', '[data-effective-form-has-many-remove]', (event) ->
|
|
48
48
|
event.preventDefault()
|
49
49
|
|
50
50
|
$obj = $(event.currentTarget)
|
51
|
+
return unless $obj.data('confirmed') if $obj.data('confirm')
|
52
|
+
|
51
53
|
$hasMany = $obj.closest('.form-has-many')
|
52
54
|
return unless $hasMany.length > 0
|
53
55
|
|
@@ -56,9 +58,9 @@ $(document).on 'click', '[data-effective-form-has-many-remove]', (event) ->
|
|
56
58
|
|
57
59
|
if $input.length > 0
|
58
60
|
$input.val('true')
|
59
|
-
$fields.addClass('marked-for-destruction').fadeOut('
|
61
|
+
$fields.addClass('marked-for-destruction').fadeOut('fast')
|
60
62
|
else
|
61
|
-
$fields.fadeOut('
|
63
|
+
$fields.fadeOut('fast', -> this.remove())
|
62
64
|
|
63
65
|
assignPositions($hasMany)
|
64
66
|
true
|
@@ -70,5 +72,8 @@ $(document).on 'click', '[data-effective-form-has-many-reorder]', (event) ->
|
|
70
72
|
$hasMany = $obj.closest('.form-has-many')
|
71
73
|
return unless $hasMany.length > 0
|
72
74
|
|
75
|
+
$fields = $hasMany.children('.has-many-fields:not(.marked-for-destruction)')
|
76
|
+
return unless $fields.length > 1
|
77
|
+
|
73
78
|
$hasMany.toggleClass('reordering')
|
74
79
|
true
|
@@ -0,0 +1,9 @@
|
|
1
|
+
# Prevent non-currency buttons from being pressed
|
2
|
+
$(document).on 'click', 'button[data-effective-password]', (event) ->
|
3
|
+
$obj = $(event.currentTarget)
|
4
|
+
$input = $obj.closest('.input-group')
|
5
|
+
|
6
|
+
$input.find('input').attr('type', $obj.data('effective-password'))
|
7
|
+
$input.find('button[data-effective-password]').toggle()
|
8
|
+
|
9
|
+
false
|
@@ -0,0 +1 @@
|
|
1
|
+
//= require ./initialize
|
@@ -1,8 +1,8 @@
|
|
1
1
|
module EffectiveFormBuilderHelper
|
2
2
|
def effective_form_with(**options, &block)
|
3
3
|
# Compute the default ID
|
4
|
-
subject = Array(options[:
|
5
|
-
class_name = subject.class.name.parameterize.underscore
|
4
|
+
subject = Array(options[:model] || options[:scope]).last
|
5
|
+
class_name = (options[:scope] || subject.class.name.parameterize.underscore)
|
6
6
|
unique_id = options.except(:model).hash.abs
|
7
7
|
|
8
8
|
html_id = if subject.kind_of?(Symbol)
|
@@ -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 =
|
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
|
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
|
-
|
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:
|
28
|
+
# cards: false
|
25
29
|
def display
|
26
30
|
@display ||= (options[:input].delete(:cards) ? :cards : :rows)
|
27
31
|
end
|
28
32
|
|
29
|
-
#
|
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
|
-
#
|
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?)].
|
104
|
+
[*(link_to_add(block) if add?), *(link_to_reorder(block) if reorder?)].join(' ').html_safe
|
81
105
|
end
|
82
106
|
end
|
83
107
|
|
@@ -93,7 +117,7 @@ module Effective
|
|
93
117
|
fields
|
94
118
|
end
|
95
119
|
|
96
|
-
remove += link_to_remove(resource) if remove?
|
120
|
+
remove += link_to_remove(resource) if (remove? || resource.new_record?)
|
97
121
|
|
98
122
|
content_tag(:div, render_fields(content, remove), class: 'has-many-fields')
|
99
123
|
end
|
@@ -115,9 +139,14 @@ module Effective
|
|
115
139
|
|
116
140
|
def render_template(block)
|
117
141
|
resource = build_resource()
|
118
|
-
index =
|
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
|
-
|
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
|
@@ -3,11 +3,25 @@ module Effective
|
|
3
3
|
class PasswordField < Effective::FormInput
|
4
4
|
|
5
5
|
def input_html_options
|
6
|
-
{ class: 'form-control', id: tag_id }
|
6
|
+
{ class: 'form-control effective_password', id: tag_id }
|
7
7
|
end
|
8
8
|
|
9
9
|
def input_group_options
|
10
|
-
{ input_group: { class: 'input-group' },
|
10
|
+
{ input_group: { class: 'input-group' }, append: eyes }
|
11
|
+
end
|
12
|
+
|
13
|
+
def eyes
|
14
|
+
content_tag(:button, icon('eye'),
|
15
|
+
class: 'btn input-group-text',
|
16
|
+
title: 'Show password',
|
17
|
+
'data-effective-password': 'text'
|
18
|
+
) +
|
19
|
+
content_tag(:button, icon('eye-off'),
|
20
|
+
class: 'btn input-group-text',
|
21
|
+
title: 'Hide password',
|
22
|
+
style: 'display: none;',
|
23
|
+
'data-effective-password': 'password'
|
24
|
+
)
|
11
25
|
end
|
12
26
|
|
13
27
|
def feedback_options
|
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.
|
4
|
+
version: 0.9.15
|
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-
|
11
|
+
date: 2021-02-24 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
|
@@ -426,6 +440,8 @@ files:
|
|
426
440
|
- app/assets/javascripts/effective_integer/input.js
|
427
441
|
- app/assets/javascripts/effective_number_text/initialize.js.coffee
|
428
442
|
- app/assets/javascripts/effective_number_text/input.js
|
443
|
+
- app/assets/javascripts/effective_password/initialize.js.coffee
|
444
|
+
- app/assets/javascripts/effective_password/input.js
|
429
445
|
- app/assets/javascripts/effective_percent/initialize.js.coffee
|
430
446
|
- app/assets/javascripts/effective_percent/input.js
|
431
447
|
- app/assets/javascripts/effective_phone/initialize.js.coffee
|