simple_form-magic_submit 1.1.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +5 -0
- data/lib/simple_form/magic_submit.rb +35 -10
- data/lib/simple_form/magic_submit/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 87ca804fae3f7a0ddea9b6c274811bbd608fe202
|
4
|
+
data.tar.gz: 32b03c1942686a0a57f30dd863476eb4dcc9e8cd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8b7a8c045917656bdedab912ec93ed8eae928763cdfb3987c0b2fb87c33819f4eaca774c1e1f510549df116601ed997133491e18e732e7eb9e88ce49a844d514
|
7
|
+
data.tar.gz: 44aa9d4b79cec36cf2cf7819d57638a7e5d9a0ccc0eaf3fbfe8370003da1e1c76efaa1c6390222193c83bd771eb901223c181d4d181a8bfcfc49e09705572176
|
data/README.md
CHANGED
@@ -125,3 +125,8 @@ Each lookup will have `%{model}` interpolated to the name of the model.
|
|
125
125
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
126
126
|
4. Push to the branch (`git push origin my-new-feature`)
|
127
127
|
5. Create new Pull Request
|
128
|
+
|
129
|
+
## Thanks go to...
|
130
|
+
|
131
|
+
Victor Nahuel Chaves (https://github.com/nahue) for adding support for model-less forms.
|
132
|
+
|
@@ -22,28 +22,53 @@ module SimpleForm
|
|
22
22
|
end
|
23
23
|
|
24
24
|
private
|
25
|
+
|
26
|
+
def bound_to_model?
|
27
|
+
# if its a string means that its bound to a model.. but if its a symbol its not...
|
28
|
+
self.object_name.is_a?(String)# || self.object.present?
|
29
|
+
end
|
30
|
+
|
25
31
|
def main_class(options = {})
|
26
32
|
options.fetch(:destructive, false) ? 'btn-destructive' : 'btn-primary'
|
27
33
|
end
|
28
|
-
|
34
|
+
|
29
35
|
def controller_scope
|
36
|
+
# falls to default if the model isn't tied to a model
|
37
|
+
return "default" unless bound_to_model?
|
38
|
+
|
30
39
|
template.controller.params[:controller].gsub('/', '.')
|
31
40
|
end
|
32
41
|
|
33
42
|
def object_scope
|
43
|
+
# returns empty string if no model is found to prevent exception
|
44
|
+
return "" unless bound_to_model?
|
45
|
+
|
34
46
|
self.object.class.model_name.i18n_key.to_s
|
35
47
|
end
|
36
48
|
|
37
49
|
def translate_key(key = nil)
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
:
|
44
|
-
|
45
|
-
|
46
|
-
|
50
|
+
|
51
|
+
if bound_to_model?
|
52
|
+
key ||= self.object.errors.count > 0 ? :retry : :submit
|
53
|
+
|
54
|
+
I18n.t("simple_form.magic_submit.#{controller_scope}.#{object_scope}.#{lookup_action}.#{key}",
|
55
|
+
default: [
|
56
|
+
:"simple_form.magic_submit.#{controller_scope}.#{lookup_action}.#{key}",
|
57
|
+
:"simple_form.magic_submit.default.#{lookup_action}.#{key}",
|
58
|
+
:"helpers.submit.#{lookup_action}"
|
59
|
+
],
|
60
|
+
model: self.object.class.model_name.human.titlecase
|
61
|
+
).html_safe
|
62
|
+
else
|
63
|
+
# we have no model errors... so we test if the post is get or already posted
|
64
|
+
key ||= template.request.get? ? :submit : :retry
|
65
|
+
I18n.t("simple_form.magic_submit.#{controller_scope}.#{object_scope}.#{lookup_action}.#{key}",
|
66
|
+
default: [
|
67
|
+
:"simple_form.magic_submit.#{controller_scope}.#{lookup_action}.#{key}",
|
68
|
+
:"simple_form.magic_submit.default.#{lookup_action}.#{key}",
|
69
|
+
:"helpers.submit.#{lookup_action}"
|
70
|
+
]).html_safe
|
71
|
+
end
|
47
72
|
end
|
48
73
|
|
49
74
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simple_form-magic_submit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrey Subbotin
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2014-03-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: simple_form
|
@@ -120,7 +120,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
120
120
|
version: '0'
|
121
121
|
requirements: []
|
122
122
|
rubyforge_project:
|
123
|
-
rubygems_version: 2.
|
123
|
+
rubygems_version: 2.1.11
|
124
124
|
signing_key:
|
125
125
|
specification_version: 4
|
126
126
|
summary: Magic Submit Button for Simple Form
|