turbograft 0.1.12 → 0.1.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1aff9e76ad586eab0a400892c5f596ffeac608b0
|
4
|
+
data.tar.gz: 0e0c807cb3e2b1f6897de5977ae37850225b306c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 161fbc9a0d5312ce29364cabe5689aa8d25f9588b6504c1fde1f1a348c5daf9f47065a08e5533aa3e666d558469923ea9be4e9e26b677b1a80fcbaf5cc7aa238
|
7
|
+
data.tar.gz: 9b2346f149f5ead38e386d5a8fbff973c70075bf33018b94c3125518bc3b39b282d0a86cacc3c68c60c2595a80f78bf62c6ba427b4d07d98eb81597cf3e66b5d
|
data/README.md
CHANGED
@@ -74,12 +74,15 @@ It requires your `<form>`, `<a>`, or `<button>` to be marked up with:
|
|
74
74
|
* `tg-remote`: (optionally valueless for `<form>`, but requires an HTTP method for links) the HTTP method you wish to call on your endpoint
|
75
75
|
* `href`: (if node is `<a>` or `<button>`) the URL of the endpoint you wish to hit
|
76
76
|
* `refresh-on-success`: (optional) The refresh keys to be refreshed, using the body of the response. This is space-delimited
|
77
|
+
* `full-refresh-on-success-except`: (optional) Replaces body except for specififed refresh keys, using the body of the XHR which has succeeded
|
77
78
|
* `refresh-on-error`: (optional) The refresh keys to be refreshed, but using body of XHR which has failed. Only works with error 422. If the XHR returns and error and you do not supply a refresh-on-error, nothing is changed
|
78
79
|
* `full-refresh-on-error-except`: (optional) Replaces body except for specified refresh keys, using the body of the XHR which has failed. Only works with error 422
|
79
80
|
* `remote-once`: (optional) The action will only be performed once. Removes `remote-method` and `remote-once` from element after consumption
|
80
81
|
* `full-refresh`: Rather than using the content of the XHR response for partial page replacement, a full page refresh is performed. If `refresh-on-success` is defined, the page will be reloaded on these keys. If `refresh-on-success` is not defined, a full page refresh is performed. Defaults to true if neither refresh-on-success nor refresh-on-error are provided
|
81
82
|
* `tg-remote-norefresh`: Prevents `Page.refresh()` from being called, allowing methods to be executed without updating client state
|
82
83
|
|
84
|
+
Note that as `refresh-on-*` pertains to partial refreshes and `full-refresh-on-*-except` pertains to full refreshes, they are incompatible with each other and should not be combined.
|
85
|
+
|
83
86
|
### Examples
|
84
87
|
|
85
88
|
Call a remote method:
|
@@ -21,6 +21,7 @@ TurboGraft.handlers.remoteMethodHandler = (ev) ->
|
|
21
21
|
httpUrl: httpUrl
|
22
22
|
fullRefresh: target.getAttribute('full-refresh')?
|
23
23
|
refreshOnSuccess: target.getAttribute('refresh-on-success')
|
24
|
+
refreshOnSuccessExcept: target.getAttribute('full-refresh-on-success-except')
|
24
25
|
refreshOnError: target.getAttribute('refresh-on-error')
|
25
26
|
refreshOnErrorExcept: target.getAttribute('full-refresh-on-error-except')
|
26
27
|
|
@@ -40,6 +41,7 @@ TurboGraft.handlers.remoteFormHandler = (ev) ->
|
|
40
41
|
httpUrl: httpUrl
|
41
42
|
fullRefresh: target.getAttribute('full-refresh')?
|
42
43
|
refreshOnSuccess: target.getAttribute('refresh-on-success')
|
44
|
+
refreshOnSuccessExcept: target.getAttribute('full-refresh-on-success-except')
|
43
45
|
refreshOnError: target.getAttribute('refresh-on-error')
|
44
46
|
refreshOnErrorExcept: target.getAttribute('full-refresh-on-error-except')
|
45
47
|
|
@@ -8,6 +8,7 @@ class TurboGraft.Remote
|
|
8
8
|
@formData = @createPayload(form)
|
9
9
|
|
10
10
|
@refreshOnSuccess = @opts.refreshOnSuccess.split(" ") if @opts.refreshOnSuccess
|
11
|
+
@refreshOnSuccessExcept = @opts.refreshOnSuccessExcept.split(" ") if @opts.refreshOnSuccessExcept
|
11
12
|
@refreshOnError = @opts.refreshOnError.split(" ") if @opts.refreshOnError
|
12
13
|
@refreshOnErrorExcept = @opts.refreshOnErrorExcept.split(" ") if @opts.refreshOnErrorExcept
|
13
14
|
|
@@ -51,8 +52,8 @@ class TurboGraft.Remote
|
|
51
52
|
|
52
53
|
createPayload: (form) ->
|
53
54
|
if form
|
54
|
-
if form.querySelectorAll("[type='file']").length > 0
|
55
|
-
formData =
|
55
|
+
if form.querySelectorAll("[type='file'][name]").length > 0
|
56
|
+
formData = @nativeEncodeForm(form)
|
56
57
|
else # for much smaller payloads
|
57
58
|
formData = @uriEncodeForm(form)
|
58
59
|
else
|
@@ -70,6 +71,25 @@ class TurboGraft.Remote
|
|
70
71
|
|
71
72
|
uriEncodeForm: (form) ->
|
72
73
|
formData = ""
|
74
|
+
@_iterateOverFormInputs form, (input) =>
|
75
|
+
formData = @formAppend(formData, input.name, input.value)
|
76
|
+
formData
|
77
|
+
|
78
|
+
formDataAppend: (formData, input) ->
|
79
|
+
if input.type == 'file'
|
80
|
+
for file in input.files
|
81
|
+
formData.append(input.name, file)
|
82
|
+
else
|
83
|
+
formData.append(input.name, input.value)
|
84
|
+
formData
|
85
|
+
|
86
|
+
nativeEncodeForm: (form) ->
|
87
|
+
formData = new FormData
|
88
|
+
@_iterateOverFormInputs form, (input) =>
|
89
|
+
formData = @formDataAppend(formData, input)
|
90
|
+
formData
|
91
|
+
|
92
|
+
_iterateOverFormInputs: (form, callback) ->
|
73
93
|
inputs = form.querySelectorAll("input:not([type='reset']):not([type='button']):not([type='submit']):not([type='image']), select, textarea")
|
74
94
|
for input in inputs
|
75
95
|
inputEnabled = !input.disabled
|
@@ -77,9 +97,7 @@ class TurboGraft.Remote
|
|
77
97
|
|
78
98
|
if inputEnabled && input.name
|
79
99
|
if (radioOrCheck && input.checked) || !radioOrCheck
|
80
|
-
|
81
|
-
|
82
|
-
formData
|
100
|
+
callback(input)
|
83
101
|
|
84
102
|
onSuccess: (ev) ->
|
85
103
|
@opts.success?()
|
@@ -102,6 +120,10 @@ class TurboGraft.Remote
|
|
102
120
|
Page.refresh
|
103
121
|
response: xhr
|
104
122
|
onlyKeys: @refreshOnSuccess
|
123
|
+
else if @refreshOnSuccessExcept
|
124
|
+
Page.refresh
|
125
|
+
response: xhr
|
126
|
+
exceptKeys: @refreshOnSuccessExcept
|
105
127
|
else
|
106
128
|
Page.refresh
|
107
129
|
response: xhr
|
@@ -114,10 +136,13 @@ class TurboGraft.Remote
|
|
114
136
|
initiator: @initiator
|
115
137
|
xhr: xhr
|
116
138
|
|
117
|
-
if @refreshOnError
|
139
|
+
if @refreshOnError
|
118
140
|
Page.refresh
|
119
141
|
response: xhr
|
120
142
|
onlyKeys: @refreshOnError
|
143
|
+
else if @refreshOnErrorExcept
|
144
|
+
Page.refresh
|
145
|
+
response: xhr
|
121
146
|
exceptKeys: @refreshOnErrorExcept
|
122
147
|
else
|
123
148
|
triggerEventFor 'turbograft:remote:fail:unhandled', @initiator,
|
data/lib/turbograft/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: turbograft
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.14
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kristian Plettenberg-Dussault
|
@@ -13,7 +13,7 @@ authors:
|
|
13
13
|
autorequire:
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
|
-
date: 2015-
|
16
|
+
date: 2015-02-09 00:00:00.000000000 Z
|
17
17
|
dependencies:
|
18
18
|
- !ruby/object:Gem::Dependency
|
19
19
|
name: coffee-rails
|