thin_man 0.17.0 → 0.18.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/assets/javascripts/thin_man.js +80 -0
- data/lib/thin_man/ajax_helper.rb +6 -1
- data/lib/thin_man/version.rb +1 -1
- data/test/javascript/spec/thinManSpec.js +18 -2
- data/test/thin_man_test.rb +9 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 889c8c7807a4ed374dd0bb78ab34768f9f641f66
|
4
|
+
data.tar.gz: cb5199ac9ddd6a2471ca0f91e039d0123270d4e3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2b8c563c47e60e8f4b6167d34c2cc6863671343cfd7cbaca583bed57f7fa56a2283d7c4951904fd9ca9373a6e889fc8f7317710fc2d526ee83ae77e615e6e45b
|
7
|
+
data.tar.gz: ac17499c839a3096abf2d69d4fcea1889b4b290ffc245c1e9298b0e18d11e744427f354b818d083b66d21dab5c497002e963682c86838ab00fc7f42847cd4c9f
|
@@ -8,6 +8,51 @@ var initThinMan = function(){
|
|
8
8
|
}
|
9
9
|
return this_class;
|
10
10
|
},
|
11
|
+
getLinkGroup: function(name){
|
12
|
+
if(thin_man.hasOwnProperty('link_groups') && thin_man.link_groups.hasOwnProperty(name)){
|
13
|
+
return thin_man.link_groups[name]
|
14
|
+
} else {
|
15
|
+
return thin_man.addLinkGroup(name)
|
16
|
+
}
|
17
|
+
},
|
18
|
+
addLinkGroup: function(name){
|
19
|
+
if(!thin_man.hasOwnProperty('link_groups')){
|
20
|
+
thin_man.link_groups = {}
|
21
|
+
}
|
22
|
+
if(!thin_man.link_groups.hasOwnProperty(name)){
|
23
|
+
var this_group = new thin_man.LinkGroup(name)
|
24
|
+
thin_man.link_groups[name] = this_group
|
25
|
+
return this_group
|
26
|
+
}
|
27
|
+
},
|
28
|
+
addLinkToGroup: function(link, sequence_number, group_name){
|
29
|
+
var group = thin_man.getLinkGroup(group_name)
|
30
|
+
group.addLink(link,sequence_number)
|
31
|
+
},
|
32
|
+
LinkGroup: Class.extend({
|
33
|
+
init: function(name){
|
34
|
+
this.name = name
|
35
|
+
this.links = {}
|
36
|
+
this.current_number = 0
|
37
|
+
},
|
38
|
+
addLink: function(link_submission, sequence_number){
|
39
|
+
this.links[sequence_number] = link_submission
|
40
|
+
link_submission.addWatcher(this)
|
41
|
+
if(sequence_number == this.current_number){
|
42
|
+
this.fire()
|
43
|
+
}
|
44
|
+
},
|
45
|
+
fire: function(){
|
46
|
+
if(this.links.hasOwnProperty(this.current_number)){
|
47
|
+
this.links[this.current_number].fire()
|
48
|
+
delete this.links[this.current_number]
|
49
|
+
}
|
50
|
+
},
|
51
|
+
linkCompleted: function(link_submission){
|
52
|
+
this.current_number += 1
|
53
|
+
this.fire()
|
54
|
+
}
|
55
|
+
}),
|
11
56
|
AjaxSubmission: Class.extend({
|
12
57
|
init: function(jq_obj,params){
|
13
58
|
this.jq_obj = jq_obj;
|
@@ -24,6 +69,7 @@ var initThinMan = function(){
|
|
24
69
|
this.progress_target = $(jq_obj.data('progress-target'));
|
25
70
|
this.custom_progress = typeof(jq_obj.data('custom-progress')) != 'undefined';
|
26
71
|
this.scroll_to = jq_obj.data('scroll-to')
|
72
|
+
this.watchers = []
|
27
73
|
if(this.progress_target.length == 0 && this.trigger.length > 0){
|
28
74
|
this.progress_target = this.trigger
|
29
75
|
this.trigger_is_progress_target = true
|
@@ -48,8 +94,30 @@ var initThinMan = function(){
|
|
48
94
|
this.ajax_options.xhr = this.customXHR
|
49
95
|
this.ajax_options.thin_man_obj = this;
|
50
96
|
}
|
97
|
+
this.handleGroup()
|
98
|
+
if(this.readyToFire()){
|
99
|
+
this.fire()
|
100
|
+
}
|
101
|
+
},
|
102
|
+
fire: function(){
|
51
103
|
$.ajax(this.ajax_options);
|
52
104
|
},
|
105
|
+
readyToFire: function(){
|
106
|
+
if(!this.sequence_group){ return true }
|
107
|
+
},
|
108
|
+
handleGroup: function(){
|
109
|
+
this.sequence_group = this.jq_obj.data('sequence-group');
|
110
|
+
this.sequence_number = this.jq_obj.data('sequence-number');
|
111
|
+
if(typeof(this.sequence_number) == 'number' && !this.sequence_group){
|
112
|
+
console.log('Warning! Thin Man Link has sequence number but no sequence group.')
|
113
|
+
}
|
114
|
+
if(this.sequence_group && typeof(this.sequence_number) != 'number'){
|
115
|
+
console.log('Warning! Thin Man Link has sequence group ' + this.sequence_group + ' but no sequence number.')
|
116
|
+
}
|
117
|
+
if(this.sequence_group){
|
118
|
+
thin_man.addLinkToGroup(this, this.sequence_number, this.sequence_group)
|
119
|
+
}
|
120
|
+
},
|
53
121
|
getTarget: function(){
|
54
122
|
var target_selector = this.jq_obj.data('ajax-target');
|
55
123
|
if(target_selector){
|
@@ -173,8 +241,20 @@ var initThinMan = function(){
|
|
173
241
|
this.jq_obj.find('.help-inline').remove()
|
174
242
|
}
|
175
243
|
},
|
244
|
+
addWatcher: function(watcher){
|
245
|
+
if(!this.hasOwnProperty('watchers')){
|
246
|
+
this.watchers = []
|
247
|
+
}
|
248
|
+
this.watchers.push(watcher)
|
249
|
+
},
|
250
|
+
notifyWatchers: function(){
|
251
|
+
$.each(this.watchers, function(){
|
252
|
+
this.linkCompleted(this)
|
253
|
+
})
|
254
|
+
},
|
176
255
|
ajaxComplete: function(jqXHR) {
|
177
256
|
this.showTrigger();
|
257
|
+
this.notifyWatchers();
|
178
258
|
if(this.progress_indicator){
|
179
259
|
this.progress_indicator.stop();
|
180
260
|
} else if(!this.trigger_is_progress_target){
|
data/lib/thin_man/ajax_helper.rb
CHANGED
@@ -21,7 +21,10 @@ module ThinMan
|
|
21
21
|
html_options.merge(ajax_options))
|
22
22
|
end
|
23
23
|
|
24
|
-
def ajax_link_now(name, options, html_options, target,
|
24
|
+
def ajax_link_now(name, options, html_options, target,
|
25
|
+
sub_class: nil, insert_method: nil, empty_on_success: nil,
|
26
|
+
http_method: nil, no_mouse_click: nil, progress_target: nil,
|
27
|
+
progress_color: nil, sequence_group: nil, sequence_number: nil)
|
25
28
|
ajax_options = {
|
26
29
|
'data-ajax-link-now' => true,
|
27
30
|
'data-ajax-target' => target
|
@@ -33,6 +36,8 @@ module ThinMan
|
|
33
36
|
ajax_options.merge!('data-no-mouse-click' => no_mouse_click) if no_mouse_click.present?
|
34
37
|
ajax_options.merge!('data-progress-target' => progress_target) if progress_target.present?
|
35
38
|
ajax_options.merge!('data-progress-color' => progress_color) if progress_color.present?
|
39
|
+
ajax_options.merge!('data-sequence-group' => sequence_group) if sequence_group.present?
|
40
|
+
ajax_options.merge!('data-sequence-number' => sequence_number) if sequence_number.present?
|
36
41
|
link_to(name,
|
37
42
|
options,
|
38
43
|
html_options.merge(ajax_options))
|
data/lib/thin_man/version.rb
CHANGED
@@ -113,10 +113,26 @@ describe("thin_man", function(){
|
|
113
113
|
expect(getAjaxArg("url")).toMatch("/url");
|
114
114
|
expect(getAjaxArg("type")).toMatch("PATCH");
|
115
115
|
expect(getAjaxArg("datatype")).toMatch("json");
|
116
|
+
expect(thin_man.hasOwnProperty('link_groups')).toEqual(false)
|
116
117
|
});
|
117
|
-
|
118
|
+
it("fires grouped links in sequence", function(){
|
119
|
+
var $link_zero = affix('a[data-ajax-link-now="true"][data-ajax-target="#test_dom_id"][href="/url"][data-ajax-method="PATCH"][data-sequence-group="test_group"][data-sequence-number="0"]');
|
120
|
+
var $link_one = affix('a[data-ajax-link-now="true"][data-ajax-target="#test_dom_id"][href="/url"][data-ajax-method="PATCH"][data-sequence-group="test_group"][data-sequence-number="1"]');
|
121
|
+
var $link_two = affix('a[data-ajax-link-now="true"][data-ajax-target="#test_dom_id"][href="/url"][data-ajax-method="PATCH"][data-sequence-group="test_group"][data-sequence-number="2"]');
|
122
|
+
zero = new thin_man.AjaxLinkSubmission($link_zero)
|
123
|
+
one = new thin_man.AjaxLinkSubmission($link_one)
|
124
|
+
two = new thin_man.AjaxLinkSubmission($link_two)
|
125
|
+
expect(thin_man.hasOwnProperty('link_groups')).toEqual(true)
|
126
|
+
spyOn(one,'fire')
|
127
|
+
spyOn(two,'fire')
|
128
|
+
zero.ajaxComplete()
|
129
|
+
expect(one.fire).toHaveBeenCalled();
|
130
|
+
expect(two.fire).not.toHaveBeenCalled();
|
131
|
+
one.ajaxComplete()
|
132
|
+
expect(one.fire.calls.count()).toEqual(1);
|
133
|
+
expect(two.fire).toHaveBeenCalled();
|
134
|
+
})
|
118
135
|
});
|
119
|
-
|
120
136
|
describe("DeleteLink", function(){
|
121
137
|
it("submits an ajax delete call with options", function(){
|
122
138
|
var $link = affix('a[data-ajax-delete="true"][data-ajax-target="#test_dom_id"][href="/url"]');
|
data/test/thin_man_test.rb
CHANGED
@@ -14,6 +14,8 @@ class ThinManTest < ActionView::TestCase
|
|
14
14
|
@progress_target = '#progress_element'
|
15
15
|
@progress_color = 'blue'
|
16
16
|
@scroll_to = true
|
17
|
+
@sequence_group = 'test_group'
|
18
|
+
@sequence_number = 0
|
17
19
|
|
18
20
|
@replace_response = true
|
19
21
|
@no_confirm = true
|
@@ -39,7 +41,11 @@ class ThinManTest < ActionView::TestCase
|
|
39
41
|
end
|
40
42
|
|
41
43
|
it "generates an instant link" do
|
42
|
-
test_link = ajax_link_now('test link', "http://test.com", @html_options, @target,
|
44
|
+
test_link = ajax_link_now('test link', "http://test.com", @html_options, @target,
|
45
|
+
insert_method: @insert_method, empty_on_success: @empty_on_success,
|
46
|
+
http_method: @http_method, progress_target: @progress_target,
|
47
|
+
progress_color: @progress_color, sequence_number: @sequence_number,
|
48
|
+
sequence_group: @sequence_group)
|
43
49
|
test_link.must_match "data-ajax-link-now="
|
44
50
|
test_link.must_match(/class=.test_class./)
|
45
51
|
test_link.must_match "data-ajax-target=\"#{@target}\""
|
@@ -48,6 +54,8 @@ class ThinManTest < ActionView::TestCase
|
|
48
54
|
test_link.must_match "data-ajax-method=\"#{@http_method}\""
|
49
55
|
test_link.must_match "data-progress-target=\"#{@progress_target}\""
|
50
56
|
test_link.must_match "data-progress-color=\"#{@progress_color}\""
|
57
|
+
test_link.must_match "data-sequence-group=\"#{@sequence_group}\""
|
58
|
+
test_link.must_match "data-sequence-number=\"#{@sequence_number}\""
|
51
59
|
end
|
52
60
|
|
53
61
|
it "generates a delete link" do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: thin_man
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.18.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eric Draut, Adam Bialek
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-02-
|
11
|
+
date: 2017-02-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|