sweet-alert-confirm 0.0.3 → 0.1.0

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: 32e9ada7f2a5dde5e4b65cc1b3e2dcfe50f2e528
4
- data.tar.gz: eb855c29b0a13b04e434d53f4130c4c7c4b9b2e0
3
+ metadata.gz: 79d4562caf3b1e3cecbf4c9d92fe3384d416c318
4
+ data.tar.gz: 049049199569fe95b9594d134b4d6841e2795c89
5
5
  SHA512:
6
- metadata.gz: 6e46869d170b981debe6426a8e1ea21d2760032e20c2aa4b9e034b14bb80ce890e27aeecbed91e453721188dd499df25aacb236719847771024119c563ffd4ee
7
- data.tar.gz: c453374d66b91d4f3f491a8e9112c9557b8a0bbceef0ae6b093792c39144c5a759513967a8872227ffafc08a0df7b580be86afe9ab248eb8dc698b0d624a9e26
6
+ metadata.gz: 5c65648175a8152da2da0dacf0e08d1386a8926f13e7d2f90398025db361919065cc095f2698990fa51874e8234928f9d2a19ab818a46ccb26c3ef13b6f4cc68
7
+ data.tar.gz: e6fc7263994d927fdd0b26b7f6f34a9b2face824aa12643f4bab822ba62c64801c7d22d39cc48a06d932ce3db48cb914a2b70eb4d05bb68dd9f65719c4e38e54
data/README.md CHANGED
@@ -40,7 +40,7 @@ You can pass options in `data:`
40
40
  :'confirm-button-text' => 'Im ready',
41
41
  :'cancel-button-text' => 'No way',
42
42
  :'confirm-button-color' => '#66CD00',
43
- type: 'info',
43
+ :'sweet-alert-type' => 'info',
44
44
  text: 'This is a subtitle',
45
45
  :'image-url' => '/pic.png'
46
46
 
@@ -49,4 +49,11 @@ You can pass options in `data:`
49
49
 
50
50
  ![Custom confirm](https://cloud.githubusercontent.com/assets/5833678/4653700/14389916-54b0-11e4-9850-14ee970e9345.png)
51
51
 
52
+ ## Contribute
53
+
54
+ Fork the repo & pull request you fix/feature
55
+
56
+ append `RAILS_VERSION=4.1.2` or whichever you target before your `bundle` command ex: `RAILS_VERSION=4.1.2 bundle install`
57
+
58
+ please add/modify test examples on fix or features
52
59
 
@@ -16,7 +16,7 @@
16
16
  var optionKeys = [
17
17
  'confirm',
18
18
  'text',
19
- 'type',
19
+ 'sweetAlertType',
20
20
  'showCancelButton',
21
21
  'confirmButtonColor',
22
22
  'cancelButtonColor',
@@ -32,6 +32,10 @@
32
32
  $.each($linkToVerify.data(), function(key, val){
33
33
  if ($.inArray(key, optionKeys) >= 0) {
34
34
  swalOptions[key] = val
35
+ if (key == 'sweetAlertType') {
36
+ swalOptions['type'] = val;
37
+ }
38
+
35
39
  }
36
40
  })
37
41
 
@@ -57,7 +61,16 @@
57
61
  if (r === false) {
58
62
  return false;
59
63
  } else {
60
- window.location.href = $linkToVerify.attr('href');
64
+ if($linkToVerify.is('input')){
65
+ var name = $linkToVerify.attr('name'),
66
+ data = name ? {name: name, value:$linkToVerify.val()} : null;
67
+ $linkToVerify.closest('form').data('ujs:submit-button', data);
68
+ $linkToVerify.closest('form').submit();
69
+ }
70
+ else {
71
+ window.location.href = $linkToVerify.attr('href');
72
+ }
73
+
61
74
  }
62
75
  }
63
76
  });
@@ -66,9 +79,11 @@
66
79
  //});
67
80
  //return this;
68
81
  }
69
- $(document).ready(function(){
70
- //$("a[data-sweet-alert-confirm]").sweetAlertConfirm();
71
- $('a[data-sweet-alert-confirm]').on('click', sweetAlertConfirm)
82
+
83
+ $(document).on('ready page:change ajaxComplete', function() {
84
+ $('[data-sweet-alert-confirm]').on('click', sweetAlertConfirm)
85
+ //To avoid "Uncaught TypeError: Cannot read property 'querySelector' of null" on turbolinks
86
+ window.sweetAlertInitialize();
72
87
  });
73
88
 
74
89
  })( jQuery );
@@ -1,3 +1,3 @@
1
1
  module SweetAlertConfirm
2
- VERSION = "0.0.3"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -2,13 +2,26 @@ module SweetAlertConfirm
2
2
  module ViewHelpers
3
3
  def link_to(*args, &block)
4
4
  html_options = args[block_given? ? 1 : 2] || {}
5
- if (html_options[:confirm] || (html_options[:data] && html_options[:data][:confirm]) &&
6
- !html_options[:remote])
7
5
 
6
+ if options_has_confirm?(html_options)
8
7
  html_options['data-sweet-alert-confirm'] = html_options.delete(:confirm) ||
9
8
  html_options[:data].delete(:confirm)
10
9
  end
11
10
  super *args, &block
12
11
  end
12
+
13
+ def submit_tag(value = "Save changes", options = {})
14
+ options['data-sweet-alert-confirm'] = options.delete(:confirm) || options[:data].delete(:confirm) if options_has_confirm?(options)
15
+ super value, options
16
+ end
17
+
18
+ protected
19
+ def options_has_confirm?(options)
20
+ if (options[:confirm] || (options[:data] && options[:data][:confirm]))
21
+ true
22
+ else
23
+ false
24
+ end
25
+ end
13
26
  end
14
27
  end
@@ -1,11 +1,15 @@
1
1
  <%= link_to 'Basic confirm', get_cow_path, id: 'basic-confirm', data: { text: 'nanana', confirm: 'Are you sure?' } %>
2
2
  <%= link_to 'Delete confirm', delete_cow_path,method: :delete, id: 'method-confirm', data: { text: 'nanana', confirm: 'Are you sure?' } %>
3
- <%= link_to 'Remote confirm', delete_cow_path,method: :delete, id: 'remote-confirm', data: { remote: 'true', text: 'nanana', confirm: 'Are you sure?' } %>
3
+ <%= link_to 'Remote confirm', delete_cow_path,method: :delete, id: 'remote-confirm', data: { remote: 'true', 'sweet-alert-type' => 'info', text: 'nanana', confirm: 'Are you sure?' } %>
4
4
  <%= link_to 'Custom confirm', get_cow_path, id: 'custom-confirm', data: {
5
5
  :'confirm-button-text' => 'Im ready',
6
6
  :'cancel-button-text' => 'No way',
7
7
  :'confirm-button-color' => '#66CD00',
8
- type: 'info',
8
+ :'sweet-alert-type' => 'info',
9
9
  text: 'This is a subtitle',
10
10
  confirm: 'Are you ready?'
11
11
  } %>
12
+
13
+ <%= form_tag(delete_cow_path, method: :delete) do %>
14
+ <%= submit_tag 'Submit to delete cow', id: 'submit-delete', data: {confirm: 'Are you sure?'} %>
15
+ <% end %>
@@ -1,11 +1,15 @@
1
1
  <%= link_to 'Basic confirm', get_cow_path, id: 'basic-confirm', data: { text: 'nanana', confirm: 'Are you sure?' } %>
2
2
  <%= link_to 'Delete confirm', delete_cow_path,method: :delete, id: 'method-confirm', data: { text: 'nanana', confirm: 'Are you sure?' } %>
3
- <%= link_to 'Remote confirm', delete_cow_path,method: :delete, id: 'remote-confirm', data: { remote: 'true', text: 'nanana', confirm: 'Are you sure?' } %>
3
+ <%= link_to 'Remote confirm', delete_cow_path,method: :delete, id: 'remote-confirm', data: { remote: 'true', 'sweet-alert-type' => 'warning', text: 'nanana', confirm: 'Are you sure?' } %>
4
4
  <%= link_to 'Custom confirm', get_cow_path, id: 'custom-confirm', data: {
5
5
  :'confirm-button-text' => 'Im ready',
6
6
  :'cancel-button-text' => 'No way',
7
7
  :'confirm-button-color' => '#66CD00',
8
- type: 'info',
8
+ :'sweet-alert-type' => 'info',
9
9
  text: 'This is a subtitle',
10
10
  confirm: 'Are you ready?'
11
11
  } %>
12
+
13
+ <%= form_tag(delete_cow_path, method: :delete) do %>
14
+ <%= submit_tag 'Submit to delete cow', id: 'submit-delete', data: {confirm: 'Are you sure?'} %>
15
+ <% end %>
@@ -105,5 +105,33 @@ describe 'basic confirms', js: true, type: :feature do
105
105
  end
106
106
  end
107
107
 
108
+ describe 'Submit confirm' do
109
+ before do
110
+ visit confirms_page_path
111
+ find("#submit-delete").trigger('click')
112
+ end
113
+ it 'show the alert when click the submit', :js => true do
114
+ sleep 1
115
+ expect(page).to have_content('Are you sure?')
116
+ expect(page).not_to have_content('You murdered a silly cow')
117
+ end
118
+
119
+ it 'does not submit the form when click on cancel' do
120
+ sleep 1
121
+ expect(page).to_not have_content('You murdered a silly cow')
122
+ click_button('Cancel')
123
+ sleep 1
124
+ expect(page).to_not have_content('You murdered a silly cow')
125
+ end
126
+
127
+ it 'submit the form after accept confirm' do
128
+ #click_on '.confirm'
129
+ expect(page).to_not have_content('You murdered a silly cow')
130
+ sleep 1
131
+ click_button('Ok')
132
+ expect(page).to have_content('You murdered a silly cow')
133
+ end
134
+ end
135
+
108
136
  end
109
137
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sweet-alert-confirm
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Moises Viloria
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-23 00:00:00.000000000 Z
11
+ date: 2014-11-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jquery-rails