Class: Releaf::ActionController

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

Defined Under Namespace

Modules: Ajax, Breadcrumbs, Builders, Exceptions, Features, Layout, 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 Exceptions

#access_denied, #page_not_found

Methods included from Layout

#layout_features

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?, #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

#collection_given?Boolean

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

Returns:

  • (Boolean)

130
131
132
# File 'app/controllers/releaf/action_controller.rb', line 130

def collection_given?
  !!defined? @collection
end

#confirm_destroyObject


62
63
64
65
66
# File 'app/controllers/releaf/action_controller.rb', line 62

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)


152
153
154
# File 'app/controllers/releaf/action_controller.rb', line 152

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

#createObject


50
51
52
53
54
# File 'app/controllers/releaf/action_controller.rb', line 50

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

#create_another?Boolean

Returns:

  • (Boolean)

138
139
140
# File 'app/controllers/releaf/action_controller.rb', line 138

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

#definitionObject


167
168
169
# File 'app/controllers/releaf/action_controller.rb', line 167

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

#destroyObject


73
74
75
76
77
# File 'app/controllers/releaf/action_controller.rb', line 73

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


145
146
147
# File 'app/controllers/releaf/action_controller.rb', line 145

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

#editObject


45
46
47
48
# File 'app/controllers/releaf/action_controller.rb', line 45

def edit
  prepare_edit
  respond_with(@resource)
end

#indexObject


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

def index
  prepare_index
  respond_with(@collection)
end

#newObject


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

def new
  prepare_new
  respond_with(@resource)
end

#page_titleObject


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

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

  title
end

#prepare_createObject


96
97
98
99
100
# File 'app/controllers/releaf/action_controller.rb', line 96

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

#prepare_destroyObject


121
122
123
# File 'app/controllers/releaf/action_controller.rb', line 121

def prepare_destroy
  load_resource
end

#prepare_editObject


106
107
108
# File 'app/controllers/releaf/action_controller.rb', line 106

def prepare_edit
  prepare_resource_view
end

#prepare_indexObject


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

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


90
91
92
93
94
# File 'app/controllers/releaf/action_controller.rb', line 90

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

#prepare_resource_viewObject


110
111
112
113
114
# File 'app/controllers/releaf/action_controller.rb', line 110

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

#prepare_showObject


102
103
104
# File 'app/controllers/releaf/action_controller.rb', line 102

def prepare_show
  prepare_resource_view
end

#prepare_toolboxObject


125
126
127
# File 'app/controllers/releaf/action_controller.rb', line 125

def prepare_toolbox
  load_resource
end

#prepare_updateObject


116
117
118
119
# File 'app/controllers/releaf/action_controller.rb', line 116

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

#required_paramsObject


134
135
136
# File 'app/controllers/releaf/action_controller.rb', line 134

def required_params
  params.require(:resource)
end

#short_nameObject


163
164
165
# File 'app/controllers/releaf/action_controller.rb', line 163

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

#showObject


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

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

#toolboxObject


68
69
70
71
# File 'app/controllers/releaf/action_controller.rb', line 68

def toolbox
  prepare_toolbox
  respond_with(@resource)
end

#updateObject


56
57
58
59
60
# File 'app/controllers/releaf/action_controller.rb', line 56

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