on_the_spot 0.0.10 → 0.0.11
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +1 -0
- data/Rakefile +4 -0
- data/VERSION +1 -1
- data/lib/generators/on_the_spot/install/templates/on_the_spot.js +48 -44
- data/lib/on_the_spot/on_the_spot_helpers.rb +3 -1
- data/on_the_spot.gemspec +2 -2
- data/spec/on_the_spot_spec.rb +10 -0
- metadata +3 -3
data/README.markdown
CHANGED
@@ -67,6 +67,7 @@ The `on_the_spot_edit` also accepts options:
|
|
67
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
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
|
+
* `:selected`: Text selected by default on edit (boolean, default is false)
|
70
71
|
|
71
72
|
|
72
73
|
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/Rakefile
CHANGED
@@ -21,8 +21,12 @@ rescue LoadError
|
|
21
21
|
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
22
22
|
end
|
23
23
|
|
24
|
+
|
24
25
|
RSpec::Core::RakeTask.new(:spec)
|
25
26
|
|
27
|
+
task :default => :spec
|
28
|
+
|
29
|
+
|
26
30
|
desc "Run all specs with rcov"
|
27
31
|
RSpec::Core::RakeTask.new("test_cov") do |t|
|
28
32
|
t.rcov = true
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.11
|
@@ -6,52 +6,56 @@ $(document).ready(function() {
|
|
6
6
|
$(".on_the_spot_editing").mouseout(function() {
|
7
7
|
$(this).css('background-color', 'inherit');
|
8
8
|
});
|
9
|
-
$('.on_the_spot_editing').each(
|
10
|
-
var el = $(this),
|
11
|
-
auth_token = el.attr('data-auth'),
|
12
|
-
data_url = el.attr('data-url'),
|
13
|
-
ok_text = el.attr('data-ok') || 'OK',
|
14
|
-
cancel_text = el.attr('data-cancel') || 'Cancel',
|
15
|
-
tooltip_text = el.attr('data-tooltip') || 'Click to edit ...',
|
16
|
-
edit_type = el.attr('data-edittype'),
|
17
|
-
select_data = el.attr('data-select'),
|
18
|
-
rows = el.attr('data-rows'),
|
19
|
-
columns = el.attr('data-columns'),
|
20
|
-
load_url = el.attr('data-loadurl');
|
9
|
+
$('.on_the_spot_editing').each(initializeOnTheSpot);
|
21
10
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
11
|
+
});
|
12
|
+
|
13
|
+
function initializeOnTheSpot(n){
|
14
|
+
var el = $(this),
|
15
|
+
auth_token = el.attr('data-auth'),
|
16
|
+
data_url = el.attr('data-url'),
|
17
|
+
ok_text = el.attr('data-ok') || 'OK',
|
18
|
+
cancel_text = el.attr('data-cancel') || 'Cancel',
|
19
|
+
tooltip_text = el.attr('data-tooltip') || 'Click to edit ...',
|
20
|
+
edit_type = el.attr('data-edittype'),
|
21
|
+
select_data = el.attr('data-select'),
|
22
|
+
rows = el.attr('data-rows'),
|
23
|
+
columns = el.attr('data-columns'),
|
24
|
+
load_url = el.attr('data-loadurl'),
|
25
|
+
selected = el.attr('data-selected');
|
26
|
+
|
27
|
+
var options = {
|
28
|
+
tooltip: tooltip_text,
|
29
|
+
placeholder: tooltip_text,
|
30
|
+
cancel: cancel_text,
|
31
|
+
submit: ok_text,
|
32
|
+
select: selected,
|
33
|
+
onerror: function (settings, original, xhr) {
|
34
|
+
original.reset();
|
35
|
+
//just show the error-msg for now
|
36
|
+
alert(xhr.responseText);
|
37
|
+
},
|
38
|
+
submitdata: {
|
39
|
+
authenticity_token: auth_token,
|
40
|
+
_method: 'put'
|
39
41
|
}
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
42
|
+
};
|
43
|
+
if (edit_type != null) {
|
44
|
+
options.type = edit_type;
|
45
|
+
}
|
46
|
+
if (edit_type == 'select') {
|
47
|
+
if (select_data != null) {
|
48
|
+
options.data = select_data;
|
49
|
+
options.submitdata['select_array'] = select_data;
|
48
50
|
}
|
49
|
-
|
50
|
-
options.
|
51
|
-
options.cols = columns;
|
51
|
+
if (load_url != null) {
|
52
|
+
options.loadurl = load_url;
|
52
53
|
}
|
54
|
+
}
|
55
|
+
else if (edit_type == 'textarea') {
|
56
|
+
options.rows = rows;
|
57
|
+
options.cols = columns;
|
58
|
+
}
|
53
59
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
});
|
60
|
+
el.editable(data_url, options)
|
61
|
+
}
|
@@ -17,6 +17,7 @@ module OnTheSpot
|
|
17
17
|
# display_text : either overrule the normal display-value, or needed when using loadurl
|
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
|
+
# selected : (optional) boolean, text selected on edit
|
20
21
|
def on_the_spot_edit(object, field, options={})
|
21
22
|
#!!! to do: translate options to data-fields
|
22
23
|
# Possible fields:
|
@@ -63,7 +64,8 @@ module OnTheSpot
|
|
63
64
|
html_options[:'data-cancel'] = options[:cancel_text]
|
64
65
|
html_options[:'data-tooltip'] = options[:tooltip]
|
65
66
|
html_options[:'data-auth'] = form_authenticity_token if defined? form_authenticity_token
|
66
|
-
|
67
|
+
html_options[:'data-selected'] = options[:selected]
|
68
|
+
|
67
69
|
content_tag("span", html_options) do
|
68
70
|
if options[:display_text]
|
69
71
|
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.
|
8
|
+
s.version = "0.0.11"
|
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-
|
12
|
+
s.date = %q{2011-05-29}
|
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
@@ -56,6 +56,11 @@ describe "OnTheSpot" do
|
|
56
56
|
@result = @tester.on_the_spot_edit @dummy, :content
|
57
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
58
|
end
|
59
|
+
|
60
|
+
it "should make the correct html for an edit-field with text selected on click" do
|
61
|
+
@result = @tester.on_the_spot_edit @dummy, :content, :selected => true
|
62
|
+
@result.should == "<span class=\"on_the_spot_editing\" data-cancel=\"cancel\" data-ok=\"ok\" data-selected=\"true\" data-tooltip=\"tooltip\" data-url=\"/bla\" id=\"r_spec/mocks/mock__content__123\">test</span>"
|
63
|
+
end
|
59
64
|
|
60
65
|
it "should make the correct html for an edit-field and overrule display-text" do
|
61
66
|
@result = @tester.on_the_spot_edit @dummy, :content, :display_text => 'jediknight'
|
@@ -66,6 +71,11 @@ describe "OnTheSpot" do
|
|
66
71
|
@result = @tester.on_the_spot_edit @dummy, :content, :type => :textarea
|
67
72
|
@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
73
|
end
|
74
|
+
|
75
|
+
it "should make the correct html for a text-area with text selected on click" do
|
76
|
+
@result = @tester.on_the_spot_edit @dummy, :content, :type => :textarea, :selected => true
|
77
|
+
@result.should == "<span class=\"on_the_spot_editing\" data-cancel=\"cancel\" data-columns=\"40\" data-edittype=\"textarea\" data-ok=\"ok\" data-rows=\"5\" data-selected=\"true\" data-tooltip=\"tooltip\" data-url=\"/bla\" id=\"r_spec/mocks/mock__content__123\">test</span>"
|
78
|
+
end
|
69
79
|
|
70
80
|
it "should make the correct html for a select-box" do
|
71
81
|
@result = @tester.on_the_spot_edit @dummy, :content, :type => :select, :data => [['test', 'This a test'], ['prod', 'Pure Production'], ['QA', 'Quality Assurance']]
|
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
|
+
- 11
|
9
|
+
version: 0.0.11
|
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-
|
17
|
+
date: 2011-05-29 00:00:00 +02:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|