on_the_spot 0.0.11 → 0.0.12

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.
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ rvm:
2
+ - 1.8.7
3
+ - 1.9.2
4
+ - rbx
5
+ - ree
6
+ - jruby
data/README.markdown CHANGED
@@ -68,6 +68,7 @@ The `on_the_spot_edit` also accepts options:
68
68
  * `:loadurl`: for select, an url that will return the data in JSON format (use instead of `:data`)
69
69
  * `:url`: URL to post to if you don't want to use the standard routes
70
70
  * `:selected`: Text selected by default on edit (boolean, default is false)
71
+ * `:callback`: The name of a javascript function that is called after form has been submitted
71
72
 
72
73
 
73
74
  For the texts: if a text is not specified, the default is taken from the `on_the_spot.en.yml` (or your current language).
@@ -86,6 +87,17 @@ For the texts: if a text is not specified, the default is taken from the `on_the
86
87
 
87
88
  <%= on_the_spot_edit @user, :rating, :type => :select, :data => [[1, 'good'], [2, 'mediocre'], [3, 'bad']] %>
88
89
 
90
+ ### Callback
91
+
92
+ Somewhere in a .js file:
93
+ function testCallback(object, value, settings) {
94
+ console.log(object);
95
+ console.log(value);
96
+ console.log(settings);
97
+ }
98
+
99
+ <%= on_the_spot_edit @user, :name, :callback => 'testCallback' %>
100
+
89
101
 
90
102
  ## Example project
91
103
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.11
1
+ 0.0.12
@@ -22,7 +22,8 @@ function initializeOnTheSpot(n){
22
22
  rows = el.attr('data-rows'),
23
23
  columns = el.attr('data-columns'),
24
24
  load_url = el.attr('data-loadurl'),
25
- selected = el.attr('data-selected');
25
+ selected = el.attr('data-selected'),
26
+ callback = el.attr('data-callback');
26
27
 
27
28
  var options = {
28
29
  tooltip: tooltip_text,
@@ -38,7 +39,8 @@ function initializeOnTheSpot(n){
38
39
  submitdata: {
39
40
  authenticity_token: auth_token,
40
41
  _method: 'put'
41
- }
42
+ },
43
+ callback: new Function("value", "settings", "return "+callback+"(this, value, settings);")
42
44
  };
43
45
  if (edit_type != null) {
44
46
  options.type = edit_type;
@@ -18,6 +18,7 @@ module OnTheSpot
18
18
  # data : (for select) an array of options in the form [id, value]
19
19
  # url : (optional) URL to post to if you don't want to use the standard routes
20
20
  # selected : (optional) boolean, text selected on edit
21
+ # callback : (optional) a javascript function that is called after form has been submitted
21
22
  def on_the_spot_edit(object, field, options={})
22
23
  #!!! to do: translate options to data-fields
23
24
  # Possible fields:
@@ -65,6 +66,7 @@ module OnTheSpot
65
66
  html_options[:'data-tooltip'] = options[:tooltip]
66
67
  html_options[:'data-auth'] = form_authenticity_token if defined? form_authenticity_token
67
68
  html_options[:'data-selected'] = options[:selected]
69
+ html_options[:'data-callback'] = options[:callback]
68
70
 
69
71
  content_tag("span", html_options) do
70
72
  if options[:display_text]
data/on_the_spot.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{on_the_spot}
8
- s.version = "0.0.11"
8
+ s.version = "0.0.12"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Nathan Van der Auwera"]
12
- s.date = %q{2011-05-29}
12
+ s.date = %q{2011-07-02}
13
13
  s.description = %q{Unobtrusive in place editing, using jEditable; only works in Rails 3}
14
14
  s.email = %q{nathan@dixis.com}
15
15
  s.extra_rdoc_files = [
@@ -20,6 +20,7 @@ Gem::Specification.new do |s|
20
20
  ".document",
21
21
  ".gitignore",
22
22
  ".rspec",
23
+ ".travis.yml",
23
24
  "Gemfile",
24
25
  "Gemfile.lock",
25
26
  "LICENSE",
@@ -81,6 +81,11 @@ describe "OnTheSpot" do
81
81
  @result = @tester.on_the_spot_edit @dummy, :content, :type => :select, :data => [['test', 'This a test'], ['prod', 'Pure Production'], ['QA', 'Quality Assurance']]
82
82
  @result.should == "<span class=\"on_the_spot_editing\" data-cancel=\"cancel\" data-edittype=\"select\" data-ok=\"ok\" data-select=\"{ 'test':'This a test', 'prod':'Pure Production', 'QA':'Quality Assurance', 'selected':'test'}\" data-tooltip=\"tooltip\" data-url=\"/bla\" id=\"r_spec/mocks/mock__content__123\">This a test</span>"
83
83
  end
84
+
85
+ it "should make the correct html for an edit-field with a callback" do
86
+ @result = @tester.on_the_spot_edit @dummy, :content, :callback => 'testCallback(value, settings);'
87
+ @result.should == "<span class=\"on_the_spot_editing\" data-callback=\"testCallback(value, settings);\" data-cancel=\"cancel\" data-ok=\"ok\" data-tooltip=\"tooltip\" data-url=\"/bla\" id=\"r_spec/mocks/mock__content__123\">test</span>"
88
+ end
84
89
 
85
90
 
86
91
 
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 11
9
- version: 0.0.11
8
+ - 12
9
+ version: 0.0.12
10
10
  platform: ruby
11
11
  authors:
12
12
  - Nathan Van der Auwera
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2011-05-29 00:00:00 +02:00
17
+ date: 2011-07-02 00:00:00 +02:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -75,6 +75,7 @@ files:
75
75
  - .document
76
76
  - .gitignore
77
77
  - .rspec
78
+ - .travis.yml
78
79
  - Gemfile
79
80
  - Gemfile.lock
80
81
  - LICENSE