Class: Avo::Views::ResourceEditComponent
- Inherits:
-
ResourceComponent
- Object
- ResourceComponent
- Avo::Views::ResourceEditComponent
- Includes:
- ApplicationHelper, Concerns::FormBuilder
- Defined in:
- app/components/avo/views/resource_edit_component.rb
Constant Summary
Constants included from ApplicationHelper
ApplicationHelper::UNRENDERABLE_IMAGE_CONTENT_TYPES
Instance Method Summary collapse
- #back_path ⇒ Object
- #can_see_the_destroy_button? ⇒ Boolean
-
#can_see_the_save_button? ⇒ Boolean
The save button is dependent on the edit? policy method.
- #controls ⇒ Object
-
#embedded_in_modal? ⇒ Boolean
True when the form is shown inside a modal opened from a belongs_to "Create new" link.
-
#render_form_items(form) ⇒ Object
Renders the form panels.
- #resource_view_path ⇒ Object
- #resources_path ⇒ Object
- #title ⇒ Object
Methods included from Concerns::FormBuilder
Methods included from ApplicationHelper
#a_button, #a_link, #appearance_neutral_labels, #avo_appearance_t, #body_classes, #button_classes, #chart_color, #container_classes, #custom_sidebar_width_default, #d, #decode_filter_params, #e, #editor_file_path, #editor_url, #empty_state, #encode_filter_params, #frame_id, #get_model_class, #input_classes, #manual_frame_cookie_name, #manual_frame_remembered?, #mount_path, #number_to_social, #possibly_rails_authentication?, #render_header_menu_items, #render_license_warning, #root_path_without_url, #rtl?, #safe_blob_path, #safe_blob_representation_url, #safe_blob_url, #safe_image_url, #sidebar_width_default, #sidebar_width_max, #sidebar_width_min, #text_direction, #ui, #wrap_in_modal
Methods included from SummaryChartHelper
Methods included from ResourcesHelper
#field_wrapper, #index_field_wrapper, #item_selector_data_attributes, #record_path, #record_title, #resource_for_record, #resource_grid, #resource_show_path, #resource_table
Instance Method Details
#back_path ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'app/components/avo/views/resource_edit_component.rb', line 16 def back_path # The `return_to` param takes precedence over anything else. return params[:return_to] if params[:return_to].present? return resource_view_path if via_resource? return resources_path if via_index? if is_edit? && Avo.configuration.resource_default_view.show? # via resource show or edit page return helpers.resource_path(record: @resource.record, resource: @resource, **keep_referrer_params) end resources_path end |
#can_see_the_destroy_button? ⇒ Boolean
38 39 40 41 42 |
# File 'app/components/avo/views/resource_edit_component.rb', line 38 def return super if is_edit? && Avo.configuration.resource_default_view.edit? false end |
#can_see_the_save_button? ⇒ Boolean
The save button is dependent on the edit? policy method. The update? method should be called only when the user clicks the Save button so the developer gets access to the params from the form.
46 47 48 |
# File 'app/components/avo/views/resource_edit_component.rb', line 46 def @resource.. @view, raise_exception: false end |
#controls ⇒ Object
50 51 52 |
# File 'app/components/avo/views/resource_edit_component.rb', line 50 def controls @resource.render_edit_controls end |
#embedded_in_modal? ⇒ Boolean
True when the form is shown inside a modal opened from a belongs_to "Create new" link. In that case the title moves to the modal header and the controls move to the modal footer, so the in-form panel header is skipped.
57 58 59 |
# File 'app/components/avo/views/resource_edit_component.rb', line 57 def params[:via_belongs_to_resource_class].present? end |
#render_form_items(form) ⇒ Object
Renders the form panels. When embedded in a modal the panel header is dropped — its title and controls live in the modal chrome instead.
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'app/components/avo/views/resource_edit_component.rb', line 63 def render_form_items(form) items = @resource.get_items items = items.reject(&:is_header?) if safe_join(items.each_with_index.map do |item, index| render Avo::Items::SwitcherComponent.new( resource: @resource, reflection: @reflection, item: item, index: index + 1, view: @view, parent_resource: @parent_resource, parent_record: @parent_record, form: form, parent_component: self, actions: @actions ) end) end |
#resource_view_path ⇒ Object
34 35 36 |
# File 'app/components/avo/views/resource_edit_component.rb', line 34 def resource_view_path helpers.resource_view_path(record: association_resource.record, resource: association_resource) end |
#resources_path ⇒ Object
30 31 32 |
# File 'app/components/avo/views/resource_edit_component.rb', line 30 def resources_path helpers.resources_path(resource: @resource, **keep_referrer_params) end |
#title ⇒ Object
12 13 14 |
# File 'app/components/avo/views/resource_edit_component.rb', line 12 def title @resource.default_panel_name end |