on_the_spot 1.1.2 → 1.1.3

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
- SHA1:
3
- metadata.gz: b529c0ec359d065b5be58926383c947ecd89b40f
4
- data.tar.gz: f4b5c500c36945091220524c621814e7f8129d2e
2
+ SHA256:
3
+ metadata.gz: 40b5d965c2d82d3af5910189c680a7b78ac758b4faddbcbac8724a173420b1bb
4
+ data.tar.gz: 9cb9cd5073ed51a6561b5878fda09b764a4c13f55dc7f568da2f7daed09dbc51
5
5
  SHA512:
6
- metadata.gz: 54be6beb41950cdcb7de401b73ec1ab66ecd471960e06d4626818426ec1f942b51614b3fcca3a1c637e6f5d3ab501e3d3a5a8757bbd89d8e9238efd8e5a627cf
7
- data.tar.gz: f749c615ed9b9a2e8ddc4af6f4498df88f4f357a26727d056590b77023a46b6eac01e6562679b72dc22e41e42aa9ef5a35ba298746975625a059c1203633535c
6
+ metadata.gz: '0396ab103978dd4f521c3fb477449a686fbef65e3488855b3f7f379e3f29fb73427b88e69ac9c38c2ced75c619faa09d404cfbd5bb0e0a2194d991ca8030af20'
7
+ data.tar.gz: 07eb52d9787e8ec4860cb62b6636ee3f2b967ca5b032e6efd42c3939c12dfd4df8f5f8f2925f7c30324d3819ecbc46afcd8d7ba594cbb22373afba620e0fa065
@@ -116,6 +116,11 @@ It should be as simple as that :)
116
116
 
117
117
  ## Detailed options
118
118
 
119
+ The `can_edit_on_the_spot` accepts options:
120
+
121
+ * `:is_allowed`: method-name to call to check if the update is allowed to be performed
122
+ * `:on_success`: method-name that is called when the update was succesfully performed, this could be used for audit-logging a.o.
123
+
119
124
  The `on_the_spot_edit` also accepts options:
120
125
 
121
126
  * `:type` : `:textarea`, `:select` or `:checkbox` (none means default edit)
@@ -134,6 +139,7 @@ The `on_the_spot_edit` also accepts options:
134
139
  attempt to look up the raw value of the field to edit. This differs from the `:display_text` option, as this will also be called after update.
135
140
  This supersedes the `:display_text` option.
136
141
  * `:raw`: if set to true, evaluate the field value as raw HTML.
142
+ * `:onblur`: accepts `cancel`, `submit` or `ignore` changes the behavior of the onblur handler accordingly
137
143
 
138
144
 
139
145
  For the texts: if a text is not specified, the default is taken from the `on_the_spot.en.yml` (or your current language).
@@ -178,7 +184,7 @@ When using `on_the_spot` together with `cancan`, you will have to explicitly exc
178
184
  like so:
179
185
 
180
186
  load_and_authorize_resource :except => [:update_attribute_on_the_spot, :get_attribute_on_the_spot]
181
-
187
+
182
188
  The `load_and_authorize_resource` will try to find the object, based on the id in the parameters, but `on_the_spot` uses a different
183
189
  encoding to store the object, field and id in one attribute. So if you exclude that, there will not be a problem.
184
190
 
@@ -196,6 +202,26 @@ In your controller write:
196
202
  end
197
203
 
198
204
 
205
+ Note, there are two identical ways to add this: either you use the _old format_ : `can_edit_on_the_spot :method_name` or
206
+ you could use the new format: `can_edit_on_the_spot is_allowed: :check_access`. Both are identical
207
+
208
+
209
+ ## Performing an action upon succesful update
210
+
211
+ If you want to perform some action upon succesfully updating a field,
212
+ you can specify a method to do just that.
213
+
214
+
215
+ In your controller write:
216
+
217
+ can_edit_on_the_spot on_success: :log_changes
218
+
219
+ protected
220
+
221
+ def log_changes(updated_object, field, value)
222
+ Rails.logger.debug("We updated #{updated_object.name} and set #{field} to #{value}")
223
+ end
224
+
199
225
 
200
226
  ## Example project
201
227
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.1.2
1
+ 1.1.3
@@ -8,7 +8,10 @@ module OnTheSpot
8
8
  # if this method is called inside a controller, the edit-on-the-spot
9
9
  # controller action is added that will allow to edit fields in place
10
10
  module ClassMethods
11
- def can_edit_on_the_spot(check_acces_method=nil)
11
+ def can_edit_on_the_spot(options_or_check_access_method=nil)
12
+ check_access_method = options_or_check_access_method.is_a?(Hash) ? options_or_check_access_method[:is_allowed] : options_or_check_access_method
13
+ on_success_method = options_or_check_access_method.is_a?(Hash) ? options_or_check_access_method[:on_success] : nil
14
+
12
15
  define_method :update_attribute_on_the_spot do
13
16
  klass_name, field, id = params[:id].split('__')
14
17
  select_data = params[:select_array]
@@ -17,7 +20,7 @@ module OnTheSpot
17
20
  klass = klass_name.camelize.constantize
18
21
  object = klass.find(id)
19
22
 
20
- is_allowed = check_acces_method.present? ? self.send(check_acces_method, object, field) : true
23
+ is_allowed = check_access_method.present? ? self.send(check_access_method, object, field) : true
21
24
 
22
25
  if is_allowed
23
26
  saved = if klass.attribute_names.include?(field)
@@ -28,6 +31,9 @@ module OnTheSpot
28
31
  object.save
29
32
  end
30
33
  if saved
34
+ if on_success_method.present?
35
+ self.send(on_success_method, object, field, params[:value])
36
+ end
31
37
  if select_data.nil?
32
38
  field_or_method = if display_method.present?
33
39
  object.send(display_method)
@@ -53,7 +59,7 @@ module OnTheSpot
53
59
 
54
60
  object = klass_name.camelize.constantize.find(id)
55
61
 
56
- is_allowed = check_acces_method.present? ? self.send(check_acces_method, object, field) : true
62
+ is_allowed = check_access_method.present? ? self.send(check_access_method, object, field) : true
57
63
 
58
64
  if is_allowed
59
65
  render :plain => object.send(field)
@@ -2,16 +2,16 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: on_the_spot 1.1.2 ruby lib
5
+ # stub: on_the_spot 1.1.3 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "on_the_spot".freeze
9
- s.version = "1.1.2"
9
+ s.version = "1.1.3"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
12
12
  s.require_paths = ["lib".freeze]
13
13
  s.authors = ["Nathan Van der Auwera".freeze]
14
- s.date = "2018-05-25"
14
+ s.date = "2019-10-21"
15
15
  s.description = "Unobtrusive in place editing, using jEditable; only works in Rails 3".freeze
16
16
  s.email = "nathan@dixis.com".freeze
17
17
  s.extra_rdoc_files = [
@@ -84,7 +84,7 @@ Gem::Specification.new do |s|
84
84
  ]
85
85
  s.homepage = "http://github.com/nathanvda/on_the_spot".freeze
86
86
  s.licenses = ["MIT".freeze]
87
- s.rubygems_version = "2.6.14".freeze
87
+ s.rubygems_version = "2.7.10".freeze
88
88
  s.summary = "unobtrusive in place editing".freeze
89
89
 
90
90
  if s.respond_to? :specification_version then
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: on_the_spot
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.2
4
+ version: 1.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nathan Van der Auwera
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-05-25 00:00:00.000000000 Z
11
+ date: 2019-10-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -142,7 +142,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
142
142
  version: '0'
143
143
  requirements: []
144
144
  rubyforge_project:
145
- rubygems_version: 2.6.14
145
+ rubygems_version: 2.7.10
146
146
  signing_key:
147
147
  specification_version: 4
148
148
  summary: unobtrusive in place editing