Class: Avo::Views::ResourceEditComponent

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

Instance Method Summary collapse

Methods included from ApplicationHelper

#a_button, #a_link, #button_classes, #decode_filter_params, #empty_state, #encode_filter_params, #get_model_class, #input_classes, #mount_path, #number_to_social, #render_license_warning, #root_path_without_url, #svg, #white_panel_classes

Methods included from ResourcesHelper

#field_wrapper, #filter_wrapper, #index_field_wrapper, #item_select_all_input, #item_selector_init, #item_selector_input, #resource_grid, #resource_table

Constructor Details

#initialize(resource: nil, record: nil, actions: [], view: "edit") ⇒ ResourceEditComponent

Returns a new instance of ResourceEditComponent.



6
7
8
9
10
11
# File 'app/components/avo/views/resource_edit_component.rb', line 6

def initialize(resource: nil, record: nil, actions: [], view: "edit")
  @resource = resource
  @record = record
  @actions = actions
  @view = Avo::ViewInquirer.new(view)
end

Instance Method Details

#back_pathObject



17
18
19
20
21
22
23
24
25
26
# File 'app/components/avo/views/resource_edit_component.rb', line 17

def back_path
  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)
  end

  resources_path
end

#can_see_the_destroy_button?Boolean

Returns:

  • (Boolean)


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

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)


44
45
46
# File 'app/components/avo/views/resource_edit_component.rb', line 44

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

#resource_view_pathObject



32
33
34
# File 'app/components/avo/views/resource_edit_component.rb', line 32

def resource_view_path
  helpers.resource_view_path(record: association_resource.record, resource: association_resource)
end

#resources_pathObject



28
29
30
# File 'app/components/avo/views/resource_edit_component.rb', line 28

def resources_path
  helpers.resources_path(resource: @resource)
end

#titleObject



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

def title
  @resource.default_panel_name
end