effective_bootstrap 0.0.10 → 0.0.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
  SHA1:
3
- metadata.gz: 23f8e41cf8f717cebc0a37b69649827039f10450
4
- data.tar.gz: dedfaa4742860d88677c5d7900ae0826c28dad01
3
+ metadata.gz: 53dac1bf08b5c60e5a707d5ca15430ee6ebd8854
4
+ data.tar.gz: 149db5e6e0c9780ebda2506321969933d13d551e
5
5
  SHA512:
6
- metadata.gz: b9a8b2f4057bdd82d4c169ef3f412643483df43060fe96d77b1be1fdf07ffe8764fe5f89e68ea1e6e1ce5d91332b74c0fb5bdbc2117346262c17fb3ebef1e87c
7
- data.tar.gz: 2f4b5d343cb64101e1f4733fcecce8dbac86ccc40cd369f1bd408fd6efa288192a030b01fd92271e0fae1d2a8e00711cd49e220188ba9c11ede12703ff14310f
6
+ metadata.gz: e765a1fc74612b5f85eacc613449ae35b4e24c560483e51e5b236b59e1fa87dfa60aaef59b85bfa8e2b576be0405f4a1de143c60d4feb24d6a176dcd9a3ae38f
7
+ data.tar.gz: 9bc6d5fef8d632064f1b8f0ebb99e57525517855b343ccd770b6a22e7f0c2971bfab2ab1b97a08071f37957884a84cf4978a6ac4ca6096619ba405a4023cc079
@@ -1,4 +1,5 @@
1
1
  //= require ./effective_bootstrap/base
2
+ //= require ./effective_bootstrap/form
2
3
 
3
4
  //= require ./effective_datetime/input
4
5
  //= require ./effective_date/input
@@ -1,8 +1,4 @@
1
1
  this.EffectiveBootstrap ||= new class
2
- current_submit: '' # The $(.form-actions) that clicked
3
- remote_form_payload: '' # A fresh form
4
- remote_form_flash: '' # Array of Arrays
5
-
6
2
  initialize: (target) ->
7
3
  $(target || document).find('[data-input-js-options]:not(.initialized)').each (i, element) ->
8
4
  $element = $(element)
@@ -17,112 +13,28 @@ this.EffectiveBootstrap ||= new class
17
13
  EffectiveBootstrap[method_name].call(this, $element, options)
18
14
  $element.addClass('initialized')
19
15
 
20
- validate: (form) ->
21
- valid = form.checkValidity()
22
- $form = $(form)
23
-
24
- @clearFlash()
25
- @reset($form) if $form.hasClass('was-validated')
26
-
27
- if valid then @submitting($form) else @invalidate($form)
28
- valid
29
-
30
- submitting: ($form) ->
31
- $form.addClass('form-is-valid').removeClass('form-is-invalid')
32
- @spin()
33
- setTimeout((-> EffectiveBootstrap.disable($form)), 0)
34
-
35
- invalidate: ($form) ->
36
- $form.addClass('was-validated').addClass('form-is-invalid')
37
- $form.find('.form-current-submit').removeClass('form-current-submit')
38
-
39
- # These controls need a little bit of help with client side validations
40
- $form.find('.effective-radios:not(.no-feedback),.effective-checks:not(.no-feedback)').each ->
41
- $(@).addClass(if $(@).find('input:invalid').length > 0 then 'is-invalid' else 'is-valid')
42
-
43
- @flash($form, 'danger')
44
-
45
- disable: ($form) ->
46
- $form.find('[type=submit]').prop('disabled', true)
47
-
48
- reset: ($form) ->
49
- $form.removeClass('was-validated').removeClass('form-is-invalid').removeClass('form-is-valid')
50
- $form.find('.form-current-submit').removeClass('form-current-submit')
51
-
52
- # Clear any server side validation on individual inputs
53
- $form.find('.alert.is-invalid').remove()
54
- $form.find('.is-invalid').removeClass('is-invalid')
55
- $form.find('.is-valid').removeClass('is-valid')
56
-
57
- $form.find('[type=submit]').removeAttr('disabled')
58
-
59
- spin: -> @current_submit.addClass('form-current-submit') if @current_submit.length > 0
60
-
61
- beforeAjax: ($form) ->
62
- return unless $form.data('remote')
63
-
64
- $form.one 'ajax:success', (event, thing, another) ->
65
- EffectiveBootstrap.loadFromAjax($(event.target), $(event.target).data('method') == 'delete')
66
-
67
- $form.one 'ajax:error', (event, _, status, message) ->
68
- EffectiveBootstrap.reset($(event.target))
69
- EffectiveBootstrap.flash($(event.target), 'danger', "Ajax #{status}: #{message}")
70
-
71
- # Loads remote for payload that was placed here by effective_resources create.js.erb and update.js.erb
72
- loadFromAjax: ($target, was_delete) ->
73
- $target = $target.closest('form') unless $target.is('form')
74
-
75
- if @remote_form_payload.length > 0
76
- $form = @remote_form_payload.find("form[data-remote-index='#{$target.data('remote-index')}']")
77
- $form = @remote_form_payload.find('form') if $form.length == 0
78
- $target.replaceWith($form)
79
-
80
- # We update the current submit to point to the new one.
81
- unless was_delete
82
- if @current_submit.length > 0
83
- @current_submit = $form.find("##{@current_submit.attr('id')}.form-actions")
84
-
85
- if @remote_form_flash.length > 0 && was_delete == false
86
- for flash in @remote_form_flash
87
- @flash($form, flash[0], flash[1], true)
88
-
89
- @remote_form_payload = ''; @remote_form_flash = ''; @current_submit = '';
90
-
91
- flash: ($form, status, message, skip_success = false) ->
92
- if status == 'danger' || status == 'error'
93
- @current_submit.find('.eb-icon-x').show().delay(1000).fadeOut('slow')
94
- else
95
- @current_submit.find('.eb-icon-check').show().delay(1000).fadeOut('slow')
96
-
97
- if message? && !(status == 'success' && skip_success)
98
- @current_submit.prepend(@buildFlash(status, message))
99
-
100
- clearFlash: -> @current_submit.find('.alert').remove() if @current_submit.length > 0
101
-
102
- buildFlash: (status, message) ->
103
- $("
104
- <div class='alert alert-dismissable alert-#{status} fade show' role='alert'>
105
- #{message}
106
- <button class='close' type='button' aria-label='Close' data-dismiss='alert'>
107
- <span aria-hidden='true'>&times;</span>
108
- </button>
109
- </div>
110
- ")
111
-
112
- setCurrentSubmit: ($submit) -> @current_submit = $submit if $submit.is('.form-actions')
113
-
114
16
  $ -> EffectiveBootstrap.initialize()
115
17
  $(document).on 'turbolinks:load', -> EffectiveBootstrap.initialize()
116
18
  $(document).on 'cocoon:after-insert', -> EffectiveBootstrap.initialize()
117
19
  $(document).on 'effective-bootstrap:initialize', (event) -> EffectiveBootstrap.initialize(event.currentTarget)
118
20
 
119
- # Sets EffectiveBootstrap. current_click.
120
- # This displays the spinner here, and directs any flash messages before and after loadRemoteForm
121
- $(document).on 'click', '.form-actions a[data-remote],.form-actions button[type=submit]', (event) ->
122
- EffectiveBootstrap.setCurrentSubmit($(@).parent())
123
- EffectiveBootstrap.spin()
124
-
125
- # This actually attached the handlers to a remote ajax form when it or an action inside it triggers a remote thing.
126
- $(document).on 'ajax:beforeSend', 'form[data-remote]', (event) ->
127
- EffectiveBootstrap.beforeAjax($(@))
128
- this.checkValidity()
21
+ # These next two three methods hijack jquery_ujs data-confirm and do it our own way with a double click confirm
22
+ $(document).on 'confirm', (event) ->
23
+ $obj = $(event.target)
24
+
25
+ if $obj.data('confirmed')
26
+ true
27
+ else
28
+ $obj.data('confirm-original', $obj.html())
29
+ $obj.html($obj.data('confirm'))
30
+ $obj.data('confirmed', true)
31
+ setTimeout(
32
+ (->
33
+ $obj.data('confirmed', false)
34
+ $obj.html($obj.data('confirm-original'))
35
+ )
36
+ , 4000)
37
+ false # don't show the confirmation dialog
38
+
39
+ $.rails.confirm = (message) -> true
40
+ $(document).on 'confirm:complete', (event) -> $(event.target).data('confirmed')
@@ -0,0 +1,113 @@
1
+ this.EffectiveForm ||= new class
2
+ current_submit: '' # The $(.form-actions) that clicked
3
+ remote_form_payload: '' # A fresh form
4
+ remote_form_flash: '' # Array of Arrays
5
+
6
+ validate: (form) ->
7
+ valid = form.checkValidity()
8
+ $form = $(form)
9
+
10
+ @clearFlash()
11
+ @reset($form) if $form.hasClass('was-validated')
12
+
13
+ if valid then @submitting($form) else @invalidate($form)
14
+ valid
15
+
16
+ submitting: ($form) ->
17
+ $form.addClass('form-is-valid').removeClass('form-is-invalid')
18
+ @spin()
19
+ setTimeout((-> EffectiveForm.disable($form)), 0)
20
+
21
+ invalidate: ($form) ->
22
+ $form.addClass('was-validated').addClass('form-is-invalid')
23
+ $form.find('.form-current-submit').removeClass('form-current-submit')
24
+
25
+ # These controls need a little bit of help with client side validations
26
+ $form.find('.effective-radios:not(.no-feedback),.effective-checks:not(.no-feedback)').each ->
27
+ $(@).addClass(if $(@).find('input:invalid').length > 0 then 'is-invalid' else 'is-valid')
28
+
29
+ @flash($form, 'danger')
30
+
31
+ disable: ($form) ->
32
+ $form.find('[type=submit]').prop('disabled', true)
33
+
34
+ reset: ($form) ->
35
+ $form = $form.closest('form') unless $form.is('form')
36
+
37
+ $form.removeClass('was-validated').removeClass('form-is-invalid').removeClass('form-is-valid')
38
+ $form.find('.form-current-submit').removeClass('form-current-submit')
39
+
40
+ # Clear any server side validation on individual inputs
41
+ $form.find('.alert.is-invalid').remove()
42
+ $form.find('.is-invalid').removeClass('is-invalid')
43
+ $form.find('.is-valid').removeClass('is-valid')
44
+
45
+ $form.find('[type=submit]').removeAttr('disabled')
46
+
47
+ spin: -> @current_submit.addClass('form-current-submit') if @current_submit.length > 0
48
+
49
+ beforeAjax: ($form) ->
50
+ return unless $form.data('remote')
51
+
52
+ $form.one 'ajax:success', (event, thing, another) ->
53
+ EffectiveForm.loadFromAjax($(event.target), $(event.target).data('method') == 'delete')
54
+
55
+ $form.one 'ajax:error', (event, _, status, message) ->
56
+ EffectiveForm.reset($(event.target))
57
+ EffectiveForm.flash($(event.target), 'danger', "#{status}: #{message || 'unable to contact server. please refresh the page and try again.'}")
58
+
59
+ # Loads remote for payload that was placed here by effective_resources create.js.erb and update.js.erb
60
+ loadFromAjax: ($target, was_delete) ->
61
+ $target = $target.closest('form') unless $target.is('form')
62
+
63
+ if @remote_form_payload.length > 0
64
+ $form = @remote_form_payload.find("form[data-remote-index='#{$target.data('remote-index')}']")
65
+ $form = @remote_form_payload.find('form') if $form.length == 0
66
+ if $form.length > 0
67
+ EffectiveBootstrap.initialize($form)
68
+ $target.replaceWith($form)
69
+
70
+ # We update the current submit to point to the new one.
71
+ unless was_delete
72
+ if @current_submit.length > 0
73
+ @current_submit = $form.find("##{@current_submit.attr('id')}.form-actions")
74
+
75
+ if @remote_form_flash.length > 0 && was_delete == false
76
+ for flash in @remote_form_flash
77
+ @flash($form, flash[0], flash[1], true)
78
+
79
+ @remote_form_payload = ''; @remote_form_flash = ''; @current_submit = '';
80
+
81
+ flash: ($form, status, message, skip_success = false) ->
82
+ if status == 'danger' || status == 'error'
83
+ @current_submit.find('.eb-icon-x').show().delay(1000).fadeOut('slow')
84
+ else
85
+ @current_submit.find('.eb-icon-check').show().delay(1000).fadeOut('slow')
86
+
87
+ if message? && !(status == 'success' && skip_success)
88
+ @current_submit.prepend(@buildFlash(status, message))
89
+
90
+ clearFlash: -> @current_submit.find('.alert').remove() if @current_submit.length > 0
91
+
92
+ buildFlash: (status, message) ->
93
+ $("
94
+ <div class='alert alert-dismissable alert-#{status} fade show' role='alert'>
95
+ #{message}
96
+ <button class='close' type='button' aria-label='Close' data-dismiss='alert'>
97
+ <span aria-hidden='true'>&times;</span>
98
+ </button>
99
+ </div>
100
+ ")
101
+
102
+ setCurrentSubmit: ($submit) -> @current_submit = $submit if $submit.is('.form-actions')
103
+
104
+ # Sets EffectiveBootstrap. current_click.
105
+ # This displays the spinner here, and directs any flash messages before and after loadRemoteForm
106
+ $(document).on 'click', '.form-actions a[data-remote],.form-actions button[type=submit]', (event) ->
107
+ EffectiveForm.setCurrentSubmit($(@).parent())
108
+ EffectiveForm.spin()
109
+
110
+ # This actually attached the handlers to a remote ajax form when it or an action inside it triggers a remote thing.
111
+ $(document).on 'ajax:beforeSend', 'form[data-remote]', (event) ->
112
+ EffectiveForm.beforeAjax($(@))
113
+ this.checkValidity()
@@ -36,15 +36,15 @@
36
36
  }
37
37
 
38
38
  .form-actions.justify-content-start {
39
- > a,button { margin-right: 0.5em; }
39
+ > a,button { margin-right: 0.5em; } // Not svg
40
40
  }
41
41
 
42
42
  .form-actions.justify-content-end {
43
- > a,button { margin-left: 0.5em; }
43
+ > a,button { margin-left: 0.5em; } // Not svg
44
44
  }
45
45
 
46
46
  .form-actions.justify-content-center {
47
- > a,button { margin-left: 0.5em; }
47
+ > a,button { margin-left: 0.5em; } // Not svg
48
48
  }
49
49
 
50
50
  // Spinner
@@ -52,16 +52,11 @@
52
52
  .form-actions.form-current-submit .eb-icon-spinner { display: inline; }
53
53
 
54
54
  // Radio and Checkbox fieldsets
55
- fieldset.form-group > label {
56
- display: block;
57
- }
58
-
59
- div.form-group > label + .btn-group {
60
- display: block;
61
- }
55
+ fieldset.form-group > label { display: block; }
56
+ div.form-group > label + .btn-group { display: block; }
62
57
 
63
- .effective-radios.is-invalid ~ .invalid-feedback { display: block }
64
- .effective-radios.is-valid ~ .valid-feedback { display: block }
58
+ .effective-radios.is-invalid ~ .invalid-feedback { display: block; }
59
+ .effective-radios.is-valid ~ .valid-feedback { display: block; }
65
60
 
66
- .effective-checks.is-invalid .invalid-feedback { display: block }
67
- .effective-checks.is-valid .valid-feedback { display: block }
61
+ .effective-checks.is-invalid .invalid-feedback { display: block; }
62
+ .effective-checks.is-valid .valid-feedback { display: block; }
@@ -1,7 +1,7 @@
1
1
  module EffectiveFormBuilderHelper
2
2
  def effective_form_with(**options, &block)
3
3
  options[:class] = [options[:class], 'needs-validation', ('form-inline' if options[:layout] == :inline)].compact.join(' ')
4
- options[:html] = (options[:html] || {}).merge(novalidate: true, onsubmit: 'return EffectiveBootstrap.validate(this);')
4
+ options[:html] = (options[:html] || {}).merge(novalidate: true, onsubmit: 'return EffectiveForm.validate(this);')
5
5
 
6
6
  if options.delete(:remote) == true
7
7
  @_effective_remote_index ||= 0
@@ -58,6 +58,12 @@ module Effective
58
58
  Effective::FormInputs::FormGroup.new(name, options, builder: self).to_html(&block)
59
59
  end
60
60
 
61
+ # This is gonna be a post?
62
+ def remote_link_to(name, url, options = {}, &block)
63
+ options[:href] ||= url
64
+ Effective::FormInputs::RemoteLinkTo.new(name, options, builder: self).to_html(&block)
65
+ end
66
+
61
67
  def number_field(name, options = {})
62
68
  Effective::FormInputs::NumberField.new(name, options, builder: self).to_html { super(name, options) }
63
69
  end
@@ -1,10 +1,6 @@
1
1
  module Effective
2
2
  module FormInputs
3
- class Delete < Effective::FormInput
4
-
5
- def to_html(&block)
6
- return super unless (form_readonly? || form_disabled?)
7
- end
3
+ class Delete < Submit
8
4
 
9
5
  def build_input(&block)
10
6
  tags = [
@@ -17,71 +13,14 @@ module Effective
17
13
  (left? ? tags.reverse.join : tags.join).html_safe
18
14
  end
19
15
 
20
- def label_options
21
- false
22
- end
23
-
24
- def wrapper_options
25
- @right = true unless (left? || center? || right?)
26
-
27
- classes = [
28
- ('row' if layout == :horizontal),
29
- 'form-group form-actions',
30
- ('form-actions-inline' if inline?),
31
- ('form-actions-bordered' if border?),
32
- ('justify-content-start' if left? && layout == :vertical),
33
- ('justify-content-center' if center? && layout == :vertical),
34
- ('justify-content-end' if right? && layout == :vertical)
35
- ].compact.join(' ')
36
-
37
- { class: classes, id: tag_id }
38
- end
39
-
40
16
  def input_html_options
41
- { class: 'btn btn-warning', data: { method: :delete, remote: true, confirm: "Delete #{object}?"} }
17
+ { class: 'btn btn-warning', data: { method: :delete, remote: true, confirm: "Really delete<br>#{object}?".html_safe } }
42
18
  end
43
19
 
44
20
  def border?
45
21
  false
46
22
  end
47
23
 
48
- def inline?
49
- return @form_actions_inline unless @form_actions_inline.nil?
50
- @form_actions_inline = (options.delete(:inline) || false)
51
- end
52
-
53
- def left?
54
- return @left unless @left.nil?
55
- @left = (options.delete(:left) || false)
56
- end
57
-
58
- def center?
59
- return @center unless @center.nil?
60
- @center = (options.delete(:center) || false)
61
- end
62
-
63
- def right?
64
- return @right unless @right.nil?
65
- @right = (options.delete(:right) || false)
66
- end
67
-
68
- def feedback_options
69
- # case layout
70
- # when :inline
71
- # false
72
- # else
73
- # {
74
- # valid: { class: 'valid-feedback', text: 'Looks good! Submitting...' },
75
- # invalid: {
76
- # class: 'invalid-feedback',
77
- # text: 'one or more errors are present. please fix the errors above and try again.'
78
- # }
79
- # }
80
- # end
81
- false
82
- end
83
-
84
-
85
24
  end
86
25
  end
87
26
  end
@@ -0,0 +1,30 @@
1
+ module Effective
2
+ module FormInputs
3
+ class RemoteLinkTo < Submit
4
+
5
+ def build_input(&block)
6
+ tags = [
7
+ icon('check', style: 'display: none;'),
8
+ icon('x', style: 'display: none;'),
9
+ icon('spinner'),
10
+ (block_given? ? capture(&block) : content_tag(:a, name, options[:input]))
11
+ ]
12
+
13
+ (left? ? tags.reverse.join : tags.join).html_safe
14
+ end
15
+
16
+ def input_html_options
17
+ { class: '', rel: 'nofollow', data: { method: :post, remote: true, confirm: confirm } }
18
+ end
19
+
20
+ def border?
21
+ false
22
+ end
23
+
24
+ def confirm
25
+ (options.delete(:confirm) || "#{name} to<br>#{object}?").html_safe
26
+ end
27
+
28
+ end
29
+ end
30
+ end
@@ -1,3 +1,3 @@
1
1
  module EffectiveBootstrap
2
- VERSION = '0.0.10'.freeze
2
+ VERSION = '0.0.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.0.10
4
+ version: 0.0.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: 2018-04-23 00:00:00.000000000 Z
11
+ date: 2018-04-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -369,6 +369,7 @@ files:
369
369
  - app/assets/images/icons/zoom-out.svg
370
370
  - app/assets/javascripts/effective_bootstrap.js
371
371
  - app/assets/javascripts/effective_bootstrap/base.js.coffee
372
+ - app/assets/javascripts/effective_bootstrap/form.js.coffee
372
373
  - app/assets/javascripts/effective_date/initialize.js.coffee
373
374
  - app/assets/javascripts/effective_date/input.js
374
375
  - app/assets/javascripts/effective_datetime/bootstrap-datetimepicker.js
@@ -429,6 +430,7 @@ files:
429
430
  - app/models/effective/form_inputs/phone_field.rb
430
431
  - app/models/effective/form_inputs/price_field.rb
431
432
  - app/models/effective/form_inputs/radios.rb
433
+ - app/models/effective/form_inputs/remote_link_to.rb
432
434
  - app/models/effective/form_inputs/save.rb
433
435
  - app/models/effective/form_inputs/select.rb
434
436
  - app/models/effective/form_inputs/static_field.rb