on_the_spot 0.0.7 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +3 -0
- data/VERSION +1 -1
- data/lib/on_the_spot/on_the_spot_helpers.rb +17 -12
- data/on_the_spot.gemspec +2 -2
- data/spec/on_the_spot_spec.rb +47 -11
- metadata +3 -3
data/README.markdown
CHANGED
@@ -60,10 +60,13 @@ The `on_the_spot_edit` also accepts options:
|
|
60
60
|
* `:type` : `:textarea` or `:select` (none means default edit)
|
61
61
|
* `:ok_text` : the text for the ok-button
|
62
62
|
* `:cancel_text` : the text for the cancel-button
|
63
|
+
* `:display_text`: if you want to overrule the displayed text, especially useful when using your own `:url` or `:loadurl`
|
63
64
|
* `:tooltip` : the tooltip-text
|
64
65
|
* `:rows`: for textarea, the number of rows, defaults to 5
|
65
66
|
* `:columns`: for textarea, the number of columns, defaults to 40
|
66
67
|
* `:data`: for select, the lookup-data, should be in an array of id-value pairs. E.g. `[[1, 'ok'], [2, 'not ok'], [3, 'not decided']]`.
|
68
|
+
* `:loadurl`: for select, an url that will return the data in JSON format (use instead of `:data`)
|
69
|
+
* `:url`: URL to post to if you don't want to use the standard routes
|
67
70
|
|
68
71
|
|
69
72
|
For the texts: if a text is not specified, the default is taken from the `on_the_spot.en.yml` (or your current language).
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.8
|
@@ -7,18 +7,19 @@ module OnTheSpot
|
|
7
7
|
class OnTheSpotMissingParameters < StandardError; end
|
8
8
|
|
9
9
|
# Possible options:
|
10
|
-
# ok_text
|
11
|
-
# cancel_text
|
12
|
-
# tooltip
|
13
|
-
# type
|
14
|
-
# rows
|
15
|
-
# columns
|
16
|
-
# loadurl
|
17
|
-
#
|
10
|
+
# ok_text : the ok-button text
|
11
|
+
# cancel_text : the cancel-button text
|
12
|
+
# tooltip : the tooltip to show
|
13
|
+
# type : {'textarea' || 'select' }
|
14
|
+
# rows : nr of rows for textarea
|
15
|
+
# columns : nr of columns for textarea
|
16
|
+
# loadurl : (for select) an url that will return the json for the select
|
17
|
+
# display_text : either overrule the normal display-value, or needed when using loadurl
|
18
|
+
# data : (for select) an array of options in the form [id, value]
|
19
|
+
# url : (optional) URL to post to if you don't want to use the standard routes
|
18
20
|
def on_the_spot_edit(object, field, options={})
|
19
21
|
#!!! to do: translate options to data-fields
|
20
22
|
# Possible fields:
|
21
|
-
# url?
|
22
23
|
# type: textarea or not
|
23
24
|
# button-translations ok-Text, cancel-Text
|
24
25
|
#
|
@@ -29,10 +30,12 @@ module OnTheSpot
|
|
29
30
|
:cancel_text => t('on_the_spot.cancel'),
|
30
31
|
:tooltip => t('on_the_spot.tooltip'),
|
31
32
|
:rows => 5,
|
32
|
-
:columns => 40
|
33
|
+
:columns => 40,
|
34
|
+
:url => {:action => 'update_attribute_on_the_spot'}
|
35
|
+
|
33
36
|
)
|
34
37
|
|
35
|
-
update_url = url_for(:
|
38
|
+
update_url = url_for(options[:url])
|
36
39
|
|
37
40
|
field_value = object.send(field.to_sym).to_s
|
38
41
|
|
@@ -61,7 +64,9 @@ module OnTheSpot
|
|
61
64
|
html_options[:'data-tooltip'] = options[:tooltip]
|
62
65
|
|
63
66
|
content_tag("span", html_options) do
|
64
|
-
if
|
67
|
+
if options[:display_text]
|
68
|
+
options[:display_text]
|
69
|
+
elsif editable_type == :select && options[:loadurl].nil?
|
65
70
|
lookup_display_value(select_data, field_value)
|
66
71
|
else
|
67
72
|
field_value
|
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.
|
8
|
+
s.version = "0.0.8"
|
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-
|
12
|
+
s.date = %q{2011-04-25}
|
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 = [
|
data/spec/on_the_spot_spec.rb
CHANGED
@@ -45,22 +45,58 @@ describe "OnTheSpot" do
|
|
45
45
|
@tester.should_receive(:t).with('on_the_spot.ok').and_return("ok")
|
46
46
|
@tester.should_receive(:t).with('on_the_spot.cancel').and_return("cancel")
|
47
47
|
@tester.should_receive(:t).with('on_the_spot.tooltip').and_return("tooltip")
|
48
|
-
@tester.should_receive(:url_for).and_return('/bla')
|
49
48
|
end
|
50
49
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
50
|
+
context "with standard route" do
|
51
|
+
before(:each) do
|
52
|
+
@tester.should_receive(:url_for).with({:action => 'update_attribute_on_the_spot'}).and_return('/bla')
|
53
|
+
end
|
54
|
+
|
55
|
+
it "should make the correct html for an edit-field" do
|
56
|
+
@result = @tester.on_the_spot_edit @dummy, :content
|
57
|
+
@result.should == "<span class=\"on_the_spot_editing\" data-cancel=\"cancel\" data-ok=\"ok\" data-tooltip=\"tooltip\" data-url=\"/bla\" id=\"r_spec/mocks/mock__content__123\">test</span>"
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should make the correct html for an edit-field and overrule display-text" do
|
61
|
+
@result = @tester.on_the_spot_edit @dummy, :content, :display_text => 'jediknight'
|
62
|
+
@result.should == "<span class=\"on_the_spot_editing\" data-cancel=\"cancel\" data-ok=\"ok\" data-tooltip=\"tooltip\" data-url=\"/bla\" id=\"r_spec/mocks/mock__content__123\">jediknight</span>"
|
63
|
+
end
|
64
|
+
|
65
|
+
it "should make the correct html for a text-area" do
|
66
|
+
@result = @tester.on_the_spot_edit @dummy, :content, :type => :textarea
|
67
|
+
@result.should == "<span class=\"on_the_spot_editing\" data-cancel=\"cancel\" data-columns=\"40\" data-edittype=\"textarea\" data-ok=\"ok\" data-rows=\"5\" data-tooltip=\"tooltip\" data-url=\"/bla\" id=\"r_spec/mocks/mock__content__123\">test</span>"
|
68
|
+
end
|
69
|
+
|
70
|
+
it "should make the correct html for a select-box" do
|
71
|
+
@result = @tester.on_the_spot_edit @dummy, :content, :type => :select, :data => [['test', 'This a test'], ['prod', 'Pure Production'], ['QA', 'Quality Assurance']]
|
72
|
+
@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>"
|
73
|
+
end
|
55
74
|
|
56
|
-
|
57
|
-
|
58
|
-
|
75
|
+
|
76
|
+
|
77
|
+
context "a select-box with a loadurl" do
|
78
|
+
it "should make the correct html (and not look up the value)" do
|
79
|
+
@result = @tester.on_the_spot_edit @dummy, :content, :type => :select, :loadurl => '/load/data'
|
80
|
+
@result.should == "<span class=\"on_the_spot_editing\" data-cancel=\"cancel\" data-edittype=\"select\" data-loadurl=\"/load/data\" data-ok=\"ok\" data-tooltip=\"tooltip\" data-url=\"/bla\" id=\"r_spec/mocks/mock__content__123\">test</span>"
|
81
|
+
end
|
82
|
+
|
83
|
+
it "should use the display-text preferrably" do
|
84
|
+
@result = @tester.on_the_spot_edit @dummy, :content, :type => :select, :loadurl => '/load/data', :display_text => 'ninja'
|
85
|
+
@result.should == "<span class=\"on_the_spot_editing\" data-cancel=\"cancel\" data-edittype=\"select\" data-loadurl=\"/load/data\" data-ok=\"ok\" data-tooltip=\"tooltip\" data-url=\"/bla\" id=\"r_spec/mocks/mock__content__123\">ninja</span>"
|
86
|
+
end
|
87
|
+
end
|
59
88
|
end
|
60
89
|
|
61
|
-
|
62
|
-
|
63
|
-
|
90
|
+
context "with explicit route" do
|
91
|
+
before(:each) do
|
92
|
+
@tester.should_receive(:url_for).with({:action => 'update_it_otherwise'}).and_return('/bla')
|
93
|
+
end
|
94
|
+
|
95
|
+
it "should make the correct html for an edit-field" do
|
96
|
+
@result = @tester.on_the_spot_edit @dummy, :content, :url => {:action => 'update_it_otherwise' }
|
97
|
+
@result.should == "<span class=\"on_the_spot_editing\" data-cancel=\"cancel\" data-ok=\"ok\" data-tooltip=\"tooltip\" data-url=\"/bla\" id=\"r_spec/mocks/mock__content__123\">test</span>"
|
98
|
+
end
|
99
|
+
|
64
100
|
end
|
65
101
|
end
|
66
102
|
end
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
8
|
+
- 8
|
9
|
+
version: 0.0.8
|
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-
|
17
|
+
date: 2011-04-25 00:00:00 +02:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|