Class: Jav::Views::ResourceEditComponent

Inherits:
ResourceComponent
  • Object
show all
Includes:
ApplicationHelper, ResourcesHelper
Defined in:
app/components/jav/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, #frame_id, #get_model_class, #input_classes, #mount_path, #render_license_warning, #render_license_warnings, #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, model: nil, actions: [], view: :edit, display_breadcrumbs: true) ⇒ ResourceEditComponent

Returns a new instance of ResourceEditComponent.



7
8
9
10
11
12
13
14
# File 'app/components/jav/views/resource_edit_component.rb', line 7

def initialize(resource: nil, model: nil, actions: [], view: :edit, display_breadcrumbs: true)
  super
  @resource = resource
  @model = model
  @actions = actions
  @view = view
  @display_breadcrumbs = display_breadcrumbs
end

Instance Method Details

#back_pathObject



20
21
22
23
24
25
26
27
28
# File 'app/components/jav/views/resource_edit_component.rb', line 20

def back_path
  return if via_belongs_to?
  return resource_view_path if via_resource?
  return resources_path if via_index?

  return helpers.resource_path(model: @resource.model, resource: @resource) if is_edit? && Jav.configuration.resource_default_view == :show # via resource show or edit page

  resources_path
end

#can_see_the_destroy_button?Boolean

Returns:

  • (Boolean)


40
41
42
43
44
# File 'app/components/jav/views/resource_edit_component.rb', line 40

def can_see_the_destroy_button?
  return super if is_edit? && Jav.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)


48
49
50
# File 'app/components/jav/views/resource_edit_component.rb', line 48

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

#display_breadcrumbs?Boolean

Returns:

  • (Boolean)


52
53
54
# File 'app/components/jav/views/resource_edit_component.rb', line 52

def display_breadcrumbs?
  @reflection.blank? && @display_breadcrumbs
end

#resource_view_pathObject



34
35
36
37
38
# File 'app/components/jav/views/resource_edit_component.rb', line 34

def resource_view_path
  return helpers.resource_view_path(model: association_resource.model, resource: association_resource, active_tab_name: params[:active_tab_name]) if params[:active_tab_name].present?

  helpers.resource_view_path(model: association_resource.model, resource: association_resource)
end

#resources_pathObject



30
31
32
# File 'app/components/jav/views/resource_edit_component.rb', line 30

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

#titleObject



16
17
18
# File 'app/components/jav/views/resource_edit_component.rb', line 16

def title
  @resource.default_panel_name
end