rest_in_place 2.0.2 → 2.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -148,6 +148,33 @@ restInPlace() on the jQuery object.
148
148
 
149
149
  $('.my-custom-class').restInPlace()
150
150
 
151
+ Events
152
+ ------
153
+
154
+ A REST in Place instance triggers four different events on the element that
155
+ it's associated with:
156
+
157
+ - `activate.rest-in-place` when starting the editing of the element.
158
+ Triggering the event is the first thing that happens, before any processing
159
+ and form building takes place. That means uou can use this event to modify
160
+ the content of the element (for example to remove number/date formatting).
161
+ - `success.rest-in-place` with the data retrieved from the server as an
162
+ extra parameter after a successful save on the server.
163
+ This event is triggered at the very latest moment, after the element has
164
+ been restored with the data from the server. This means you can use the
165
+ event handler to further modify the data and overwrite the displayed value
166
+ (useful for number/date formatting for example).
167
+ - `failure.rest-in-place` after an error occured
168
+ - `update.rest-in-place` immediately before sending the update to the server
169
+ - `abort.rest-in-place` when the user aborts the editing process.
170
+
171
+ Bind to these events through the jQuery event mechanisms:
172
+
173
+ $('#my-editable-element').bind('success.rest-in-place', function(event, data){
174
+ console.log("Yay it worked! The new value is", data.whatever);
175
+ });
176
+
177
+
151
178
  Example
152
179
  =======
153
180
 
@@ -15,6 +15,7 @@ class RestInPlaceEditor
15
15
 
16
16
  # Toggle the element associated with this editor from normal to a form field
17
17
  activate : ->
18
+ @$element.trigger('activate.rest-in-place')
18
19
  @oldValue = @$element.html()
19
20
  @$element.addClass('rip-active')
20
21
  @$element.unbind('click', @clickHandler)
@@ -22,6 +23,7 @@ class RestInPlaceEditor
22
23
 
23
24
  # Restore the element to its default state
24
25
  abort : ->
26
+ @$element.trigger('abort.rest-in-place')
25
27
  @$element
26
28
  .html(@oldValue)
27
29
  .removeClass('rip-active')
@@ -32,12 +34,13 @@ class RestInPlaceEditor
32
34
  # parseable answer, a second request is initiated to retrieve the updated
33
35
  # value via GET
34
36
  update : ->
37
+ @$element.trigger('update.rest-in-place')
35
38
  updateRequest = @ajax
36
39
  type : "post"
37
40
  data : @requestData()
38
41
 
39
42
  updateRequest.done (data) =>
40
- if data
43
+ if data
41
44
  @loadSuccessCallback(data)
42
45
  else
43
46
  @loadViaGET()
@@ -46,6 +49,7 @@ class RestInPlaceEditor
46
49
  if (jqXHR.status == 200 && textStatus == "parsererror")
47
50
  @loadViaGET()
48
51
  else
52
+ @$element.trigger('failure.rest-in-place')
49
53
  @abort()
50
54
 
51
55
  @$element.html("saving...")
@@ -53,6 +57,7 @@ class RestInPlaceEditor
53
57
  loadViaGET : ->
54
58
  showRequest = @ajax()
55
59
  showRequest.done (data) => @loadSuccessCallback(data)
60
+ showRequest.fail => @$element.trigger('failure.rest-in-place')
56
61
 
57
62
  # ## Implementation Methods
58
63
  #
@@ -148,6 +153,8 @@ class RestInPlaceEditor
148
153
  @$element.html(@extractAttributeFromData(data))
149
154
  @$element.click(@clickHandler)
150
155
  @$element.removeClass('rip-active')
156
+ @$element.trigger('success.rest-in-place', data)
157
+
151
158
 
152
159
  # Creates a clickhandler for the current instance of RestInPlaceEditor, that
153
160
  # has its this pointer permanently bound to the editor instance.
@@ -217,4 +224,4 @@ $.fn.restInPlace = ->
217
224
 
218
225
 
219
226
  # Run automatically
220
- $ -> $('.rest-in-place').restInPlace()
227
+ $ -> $('.rest-in-place').restInPlace()
@@ -1,3 +1,3 @@
1
1
  module RestInPlace
2
- VERSION = "2.0.2"
2
+ VERSION = "2.1"
3
3
  end
@@ -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 = '2012-06-07'
8
+ s.date = '2012-07-24'
9
9
  s.authors = ["Jan Varwig"]
10
10
  s.email = ["jan@varwig.org"]
11
11
  s.homepage = "http://jan.varwig.org"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rest_in_place
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.2
4
+ version: '2.1'
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-06-07 00:00:00.000000000 Z
12
+ date: 2012-07-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
16
- requirement: &70360483506640 !ruby/object:Gem::Requirement
16
+ requirement: &70251098586200 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,7 +21,7 @@ dependencies:
21
21
  version: '3.1'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70360483506640
24
+ version_requirements: *70251098586200
25
25
  description: REST in Place is an AJAX Inplace-Editor that talks to RESTful controllers.
26
26
  email:
27
27
  - jan@varwig.org
@@ -62,3 +62,4 @@ signing_key:
62
62
  specification_version: 3
63
63
  summary: An AJAX Inplace-Editor for the Rails 3.1 asset pipeline.
64
64
  test_files: []
65
+ has_rdoc: