rest_in_place 2.3.0 → 2.4.0
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 +8 -8
- data/README.markdown +11 -1
- data/lib/assets/javascripts/rest_in_place/rest_in_place.js.coffee.erb +31 -31
- data/lib/rest_in_place/version.rb +1 -1
- data/rest_in_place.gemspec +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MWMzNGJhY2Q4YmM3ZTM2NWIwMDAzNzQ4ZDJhOTYwZDc3NWNmNTE4ZA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
MWFhNjE4N2M2OTNmNzdjMTJjZGEzNjYwYWZhMzBiOWNmNTAyM2EwMQ==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
MzIxYjM5MGRiNDg4MDBkMWVmNTJhMjM0YTUxZTY5MWRhOTljMWYxNTkyZTRk
|
10
|
+
NGZmNjMzNzhlNDBmZDg4M2U3YjJlNTYzYTM2ZmQzZmEwZGFlOTUxNjg4NDM4
|
11
|
+
ZTU3ZWQ0Mjg3ZjAyNDc5MDY4YjRkYjQyYjdiZThkMWNlMGI1ODI=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
MTdmZTM2NWVjMzRjODA1MjgzODQ2NWUxZGI2NTg4ZDkzYWViMjczOTZhZjRi
|
14
|
+
ZThjZmI5ZjVkZWM4MzVlMThjOTE1YWUwYTg4ODhhMzEzYjg1NWQ5ZTc5M2Rk
|
15
|
+
MzNlMmYzYjY3NTNkZWU3NTk4Yzk4ZTg2MjRiZTJiMzQ0N2I3M2E=
|
data/README.markdown
CHANGED
@@ -166,7 +166,17 @@ it's associated with:
|
|
166
166
|
been restored with the data from the server. This means you can use the
|
167
167
|
event handler to further modify the data and overwrite the displayed value
|
168
168
|
(useful for number/date formatting for example).
|
169
|
-
- `failure.rest-in-place` after an error occured
|
169
|
+
- `failure.rest-in-place` after an error occured. The second argument will be
|
170
|
+
jQuery's responseJSON, so it is possible to handle (for instance) server-side
|
171
|
+
validation errors.
|
172
|
+
|
173
|
+
$('#my-editable-element').bind('failure.rest-in-place', function(event, json) {
|
174
|
+
$el = $(@)
|
175
|
+
attr = $el.data("attribute")
|
176
|
+
error_message = json[attr].join(", ")
|
177
|
+
$el.after("<span class='error'>#{error_message}</span>")
|
178
|
+
});
|
179
|
+
|
170
180
|
- `update.rest-in-place` immediately before sending the update to the server
|
171
181
|
- `abort.rest-in-place` when the user aborts the editing process.
|
172
182
|
|
@@ -8,14 +8,14 @@ class RestInPlaceEditor
|
|
8
8
|
@initOptions()
|
9
9
|
@bindForm()
|
10
10
|
@createClickHandler()
|
11
|
-
|
11
|
+
|
12
12
|
@$element.click(@clickHandler)
|
13
13
|
|
14
14
|
@updateDisplayValue(@$element.text())
|
15
|
-
|
15
|
+
|
16
16
|
# ## Public interface functions ############################################
|
17
|
-
|
18
|
-
# Toggle the element associated with this editor from normal to a form field
|
17
|
+
|
18
|
+
# Toggle the element associated with this editor from normal to a form field
|
19
19
|
activate : ->
|
20
20
|
@oldValue = @elementHTML()
|
21
21
|
@$element.trigger('activate.rest-in-place')
|
@@ -23,14 +23,14 @@ class RestInPlaceEditor
|
|
23
23
|
@$element.unbind('click', @clickHandler)
|
24
24
|
@activateForm()
|
25
25
|
@$element.trigger('ready.rest-in-place')
|
26
|
-
|
26
|
+
|
27
27
|
# Restore the element to its default state
|
28
28
|
abort : ->
|
29
29
|
@$element.trigger('abort.rest-in-place')
|
30
30
|
@updateDisplayValue(@oldValue)
|
31
31
|
@$element.removeClass('rip-active')
|
32
32
|
.click(@clickHandler)
|
33
|
-
|
33
|
+
|
34
34
|
# Take the changes a user has made and send them to the server.
|
35
35
|
# If the server accepted the request but does not send back a
|
36
36
|
# parseable answer, a second request is initiated to retrieve the updated
|
@@ -40,36 +40,36 @@ class RestInPlaceEditor
|
|
40
40
|
updateRequest = @ajax
|
41
41
|
type : "post"
|
42
42
|
data : @requestData()
|
43
|
-
|
43
|
+
|
44
44
|
updateRequest.done (data) =>
|
45
45
|
if data
|
46
46
|
@loadSuccessCallback(data)
|
47
47
|
else
|
48
48
|
@loadViaGET()
|
49
|
-
|
49
|
+
|
50
50
|
updateRequest.fail (jqXHR, textStatus) =>
|
51
51
|
if (jqXHR.status == 200 && textStatus == "parsererror")
|
52
52
|
@loadViaGET()
|
53
53
|
else
|
54
|
-
@$element.trigger('failure.rest-in-place')
|
54
|
+
@$element.trigger('failure.rest-in-place', jqXHR.responseJSON)
|
55
55
|
@abort()
|
56
|
-
|
56
|
+
|
57
57
|
@$element.html("saving...")
|
58
|
-
|
58
|
+
|
59
59
|
loadViaGET : ->
|
60
60
|
showRequest = @ajax()
|
61
61
|
showRequest.done (data) => @loadSuccessCallback(data)
|
62
|
-
showRequest.fail => @$element.trigger('failure.rest-in-place')
|
63
|
-
|
62
|
+
showRequest.fail => @$element.trigger('failure.rest-in-place', showRequest.responseJSON)
|
63
|
+
|
64
64
|
# ## Implementation Methods
|
65
65
|
#
|
66
66
|
# These are not implemented in RestInPlaceEditor. Instead, different form
|
67
67
|
# types implement this method (and some others). See [Forms](#forms)
|
68
|
-
|
69
|
-
# Turns the elements HTML into a form.
|
68
|
+
|
69
|
+
# Turns the elements HTML into a form.
|
70
70
|
activateForm : ->
|
71
71
|
alert("The form was not properly initialized. activateForm is unbound")
|
72
|
-
|
72
|
+
|
73
73
|
# When the element is active (it is a form), thtis method returns the value
|
74
74
|
# that should be sent to the server.
|
75
75
|
getValue : ->
|
@@ -86,17 +86,17 @@ class RestInPlaceEditor
|
|
86
86
|
#
|
87
87
|
# These are the options:
|
88
88
|
#
|
89
|
-
# **data-url / @url**
|
89
|
+
# **data-url / @url**
|
90
90
|
# Where to send/receive data from
|
91
91
|
#
|
92
|
-
# **data-formtype / @formType**
|
92
|
+
# **data-formtype / @formType**
|
93
93
|
# Which form extension to use (see [Forms](#forms))
|
94
94
|
#
|
95
|
-
# **data-object / @objectName**
|
95
|
+
# **data-object / @objectName**
|
96
96
|
# Rails singular lowercase name of the class of the objects. This is used
|
97
97
|
# to generate requests/parse responses that ActionController can understand.
|
98
98
|
#
|
99
|
-
# **data-attributes / @attributeName**
|
99
|
+
# **data-attributes / @attributeName**
|
100
100
|
# Name of the attribute on the object. Combined with the object name to build
|
101
101
|
# query string parameters in the form `object[attribute]`, just as Rails
|
102
102
|
# expects it.
|
@@ -121,20 +121,20 @@ class RestInPlaceEditor
|
|
121
121
|
bindForm : ->
|
122
122
|
@activateForm = RestInPlaceEditor.forms[@formType].activateForm
|
123
123
|
@getValue = RestInPlaceEditor.forms[@formType].getValue
|
124
|
-
|
124
|
+
|
125
125
|
# Generate the data that is sent in the POST request
|
126
126
|
requestData : ->
|
127
127
|
data = @getEncodedTokenAuthenticationParams()
|
128
128
|
data["_method"] = 'put'
|
129
129
|
data["#{@objectName}[#{@attributeName}]"] = @getValue()
|
130
130
|
data
|
131
|
-
|
131
|
+
|
132
132
|
# Extract CSRF token from metatags
|
133
133
|
getEncodedTokenAuthenticationParams : ->
|
134
134
|
data = {}
|
135
135
|
param = $('meta[name=csrf-param]').attr('content')
|
136
136
|
token = $('meta[name=csrf-token]').attr('content')
|
137
|
-
data[param] = token if param && token
|
137
|
+
data[param] = token if param && token
|
138
138
|
data
|
139
139
|
|
140
140
|
# A wrapper for jQuery.ajax
|
@@ -148,7 +148,7 @@ class RestInPlaceEditor
|
|
148
148
|
if @include_root_in_json
|
149
149
|
data[@objectName][@attributeName]
|
150
150
|
else
|
151
|
-
data[@attributeName]
|
151
|
+
data[@attributeName]
|
152
152
|
|
153
153
|
updateDisplayValue : (value) ->
|
154
154
|
if $.trim(value).length < 1
|
@@ -165,15 +165,15 @@ class RestInPlaceEditor
|
|
165
165
|
value
|
166
166
|
|
167
167
|
# ## Handlers ##############################################################
|
168
|
-
|
168
|
+
|
169
169
|
# Handles the successful response from the server
|
170
170
|
loadSuccessCallback : (data) ->
|
171
171
|
@updateDisplayValue(@extractAttributeFromData(data))
|
172
172
|
@$element.click(@clickHandler)
|
173
173
|
@$element.removeClass('rip-active')
|
174
174
|
@$element.trigger('success.rest-in-place', data)
|
175
|
-
|
176
|
-
|
175
|
+
|
176
|
+
|
177
177
|
# Creates a clickhandler for the current instance of RestInPlaceEditor, that
|
178
178
|
# has its this pointer permanently bound to the editor instance.
|
179
179
|
createClickHandler : ->
|
@@ -185,10 +185,10 @@ class RestInPlaceEditor
|
|
185
185
|
# provide two methods, `activateForm` and `getValue`, which are transplanted
|
186
186
|
# into the RestInPlaceEditor instance.
|
187
187
|
#
|
188
|
-
# `activateForm` : Turns the elements HTML into a form.
|
188
|
+
# `activateForm` : Turns the elements HTML into a form.
|
189
189
|
# `getValue` : When the element is active (it is a form), this method returns
|
190
190
|
# the value that should be sent to the server.
|
191
|
-
RestInPlaceEditor.forms =
|
191
|
+
RestInPlaceEditor.forms =
|
192
192
|
"input" :
|
193
193
|
activateForm : ->
|
194
194
|
value = $.trim(@elementHTML())
|
@@ -203,10 +203,10 @@ RestInPlaceEditor.forms =
|
|
203
203
|
@$element.find("input").keyup (e) =>
|
204
204
|
@abort() if e.keyCode == ESC_KEY
|
205
205
|
@$element.find("input").blur => @abort()
|
206
|
-
|
206
|
+
|
207
207
|
getValue : ->
|
208
208
|
@$element.find("input").val()
|
209
|
-
|
209
|
+
|
210
210
|
"textarea" :
|
211
211
|
activateForm : ->
|
212
212
|
value = $.trim(@elementHTML())
|
data/rest_in_place.gemspec
CHANGED
@@ -5,7 +5,7 @@ require "rest_in_place/version"
|
|
5
5
|
Gem::Specification.new do |s|
|
6
6
|
s.name = "rest_in_place"
|
7
7
|
s.version = RestInPlace::VERSION
|
8
|
-
s.date = '2014-03-
|
8
|
+
s.date = '2014-03-07'
|
9
9
|
s.authors = ["Jan Varwig"]
|
10
10
|
s.email = ["jan@varwig.org"]
|
11
11
|
s.homepage = "http://jan.varwig.org"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rest_in_place
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jan Varwig
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-03-
|
11
|
+
date: 2014-03-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|