express_admin 1.4.10 → 1.4.11
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.
- checksums.yaml +4 -4
- data/app/assets/stylesheets/express_admin/shared/_tables.sass +5 -0
- data/app/components/express_admin/smart_table.rb +1 -1
- data/app/components/express_admin/widget_box.rb +5 -1
- data/app/helpers/express_admin/admin_helper.rb +2 -2
- data/lib/express_admin/standard_actions.rb +54 -7
- data/lib/express_admin/version.rb +1 -1
- data/test/controllers/standard_controller_test.rb +6 -0
- data/test/dummy/app/models/widget.rb +2 -0
- data/test/dummy/db/test.sqlite3 +0 -0
- data/test/dummy/test/components/definition_list_test.rb +1 -1
- data/test/dummy/test/components/definition_table_test.rb +1 -1
- data/test/dummy/test/components/flash_messages_test.rb +6 -9
- data/test/dummy/test/components/icon_link_test.rb +1 -1
- data/test/dummy/test/components/icon_test.rb +1 -1
- data/test/dummy/test/components/module_sidebar_test.rb +16 -22
- data/test/dummy/test/components/smart_form_test.rb +4 -4
- data/test/dummy/test/components/smart_table_test.rb +6 -9
- data/test/dummy/test/components/widget_box_test.rb +5 -5
- data/test/test_helper.rb +11 -9
- data/vendor/gems/express_templates/Gemfile.lock +1 -1
- data/vendor/gems/express_templates/express_templates-0.10.0.gem +0 -0
- data/vendor/gems/express_templates/lib/express_templates/components/all.rb +26 -0
- data/vendor/gems/express_templates/lib/express_templates/components/capabilities/resourceful.rb +11 -15
- data/vendor/gems/express_templates/lib/express_templates/components/forms/basic_fields.rb +4 -4
- data/vendor/gems/express_templates/lib/express_templates/components/forms/checkbox.rb +1 -1
- data/vendor/gems/express_templates/lib/express_templates/components/forms/express_form.rb +6 -2
- data/vendor/gems/express_templates/lib/express_templates/components/forms/form_component.rb +16 -4
- data/vendor/gems/express_templates/lib/express_templates/components/forms/radio.rb +3 -3
- data/vendor/gems/express_templates/lib/express_templates/components.rb +1 -0
- data/vendor/gems/express_templates/lib/express_templates/version.rb +1 -1
- data/vendor/gems/express_templates/test/components/forms/basic_fields_test.rb +17 -9
- data/vendor/gems/express_templates/test/components/forms/checkbox_test.rb +13 -3
- data/vendor/gems/express_templates/test/components/forms/express_form_test.rb +12 -8
- data/vendor/gems/express_templates/test/components/forms/radio_test.rb +14 -2
- data/vendor/gems/express_templates/test/components/forms/select_test.rb +11 -3
- data/vendor/gems/express_templates/test/dummy/log/test.log +5511 -0
- data/vendor/gems/express_templates/test/test_helper.rb +3 -17
- metadata +6 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dc5b5fd470148d183da2706152e9b7019eb2c6d9
|
4
|
+
data.tar.gz: b39194d97af745e8e35873dd0a9e9e44bfb356f7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1411b21129cb3d05ba04f7f83bb13428e6145cab8702897079d5cbcb9304486ca516f9076b60c9b71e8f6edc48abe880e21010404d1d9ccd0081a2fe8427e49b
|
7
|
+
data.tar.gz: f0348de1c2da9faf4f5810c53449721a01c0f423d1af63e0048a80b01e4f5b9fa8cc226cc0a84b915a48bd60864231277edef22d7bea874f665a521740034be6
|
@@ -21,7 +21,11 @@ module ExpressAdmin
|
|
21
21
|
end
|
22
22
|
|
23
23
|
def box_title
|
24
|
-
config[:title] || (
|
24
|
+
config[:title] || (resource.persisted? ? "Edit #{resource_name}" : "New #{resource_name}")
|
25
|
+
end
|
26
|
+
|
27
|
+
def resource
|
28
|
+
self.send(config[:id])
|
25
29
|
end
|
26
30
|
end
|
27
31
|
end
|
@@ -56,9 +56,9 @@ module ExpressAdmin
|
|
56
56
|
content_for?(:description) ? yield(:description) : 'Testapp'
|
57
57
|
end
|
58
58
|
|
59
|
-
def admin_javascript_and_css_includes
|
59
|
+
def admin_javascript_and_css_includes(admin_path = nil)
|
60
60
|
current_module_path = current_module.to_s.underscore
|
61
|
-
admin_path
|
61
|
+
admin_path ||= current_module_path.eql?('admin') ? "admin" : "#{current_module_path}/admin"
|
62
62
|
a = []
|
63
63
|
a << stylesheet_link_tag("#{admin_path}/application")
|
64
64
|
a << stylesheet_link_tag("app_express/admin/application") if defined?(AppExpress)
|
@@ -24,11 +24,53 @@ module ExpressAdmin
|
|
24
24
|
params.require(:#{base.resource_name}).permit!
|
25
25
|
end
|
26
26
|
RUBY
|
27
|
+
|
28
|
+
base.class_eval do
|
29
|
+
|
30
|
+
class_attribute :resource_class
|
31
|
+
self.resource_class = resource_name.classify.constantize
|
32
|
+
|
33
|
+
if self.resource_class.respond_to?(:commands)
|
34
|
+
self.resource_class.commands.each do |command|
|
35
|
+
define_command_method(command)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def manages(a_resource_class)
|
42
|
+
self.resource_class = a_resource_class
|
27
43
|
end
|
28
44
|
|
29
45
|
def resource_name
|
30
46
|
self.to_s.demodulize.gsub(/Controller$/, '').singularize.underscore
|
31
47
|
end
|
48
|
+
|
49
|
+
protected
|
50
|
+
|
51
|
+
def define_command_method(command)
|
52
|
+
define_method(command) do
|
53
|
+
load_resource
|
54
|
+
begin
|
55
|
+
resource.send(command)
|
56
|
+
respond_to do |format|
|
57
|
+
format.html { redirect_to :show, layout: defaults[:layout] }
|
58
|
+
format.js { render status: :ok } # maybe we should return enough info
|
59
|
+
#to alter display of available or enabled commands?
|
60
|
+
|
61
|
+
end
|
62
|
+
rescue => e
|
63
|
+
respond_to do |format|
|
64
|
+
format.html {
|
65
|
+
flash[:error] = e.to_s
|
66
|
+
redirect_to :show, layout: defaults[:layout]
|
67
|
+
}
|
68
|
+
format.js { render status: :bad_request, body: e.to_s }
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
32
74
|
end
|
33
75
|
|
34
76
|
module InstanceMethods
|
@@ -157,14 +199,19 @@ module ExpressAdmin
|
|
157
199
|
|
158
200
|
def end_of_association_chain
|
159
201
|
if nested?
|
160
|
-
parent_resource
|
202
|
+
parent_resource
|
161
203
|
else
|
162
|
-
|
204
|
+
nil
|
163
205
|
end
|
164
206
|
end
|
165
207
|
|
166
208
|
def load_collection
|
167
|
-
|
209
|
+
scope = if end_of_association_chain
|
210
|
+
end_of_association_chain.send(collection_name)
|
211
|
+
else
|
212
|
+
resource_class
|
213
|
+
end
|
214
|
+
self.instance_variable_set(collection_ivar, scope.all)
|
168
215
|
end
|
169
216
|
|
170
217
|
def collection_ivar
|
@@ -185,7 +232,7 @@ module ExpressAdmin
|
|
185
232
|
|
186
233
|
def build_resource(*args)
|
187
234
|
if nested?
|
188
|
-
self.instance_variable_set(resource_ivar, end_of_association_chain.build(*args))
|
235
|
+
self.instance_variable_set(resource_ivar, end_of_association_chain.send(collection_name).build(*args))
|
189
236
|
else
|
190
237
|
self.instance_variable_set(resource_ivar, resource_class.new(*args))
|
191
238
|
end
|
@@ -199,9 +246,9 @@ module ExpressAdmin
|
|
199
246
|
"@#{resource_name}".to_sym
|
200
247
|
end
|
201
248
|
|
202
|
-
def resource_class
|
203
|
-
|
204
|
-
end
|
249
|
+
# def resource_class
|
250
|
+
# self.class.to_s.gsub(/Controller$/, '').singularize.classify.constantize
|
251
|
+
# end
|
205
252
|
|
206
253
|
# Foo::WidgetsController -> widget
|
207
254
|
def resource_name
|
@@ -107,5 +107,11 @@ module ExpressAdmin
|
|
107
107
|
|
108
108
|
# TODO: Implement later
|
109
109
|
# test "for nested resources it should try to expose a current method for parent resources"
|
110
|
+
|
111
|
+
test ".define_command_method defines a command action method on the controller" do
|
112
|
+
refute widgets_controller.respond_to?(:foo)
|
113
|
+
widgets_controller.class.send(:define_command_method, :foo)
|
114
|
+
assert widgets_controller.respond_to?(:foo)
|
115
|
+
end
|
110
116
|
end
|
111
117
|
end
|
data/test/dummy/db/test.sqlite3
CHANGED
Binary file
|
@@ -4,16 +4,13 @@ module Components
|
|
4
4
|
|
5
5
|
class FlashMessagesTest < ActiveSupport::TestCase
|
6
6
|
|
7
|
-
def assigns
|
8
|
-
{ flash: flash }
|
9
|
-
end
|
10
|
-
|
11
|
-
def flash
|
12
|
-
{notice: "Message"}
|
13
|
-
end
|
14
|
-
|
15
7
|
def helpers
|
16
|
-
|
8
|
+
mock_action_view do
|
9
|
+
def flash
|
10
|
+
{notice: "Message"}
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
17
14
|
end
|
18
15
|
|
19
16
|
def flashmsg
|
@@ -20,28 +20,22 @@ module Components
|
|
20
20
|
}
|
21
21
|
end
|
22
22
|
|
23
|
-
def assigns
|
24
|
-
{ current_menu: current_menu,
|
25
|
-
current_menu_name: current_menu_name,
|
26
|
-
foo_path: 'foo',
|
27
|
-
bar_path: 'bar',
|
28
|
-
baz_path: 'baz'
|
29
|
-
}
|
30
|
-
end
|
31
|
-
|
32
|
-
def current_menu
|
33
|
-
MenuItem.new('Big Menu', 'menu_path', [
|
34
|
-
MenuItem.new('Foo', 'foo_path',[]),
|
35
|
-
MenuItem.new('Bar', 'bar_path', []),
|
36
|
-
MenuItem.new('Baz', 'baz_path', [])])
|
37
|
-
end
|
38
|
-
|
39
|
-
def current_menu_name
|
40
|
-
current_menu.title
|
41
|
-
end
|
42
|
-
|
43
23
|
def helpers
|
44
|
-
mock_action_view
|
24
|
+
mock_action_view do
|
25
|
+
def foo_path ; "foo" ; end
|
26
|
+
def bar_path ; "bar" ; end
|
27
|
+
def baz_path ; "baz" ; end
|
28
|
+
def current_menu
|
29
|
+
MenuItem.new('Big Menu', 'menu_path', [
|
30
|
+
MenuItem.new('Foo', 'foo_path',[]),
|
31
|
+
MenuItem.new('Bar', 'bar_path', []),
|
32
|
+
MenuItem.new('Baz', 'baz_path', [])])
|
33
|
+
end
|
34
|
+
def current_menu_name
|
35
|
+
current_menu.title
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
45
39
|
end
|
46
40
|
|
47
41
|
test "renders the correct current menu name as sidebar title" do
|
@@ -49,7 +43,7 @@ module Components
|
|
49
43
|
end
|
50
44
|
|
51
45
|
test "evals the correct path" do
|
52
|
-
assert_equal "foo", helpers.instance_eval(current_menu.items.first.path)
|
46
|
+
assert_equal "foo", helpers.instance_eval(helpers.current_menu.items.first.path)
|
53
47
|
end
|
54
48
|
|
55
49
|
end
|
@@ -5,11 +5,11 @@ module ExpressAdmin
|
|
5
5
|
class SmartFormTest < ActiveSupport::TestCase
|
6
6
|
|
7
7
|
def resource_assigns
|
8
|
-
{
|
8
|
+
{example_engine: ExampleEngine::MockRouteProxy.new}
|
9
9
|
end
|
10
10
|
|
11
11
|
def helpers
|
12
|
-
view = mock_action_view
|
12
|
+
view = mock_action_view
|
13
13
|
class << view
|
14
14
|
def widget_path(widget_id)
|
15
15
|
"/widgets/#{widget_id.to_param}"
|
@@ -27,7 +27,7 @@ module ExpressAdmin
|
|
27
27
|
end
|
28
28
|
|
29
29
|
def widget_form(*args)
|
30
|
-
arbre {
|
30
|
+
arbre(widget: Widget.new) {
|
31
31
|
smart_form(:widget, *args)
|
32
32
|
}
|
33
33
|
end
|
@@ -55,7 +55,7 @@ module ExpressAdmin
|
|
55
55
|
end
|
56
56
|
|
57
57
|
test "text field column3 is a text_area" do
|
58
|
-
assert_match /<textarea.*
|
58
|
+
assert_match /<textarea.*name="widget\[column3\]".*rows="10"/, widget_form
|
59
59
|
end
|
60
60
|
|
61
61
|
test "datetime field column4 is a datetime_field" do
|
@@ -5,20 +5,17 @@ module Components
|
|
5
5
|
|
6
6
|
fixtures :widgets, :categories
|
7
7
|
|
8
|
-
def resource_assigns
|
9
|
-
{resource: Widget.new, collection: Widget.all}
|
10
|
-
end
|
11
8
|
def helpers
|
12
|
-
view = mock_action_view
|
13
|
-
class << view
|
9
|
+
view = mock_action_view do
|
14
10
|
def widget_path(widget_id)
|
15
11
|
"/widgets/#{widget_id.to_param}"
|
16
12
|
end
|
17
13
|
end
|
18
14
|
view
|
19
15
|
end
|
16
|
+
|
20
17
|
def compiled_widget_table(*args)
|
21
|
-
arbre {
|
18
|
+
arbre(widget: Widget.first, widgets: Widget.all) {
|
22
19
|
smart_table(:widgets, *args)
|
23
20
|
}
|
24
21
|
end
|
@@ -65,7 +62,7 @@ module Components
|
|
65
62
|
end
|
66
63
|
|
67
64
|
def compiled_widget_table_with_proc_column
|
68
|
-
arbre {
|
65
|
+
arbre(widget: Widget.first, widgets: Widget.all) {
|
69
66
|
smart_table(:widgets, columns: {
|
70
67
|
"This column will error" => -> (widget) { doesnt_work },
|
71
68
|
"This column will be fine" => -> (widget) { widget.column2.upcase },
|
@@ -86,7 +83,7 @@ module Components
|
|
86
83
|
end
|
87
84
|
|
88
85
|
test 'attribute accessor appended with _link generates a link' do
|
89
|
-
fragment = arbre {
|
86
|
+
fragment = arbre(widget: Widget.first, widgets: Widget.all) {
|
90
87
|
smart_table(:widgets, columns: {
|
91
88
|
'A link column' => :column3_link
|
92
89
|
})
|
@@ -95,7 +92,7 @@ module Components
|
|
95
92
|
end
|
96
93
|
|
97
94
|
test 'timestamp accessor appeneded with _in_words generates code that uses time_ago_in_words' do
|
98
|
-
fragment = arbre {
|
95
|
+
fragment = arbre(widget: Widget.first, widgets: Widget.all) {
|
99
96
|
smart_table(:widgets, columns: {
|
100
97
|
'Created' => :created_at_in_words
|
101
98
|
})
|
@@ -5,25 +5,25 @@ module ExpressAdmin
|
|
5
5
|
class WidgetBoxTest < ActiveSupport::TestCase
|
6
6
|
|
7
7
|
def helpers
|
8
|
-
mock_action_view
|
8
|
+
mock_action_view
|
9
9
|
end
|
10
10
|
|
11
11
|
def assigns
|
12
|
-
{
|
12
|
+
{category: Category.first}
|
13
13
|
end
|
14
14
|
|
15
15
|
def rendered_widget_box(*args)
|
16
16
|
arbre {
|
17
|
-
widget_box(:
|
17
|
+
widget_box(:category, *args)
|
18
18
|
}
|
19
19
|
end
|
20
20
|
|
21
21
|
test "renders correct widget box title" do
|
22
|
-
assert_match /<header class="title">Edit
|
22
|
+
assert_match /<header class="title">Edit Category/, rendered_widget_box
|
23
23
|
end
|
24
24
|
|
25
25
|
test "renders correct widget box title with param" do
|
26
|
-
assert_match /<header class="title">
|
26
|
+
assert_match /<header class="title">Category Box/, rendered_widget_box(title: "Category Box")
|
27
27
|
end
|
28
28
|
|
29
29
|
end
|
data/test/test_helper.rb
CHANGED
@@ -56,21 +56,23 @@ end
|
|
56
56
|
|
57
57
|
module ActiveSupport
|
58
58
|
class TestCase
|
59
|
-
def arbre(
|
60
|
-
Arbre::Context.new assigns, helpers, &block
|
59
|
+
def arbre(additional_assigns = {}, &block)
|
60
|
+
Arbre::Context.new assigns.merge(additional_assigns), helpers, &block
|
61
61
|
end
|
62
|
-
def
|
62
|
+
def assigns
|
63
|
+
@arbre_assigns ||={}
|
64
|
+
end
|
65
|
+
def helpers
|
66
|
+
mock_action_view
|
67
|
+
end
|
68
|
+
def mock_action_view &block
|
63
69
|
controller = ActionView::TestCase::TestController.new
|
64
70
|
ActionView::Base.send :include, ActionView::Helpers
|
65
71
|
ActionView::Base.send :include, ActionView::Helpers::UrlHelper
|
66
72
|
ActionView::Base.send :include, AdditionalHelpers
|
67
73
|
view = ActionView::Base.new(ActionController::Base.view_paths, assigns, controller)
|
68
|
-
eigenklass = class << view
|
69
|
-
|
70
|
-
end
|
71
|
-
assigns.each do |helper_name,value|
|
72
|
-
eigenklass.send(:define_method, helper_name) { value }
|
73
|
-
end
|
74
|
+
eigenklass = class << view; self; end
|
75
|
+
eigenklass.class_eval &block unless block.nil?
|
74
76
|
view
|
75
77
|
end
|
76
78
|
end
|
Binary file
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module ExpressTemplates
|
2
|
+
module Components
|
3
|
+
class All < Container
|
4
|
+
|
5
|
+
has_argument :id, "Name of the collection", as: :collection_name, type: :symbol
|
6
|
+
|
7
|
+
contains -> (&block) {
|
8
|
+
prepended
|
9
|
+
collection.each do |item|
|
10
|
+
assigns[member_name] = item
|
11
|
+
block.call(self) if block
|
12
|
+
end
|
13
|
+
appended
|
14
|
+
}
|
15
|
+
|
16
|
+
def member_name
|
17
|
+
config[:collection_name].to_s.singularize.to_sym
|
18
|
+
end
|
19
|
+
|
20
|
+
def collection
|
21
|
+
self.send(config[:collection_name])
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
data/vendor/gems/express_templates/lib/express_templates/components/capabilities/resourceful.rb
CHANGED
@@ -120,7 +120,7 @@ module ExpressTemplates
|
|
120
120
|
config[:collection]
|
121
121
|
end
|
122
122
|
else
|
123
|
-
|
123
|
+
self.send(collection_name)
|
124
124
|
end
|
125
125
|
end
|
126
126
|
|
@@ -165,19 +165,15 @@ module ExpressTemplates
|
|
165
165
|
end
|
166
166
|
|
167
167
|
def path_namespace
|
168
|
-
resource_class_name =
|
168
|
+
resource_class_name = resource.class.to_s
|
169
169
|
resource_class_name.match(/::/) ?
|
170
170
|
resource_class_name.split("::").first.try(:underscore) : nil
|
171
171
|
end
|
172
172
|
|
173
|
-
|
174
|
-
# and also may accept a resource on which we call to_param
|
175
|
-
def resource_path(ivar_or_resource = nil)
|
173
|
+
def resource_path(object = nil)
|
176
174
|
if config[:resource_path]
|
177
|
-
if config[:resource_path].respond_to?(:call) &&
|
178
|
-
|
179
|
-
![true, false].include?(ivar_or_resource)
|
180
|
-
config[:resource_path].call(ivar_or_resource)
|
175
|
+
if config[:resource_path].respond_to?(:call) && object.respond_to?(:to_param)
|
176
|
+
config[:resource_path].call(object)
|
181
177
|
else
|
182
178
|
config[:resource_path]
|
183
179
|
end
|
@@ -186,12 +182,7 @@ module ExpressTemplates
|
|
186
182
|
helpers.resource.to_param.present? # skip on nil resource
|
187
183
|
helpers.resource_path
|
188
184
|
else
|
189
|
-
|
190
|
-
![true, false].include?(ivar_or_resource)
|
191
|
-
helpers.instance_eval("#{resource_path_helper}('#{ivar_or_resource.to_param}')")
|
192
|
-
else
|
193
|
-
helpers.instance_eval("#{resource_path_helper}(#{ivar_or_resource ? '@' : ''}#{resource_name})")
|
194
|
-
end
|
185
|
+
helpers.send(resource_path_helper, object)
|
195
186
|
end
|
196
187
|
end
|
197
188
|
end
|
@@ -207,6 +198,11 @@ module ExpressTemplates
|
|
207
198
|
def resource_attributes
|
208
199
|
resource_class.columns
|
209
200
|
end
|
201
|
+
|
202
|
+
def resource
|
203
|
+
assigns.try(:[], resource_name.to_sym)
|
204
|
+
# self.send(resource_name)
|
205
|
+
end
|
210
206
|
end
|
211
207
|
end
|
212
208
|
end
|
@@ -11,7 +11,7 @@ module ExpressTemplates
|
|
11
11
|
class #{type.classify} < FormComponent
|
12
12
|
contains {
|
13
13
|
label_tag(label_name, label_text)
|
14
|
-
#{type}
|
14
|
+
#{type}_field_tag field_name_attribute, field_value, field_helper_options
|
15
15
|
}
|
16
16
|
end
|
17
17
|
RUBY
|
@@ -24,20 +24,20 @@ RUBY
|
|
24
24
|
# class Email < FormComponent
|
25
25
|
# contains {
|
26
26
|
# label_tag label_name, label_text
|
27
|
-
# email_field
|
27
|
+
# email_field field_name_attribute, field_value, field_helper_options
|
28
28
|
# }
|
29
29
|
# end
|
30
30
|
|
31
31
|
class Textarea < FormComponent
|
32
32
|
contains {
|
33
33
|
label_tag(label_name, label_text)
|
34
|
-
|
34
|
+
text_area_tag field_name_attribute, field_value, field_helper_options
|
35
35
|
}
|
36
36
|
end
|
37
37
|
|
38
38
|
class Hidden < FormComponent
|
39
39
|
contains {
|
40
|
-
|
40
|
+
hidden_field_tag field_name_attribute, field_value, field_helper_options
|
41
41
|
}
|
42
42
|
end
|
43
43
|
end
|
@@ -7,7 +7,7 @@ module ExpressTemplates
|
|
7
7
|
|
8
8
|
contains {
|
9
9
|
label_tag(label_name, label_text) if label_before?
|
10
|
-
check_box(
|
10
|
+
check_box(resource_name, field_name.to_sym, field_options, checked_value, unchecked_value)
|
11
11
|
label_tag(label_name, label_text) if label_after?
|
12
12
|
}
|
13
13
|
|
@@ -8,12 +8,16 @@ module ExpressTemplates
|
|
8
8
|
|
9
9
|
has_option :method, 'The form method', default: 'POST', attribute: true #, options: ['PUT', 'POST', 'GET', 'DELETE']
|
10
10
|
has_option :action, 'The form action containing the resource path or url.'
|
11
|
+
has_option :on_success, 'Pass a form value indicating where to go on a successful submission.'
|
12
|
+
has_option :on_failure, 'Pass a form value indicating where to go on a failed submission.'
|
11
13
|
|
12
14
|
prepends -> {
|
13
15
|
div(style: 'display:none') {
|
14
16
|
add_child helpers.utf8_enforcer_tag
|
15
17
|
add_child helpers.send(:method_tag, resource.persisted? ? :put : :post)
|
16
|
-
helpers.send(:token_tag)
|
18
|
+
add_child helpers.send(:token_tag)
|
19
|
+
hidden_field_tag :on_success, config[:on_success] if config[:on_success]
|
20
|
+
hidden_field_tag :on_failure, config[:on_failure] if config[:on_failure]
|
17
21
|
}
|
18
22
|
}
|
19
23
|
|
@@ -28,7 +32,7 @@ module ExpressTemplates
|
|
28
32
|
end
|
29
33
|
|
30
34
|
def form_action
|
31
|
-
config[:action] || (resource.try(:persisted?) ? resource_path(
|
35
|
+
config[:action] || (resource.try(:persisted?) ? resource_path(resource) : collection_path)
|
32
36
|
end
|
33
37
|
|
34
38
|
end
|
@@ -15,16 +15,16 @@ module ExpressTemplates
|
|
15
15
|
has_option :wrapper_class, 'Override the class of the wrapping div of a form component', default: 'field-wrapper'
|
16
16
|
has_option :label, 'Override the inferred label of a form component'
|
17
17
|
|
18
|
+
def resource
|
19
|
+
self.send(resource_name)
|
20
|
+
end
|
21
|
+
|
18
22
|
# Lookup the resource_name from the parent ExpressForm.
|
19
23
|
def resource_name
|
20
24
|
raise "FormComponent must have a parent form" unless parent_form
|
21
25
|
parent_form.config[:id].to_s
|
22
26
|
end
|
23
27
|
|
24
|
-
def resource_var
|
25
|
-
resource_name.to_sym
|
26
|
-
end
|
27
|
-
|
28
28
|
def resource_class
|
29
29
|
parent_form.resource_class
|
30
30
|
end
|
@@ -45,12 +45,24 @@ module ExpressTemplates
|
|
45
45
|
(config[:id] || (@args.first.is_a?(String) && @args.first)).to_s
|
46
46
|
end
|
47
47
|
|
48
|
+
def field_value
|
49
|
+
resource.send(field_name)
|
50
|
+
end
|
51
|
+
|
48
52
|
# Return the field name attribute. Currently handles only simple attributes
|
49
53
|
# on the resource. Does not handle attributes for associated resources.
|
50
54
|
def field_name_attribute
|
51
55
|
"#{resource_name.singularize}[#{field_name}]"
|
52
56
|
end
|
53
57
|
|
58
|
+
def field_id_attribute
|
59
|
+
"#{resource_name.singularize}_#{field_name}"
|
60
|
+
end
|
61
|
+
|
62
|
+
def field_helper_options
|
63
|
+
{id: field_id_attribute}.merge(input_attributes||nil)
|
64
|
+
end
|
65
|
+
|
54
66
|
# Search the parent graph until we find an ExpressForm. Returns nil if none found.
|
55
67
|
def parent_form
|
56
68
|
@my_form ||= parent
|