Class: Avo::Views::ResourceEditComponent

Inherits:
ResourceComponent
  • Object
show all
Includes:
ApplicationHelper, Concerns::FormBuilder
Defined in:
app/components/avo/views/resource_edit_component.rb

Instance Method Summary collapse

Methods included from Concerns::FormBuilder

#build_form, #form_url

Methods included from ApplicationHelper

#a_button, #a_link, #body_classes, #button_classes, #chart_color, #container_classes, #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, #text_direction, #ui, #wrap_in_modal

Methods included from SummaryChartHelper

#summary_chart_params_for

Methods included from ResourcesHelper

#field_wrapper, #filter_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_pathObject



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

Returns:

  • (Boolean)


38
39
40
41
42
# File 'app/components/avo/views/resource_edit_component.rb', line 38

def can_see_the_destroy_button?
  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.

Returns:

  • (Boolean)


46
47
48
# File 'app/components/avo/views/resource_edit_component.rb', line 46

def can_see_the_save_button?
  @resource.authorization.authorize_action @view, raise_exception: false
end

#controlsObject



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.

Returns:

  • (Boolean)


57
58
59
# File 'app/components/avo/views/resource_edit_component.rb', line 57

def embedded_in_modal?
  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 embedded_in_modal?

  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_pathObject



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_pathObject



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

#titleObject



12
13
14
# File 'app/components/avo/views/resource_edit_component.rb', line 12

def title
  @resource.default_panel_name
end