best_in_place 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -27,13 +27,16 @@ The editor works by PUTting the updated value to the server and GETting the upda
27
27
 
28
28
  ##Usage of Rails 3 Gem
29
29
 
30
- **best_in_place Object, Field, [formType, [SelectValues]]**
30
+ **best_in_place Object, Field, [formType, [selectValues, [urlObject, [nilValue]]]]**
31
31
 
32
- The object is the object itself you are about to modify. The field (passed as symbol) is the represented attribute of the Object.
33
- You can add the formType [:input, :textarea, :select, :checkbox] or it defaults to :input. In case you chose :select, you must specify the
34
- collection of values it can take. In case you use :checkbox, you can specify the two possible boolean values.
32
+ The *Object* parameter represents the object itself you are about to modify. The *field* (passed as symbol) is the attribute of the Object
33
+ you are going to display/edit. You can add the *formType* [:input, :textarea, :select, :checkbox] or it defaults to :input. In case you chose
34
+ :select, you must specify the collection of values it takes through the *selectValues* param. In case you use :checkbox, you can user the parameter
35
+ selectValues to specify the two possible boolean values. If the Object url cannot be obtained directly from the Object, you can pass the parameter
36
+ *urlObject* the same way you pass any url in Rails. The last parameter *nilValue* allows you to customize the null value, in case the user deletes
37
+ the contents. By default it will display *"-"*.
35
38
 
36
- If created a [test_app](https://github.com/bernat/best_in_place/tree/master/test_app) and a running demo in heroku to test the features.
39
+ I created a [test_app](https://github.com/bernat/best_in_place/tree/master/test_app) and a running demo in heroku to test the features.
37
40
 
38
41
  Examples (code placed in the views):
39
42
 
@@ -41,6 +44,8 @@ Examples (code placed in the views):
41
44
 
42
45
  <%= best_in_place @user, :name, :input %>
43
46
 
47
+ <%= best_in_place @user, :name, :input, nil, nil, "Click me to add content!" %>
48
+
44
49
  ### Textarea
45
50
 
46
51
  <%= best_in_place @user, :description, :textarea %>
data/lib/best_in_place.rb CHANGED
@@ -1,8 +1,8 @@
1
1
  module BestInPlace
2
2
  module BestInPlaceHelpers
3
- def best_in_place(object, field, formType = :input, selectValues = [])
3
+ def best_in_place(object, field, formType = :input, selectValues = [], urlObject = nil, nilValue = "-")
4
4
  field = field.to_s
5
- value = object.send(field).blank? ? "-" : object.send(field)
5
+ value = object.send(field).blank? ? nilValue.to_s : object.send(field)
6
6
  if formType == :select && !selectValues.blank?
7
7
  value = Hash[selectValues][object.send(field)]
8
8
  selectValues = selectValues.to_json
@@ -17,7 +17,7 @@ module BestInPlace
17
17
  end
18
18
  out = "<span class='best_in_place'"
19
19
  out += " id='best_in_place_" + object.class.to_s.underscore + "_" + field.to_s + "'"
20
- out += " data-url='" + url_for(object).to_s + "'"
20
+ out += " data-url='" + (urlObject.blank? ? url_for(object).to_s : url_for(urlObject)) + "'"
21
21
  out += " data-object='" + object.class.to_s.underscore + "'"
22
22
  out += " data-selectValues='" + selectValues + "'" if !selectValues.blank?
23
23
  out += " data-attribute='" + field + "'"
@@ -1,3 +1,3 @@
1
1
  module BestInPlace
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.4"
3
3
  end
@@ -175,7 +175,7 @@ BestInPlaceEditor.forms = {
175
175
  },
176
176
 
177
177
  inputBlurHandler : function(event) {
178
- event.data.editor.abort()
178
+ event.data.editor.update()
179
179
  },
180
180
 
181
181
  submitHandler : function(event) {
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: best_in_place
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 19
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 3
10
- version: 0.1.3
9
+ - 4
10
+ version: 0.1.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Bernat Farrero
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-01-20 00:00:00 +01:00
18
+ date: 2011-01-24 00:00:00 +01:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency