Class: Releaf::Builders::EditBuilder
- Inherits:
-
Object
- Object
- Releaf::Builders::EditBuilder
show all
- Includes:
- ResourceView
- Defined in:
- app/builders/releaf/builders/edit_builder.rb
Instance Attribute Summary collapse
Attributes included from Resource
#resource
Attributes included from Template
#template
Instance Method Summary
collapse
#back_to_list?, #back_to_list_button, #footer_secondary_tools, #section, #section_body, #section_body_attributes, #section_header_extras, #section_header_text
Methods included from Toolbox
#toolbox, #toolbox_button, #toolbox_menu
Methods included from Resource
#initialize
Methods included from View
#breadcrumb_item, #breadcrumbs, #dialog?, #dialog_name, #flash_item, #flash_notices, #footer_blocks, #footer_primary_block, #footer_secondary_block, #footer_secondary_tools, #footer_tools, #header, #header_extras, #output, #section, #section_attributes, #section_blocks, #section_body, #section_footer, #section_footer_class, #section_header, #section_header_extras, #section_header_text
Methods included from Template
#initialize
Methods included from Base
#default_translation_scope, #html_escape, #icon, #layout_settings, #locale_options, #resource_title, #safe_join, #t, #tag, #template_variable, #translate_locale, #wrapper
Instance Attribute Details
Returns the value of attribute form.
4
5
6
|
# File 'app/builders/releaf/builders/edit_builder.rb', line 4
def form
@form
end
|
Instance Method Details
#create_another_available? ⇒ Boolean
100
101
102
|
# File 'app/builders/releaf/builders/edit_builder.rb', line 100
def create_another_available?
resource.present? && resource.new_record? && feature_available?(:create_another)
end
|
#error_notices ⇒ Object
77
78
79
80
81
82
83
84
85
86
87
|
# File 'app/builders/releaf/builders/edit_builder.rb', line 77
def error_notices
return unless resource.errors.any?
tag(:div, class: "form-error-box") do
<<
tag(:ul) do
resource.errors.full_messages.collect do|message|
tag(:li, message, class: "error")
end
end
end
end
|
89
90
91
|
# File 'app/builders/releaf/builders/edit_builder.rb', line 89
def
tag(:strong, "#{resource.errors.count} validation #{"error".pluralize(resource.errors.count)} occured:")
end
|
93
94
95
96
97
98
|
# File 'app/builders/releaf/builders/edit_builder.rb', line 93
def
tools = []
tools << save_and_create_another_button if create_another_available?
tools << save_button
tools
end
|
31
32
33
|
# File 'app/builders/releaf/builders/edit_builder.rb', line 31
def form_action
resource.new_record? ? 'create' : 'update'
end
|
63
64
65
66
67
68
69
70
71
72
73
74
75
|
# File 'app/builders/releaf/builders/edit_builder.rb', line 63
def form_attributes
{
multipart: true,
id: form_identifier,
class: form_classes,
data: {
"remote" => true,
"remote-validation" => true,
"type" => :json,
},
novalidate: ""
}
end
|
39
40
41
|
# File 'app/builders/releaf/builders/edit_builder.rb', line 39
def form_builder_class
builder_class(:form)
end
|
57
58
59
60
61
|
# File 'app/builders/releaf/builders/edit_builder.rb', line 57
def form_classes
classes = [ form_identifier ]
classes << "has-error" if resource.errors.any?
classes
end
|
23
24
25
|
# File 'app/builders/releaf/builders/edit_builder.rb', line 23
def form_fields
form.releaf_fields(form.field_names.to_a)
end
|
52
53
54
55
|
# File 'app/builders/releaf/builders/edit_builder.rb', line 52
def form_identifier
action = !resource.respond_to?(:persisted?) || resource.persisted? ? :edit : :new
"#{action}-#{resource_name}"
end
|
43
44
45
46
47
48
49
50
|
# File 'app/builders/releaf/builders/edit_builder.rb', line 43
def form_options
{
builder: form_builder_class,
as: resource_name,
url: form_url,
html: form_attributes
}
end
|
27
28
29
|
# File 'app/builders/releaf/builders/edit_builder.rb', line 27
def form_url
url_for(action: form_action, id: resource.id)
end
|
#index_path_preserver ⇒ Object
15
16
17
|
# File 'app/builders/releaf/builders/edit_builder.rb', line 15
def index_path_preserver
hidden_field_tag "index_path", params[:index_path] if params[:index_path].present?
end
|
#resource_name ⇒ Object
35
36
37
|
# File 'app/builders/releaf/builders/edit_builder.rb', line 35
def resource_name
:resource
end
|
104
105
106
|
# File 'app/builders/releaf/builders/edit_builder.rb', line 104
def save_and_create_another_button
button(t("Save and create another"), "plus", name: "after_save", value: "create_another", class: "secondary", data: { type: 'ok', disable: true }, type: "submit")
end
|
108
109
110
|
# File 'app/builders/releaf/builders/edit_builder.rb', line 108
def save_button
button(t("Save"), "check", class: "primary", data: { type: 'ok', disable: true }, type: "submit")
end
|
#section_body_blocks ⇒ Object
19
20
21
|
# File 'app/builders/releaf/builders/edit_builder.rb', line 19
def section_body_blocks
[error_notices, form_fields]
end
|
#section_content ⇒ Object
6
7
8
9
10
11
12
13
|
# File 'app/builders/releaf/builders/edit_builder.rb', line 6
def section_content
form_for(resource, form_options) do |form|
self.form = form
safe_join do
[index_path_preserver] + section_blocks
end
end
end
|