Class: Releaf::ActionController

Inherits:
ActionController::Base
  • Object
show all
Includes:
Ajax, Breadcrumbs, Builders, Features, Notifications, Resources, RichtextAttachments, Search, Urls, Views, Responders
Defined in:
app/controllers/releaf/action_controller.rb

Defined Under Namespace

Modules: Ajax, Breadcrumbs, Builders, Features, Notifications, Resources, RichtextAttachments, Search, Urls, Views

Instance Method Summary collapse

Methods included from Responders

#action_responder, #action_responders, #active_responder, #respond_with

Methods included from Views

#action_view, #action_views, #active_view

Methods included from RichtextAttachments

#create_releaf_richtext_attachment, #releaf_richtext_attachment_upload_url

Methods included from Breadcrumbs

#add_resource_breadcrumb, #build_breadcrumbs, #controller_breadcrumb

Methods included from Urls

#current_path, #index_path, #resolve_index_path, #success_path, #valid_index_path?

Methods included from Ajax

#ajax?, #layout, #manage_ajax

Methods included from Features

#action_feature, #action_features, #feature_available?, #feature_disabled, #features, #verify_feature_availability!

Methods included from Search

#search, #searchable_fields, #searcher_class

Methods included from Builders

#application_scope, #builder_class, #builder_scopes

Methods included from Resources

#load_resource, #new_resource, #permitted_params, #resource_class, #resource_given?, #resource_params, #resources, #resources_per_page

Methods included from Notifications

#notice_scope_name, #render_notification

Instance Method Details

#access_deniedObject



140
141
142
# File 'app/controllers/releaf/action_controller.rb', line 140

def access_denied
  respond_with(nil, responder: action_responder(:access_denied))
end

#collection_given?Boolean

Returns true if @collection is assigned (even if it’s nil)

Returns:

  • (Boolean)


128
129
130
# File 'app/controllers/releaf/action_controller.rb', line 128

def collection_given?
  !!defined? @collection
end

#confirm_destroyObject



60
61
62
63
64
# File 'app/controllers/releaf/action_controller.rb', line 60

def confirm_destroy
  prepare_destroy
  @restricted_relations = Releaf::ResourceUtilities.restricted_relations(@resource)
  respond_with(@resource, destroyable: destroyable?)
end

#controller_scope_nameObject

return contoller translation scope name for using with I18.translation call within hash params ex. t(“save”, scope: controller_scope_name)



154
155
156
# File 'app/controllers/releaf/action_controller.rb', line 154

def controller_scope_name
  @controller_scope_name ||= 'admin.' + self.class.name.sub(/Controller$/, '').underscore.tr('/', '_')
end

#createObject



48
49
50
51
52
# File 'app/controllers/releaf/action_controller.rb', line 48

def create
  prepare_create
  @resource.save
  respond_with(@resource, location: (success_path if @resource.persisted?), redirect: true)
end

#create_another?Boolean

Returns:

  • (Boolean)


136
137
138
# File 'app/controllers/releaf/action_controller.rb', line 136

def create_another?
  params[:after_save] == "create_another" && feature_available?(:create_another)
end

#definitionObject



169
170
171
# File 'app/controllers/releaf/action_controller.rb', line 169

def definition
  Releaf::ControllerDefinition.for(short_name)
end

#destroyObject



71
72
73
74
75
# File 'app/controllers/releaf/action_controller.rb', line 71

def destroy
  prepare_destroy
  @resource.destroy if destroyable?
  respond_with(@resource, location: index_path)
end

#destroyable?Boolean

Check if @resource has existing restrict relation and it can be deleted

Returns:

  • (Boolean)

    boolean true or false



147
148
149
# File 'app/controllers/releaf/action_controller.rb', line 147

def destroyable?
  Releaf::ResourceUtilities.destroyable?(@resource)
end

#editObject



43
44
45
46
# File 'app/controllers/releaf/action_controller.rb', line 43

def edit
  prepare_edit
  respond_with(@resource)
end

#indexObject



25
26
27
28
# File 'app/controllers/releaf/action_controller.rb', line 25

def index
  prepare_index
  respond_with(@collection)
end

#newObject



30
31
32
33
# File 'app/controllers/releaf/action_controller.rb', line 30

def new
  prepare_new
  respond_with(@resource)
end

#page_titleObject



158
159
160
161
162
163
# File 'app/controllers/releaf/action_controller.rb', line 158

def page_title
  title = Rails.application.class.parent_name
  title = "#{definition.localized_name} - #{title}" if definition

  title
end

#prepare_createObject



94
95
96
97
98
# File 'app/controllers/releaf/action_controller.rb', line 94

def prepare_create
  # load resource only if is not initialized yet
  new_resource unless resource_given?
  @resource.assign_attributes(resource_params)
end

#prepare_destroyObject



119
120
121
# File 'app/controllers/releaf/action_controller.rb', line 119

def prepare_destroy
  load_resource
end

#prepare_editObject



104
105
106
# File 'app/controllers/releaf/action_controller.rb', line 104

def prepare_edit
  prepare_resource_view
end

#prepare_indexObject



77
78
79
80
81
82
83
84
85
86
# File 'app/controllers/releaf/action_controller.rb', line 77

def prepare_index
  # load resource only if they are not loaded yet
  @collection = resources unless collection_given?

  search(params[:search])

  unless resources_per_page.nil?
    @collection = @collection.page( params[:page] ).per_page( resources_per_page )
  end
end

#prepare_newObject



88
89
90
91
92
# File 'app/controllers/releaf/action_controller.rb', line 88

def prepare_new
  # load resource only if is not initialized yet
  new_resource unless resource_given?
  add_resource_breadcrumb(@resource)
end

#prepare_resource_viewObject



108
109
110
111
112
# File 'app/controllers/releaf/action_controller.rb', line 108

def prepare_resource_view
  # load resource only if is not loaded yet
  load_resource unless resource_given?
  add_resource_breadcrumb(@resource)
end

#prepare_showObject



100
101
102
# File 'app/controllers/releaf/action_controller.rb', line 100

def prepare_show
  prepare_resource_view
end

#prepare_toolboxObject



123
124
125
# File 'app/controllers/releaf/action_controller.rb', line 123

def prepare_toolbox
  load_resource
end

#prepare_updateObject



114
115
116
117
# File 'app/controllers/releaf/action_controller.rb', line 114

def prepare_update
  # load resource only if is not loaded yet
  load_resource unless resource_given?
end

#required_paramsObject



132
133
134
# File 'app/controllers/releaf/action_controller.rb', line 132

def required_params
  params.require(:resource)
end

#short_nameObject



165
166
167
# File 'app/controllers/releaf/action_controller.rb', line 165

def short_name
  self.class.name.sub(/Controller$/, "").underscore
end

#showObject



35
36
37
38
39
40
41
# File 'app/controllers/releaf/action_controller.rb', line 35

def show
  if feature_available?(:show)
    prepare_show
  else
    redirect_to url_for(action: 'edit', id: params[:id])
  end
end

#toolboxObject



66
67
68
69
# File 'app/controllers/releaf/action_controller.rb', line 66

def toolbox
  prepare_toolbox
  respond_with(@resource)
end

#updateObject



54
55
56
57
58
# File 'app/controllers/releaf/action_controller.rb', line 54

def update
  prepare_update
  @resource.update_attributes(resource_params)
  respond_with(@resource, location: success_path)
end