Module: Faalis::Dashboard::Sections::Resource

Extended by:
ActiveSupport::Concern
Included in:
DSL
Defined in:
lib/faalis/dashboard/sections/resource.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary (collapse)

Instance Method Details

- (Object) _resource_title



10
11
12
# File 'lib/faalis/dashboard/sections/resource.rb', line 10

def _resource_title
  t(controller_name.humanize)
end

- (Object) _resources (protected)



16
17
18
# File 'lib/faalis/dashboard/sections/resource.rb', line 16

def _resources
  instance_variable_get("@{plural_name")
end

- (Object) _route_engine (protected)



43
44
45
46
47
48
49
# File 'lib/faalis/dashboard/sections/resource.rb', line 43

def _route_engine
  if namespace.empty?
    Rails.application
  else
    "#{namespace.split('/')[0]}::Engine".classify.constantize
  end
end

- (Object) _route_name (private)



59
60
61
# File 'lib/faalis/dashboard/sections/resource.rb', line 59

def _route_name
  nil
end

- (Object) action_buttons(property_object) (protected)

Return the array of action buttons in given property_object. property_object is an instance of once of DSL classes.



53
54
55
# File 'lib/faalis/dashboard/sections/resource.rb', line 53

def action_buttons(property_object)
  @_action_buttons = property_object.action_buttons || []
end

- (Object) attachment_fields (private)



63
64
65
66
67
68
69
# File 'lib/faalis/dashboard/sections/resource.rb', line 63

def attachment_fields
  if model.respond_to? :attachment_definitions
    return model.attachment_definitions.keys
  end

  []
end

- (Object) errorful_resopnse(section, msg = nil) (private)



130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
# File 'lib/faalis/dashboard/sections/resource.rb', line 130

def errorful_resopnse(section, msg = nil)
  @_msg = msg

  respond_to do |f|
    if _override_views.include? section.to_sym
      f.js { render :errors }
      f.html { render :errors }
    else
      flash[:error] = msg
      path = Rails.application.routes.url_helpers.send(@index_route)
      # TODO: We really need to put setup routed on top of this method

      f.js { render 'faalis/shared/errors' }
      f.html { redirect_to path }
    end
  end
end

- (Object) guess_edit_route(scope = 'dashboard') (private)



86
87
88
89
90
# File 'lib/faalis/dashboard/sections/resource.rb', line 86

def guess_edit_route(scope  = 'dashboard')
  scope_        = "#{scope}_"
  resource_name = controller_name.singularize.underscore
  "edit_#{scope_}#{resource_name}_path"
end

- (Object) guess_index_route(scope = 'dashboard') (private)



75
76
77
78
# File 'lib/faalis/dashboard/sections/resource.rb', line 75

def guess_index_route(scope  = 'dashboard')
  scope_ = "#{scope}_"
  "#{scope_}#{controller_name}_path"
end

- (Object) guess_new_route(scope = 'dashboard') (private)



92
93
94
95
96
# File 'lib/faalis/dashboard/sections/resource.rb', line 92

def guess_new_route(scope  = 'dashboard')
  scope_        = "#{scope}_"
  resource_name = controller_name.singularize.underscore
  "new_#{scope_}#{resource_name}_path"
end

- (Object) guess_show_route(scope = 'dashboard') (private)



80
81
82
83
84
# File 'lib/faalis/dashboard/sections/resource.rb', line 80

def guess_show_route(scope  = 'dashboard')
  scope_        = "#{scope}_"
  resource_name = controller_name.singularize.underscore
  "#{scope_}#{resource_name}_path"
end

- (Boolean) has_attachment? (private)

Returns:

  • (Boolean)


71
72
73
# File 'lib/faalis/dashboard/sections/resource.rb', line 71

def has_attachment?
  !attachment_fields.empty?
end

- (Object) model (protected)



28
29
30
31
32
33
34
# File 'lib/faalis/dashboard/sections/resource.rb', line 28

def model
  "::#{model_name}".constantize
rescue
  msg = "Can't find model '::#{model_name}'. Please override \
        'model' method in your dashboard controller."
  fail NameError, msg
end

- (Object) model_name (protected)



24
25
26
# File 'lib/faalis/dashboard/sections/resource.rb', line 24

def model_name
  controller_path.gsub('dashboard/', '').classify
end

- (Object) namespace (protected)



36
37
38
39
40
41
# File 'lib/faalis/dashboard/sections/resource.rb', line 36

def namespace
  pieces = controller_path.gsub('dashboard/', '').split('/')
  return '' if pieces.length == 1
  pieces.pop
  pieces.join('/')
end

- (Object) plural_name (protected)



20
21
22
# File 'lib/faalis/dashboard/sections/resource.rb', line 20

def plural_name
  controller_name.underscore
end

- (Object) setup_named_routes (private)



104
105
106
107
108
109
110
# File 'lib/faalis/dashboard/sections/resource.rb', line 104

def setup_named_routes
  @engine        = _route_engine
  @index_route   = guess_index_route
  @new_route     = guess_new_route
  @show_route    = guess_show_route
  @edit_route    = guess_edit_route
end

- (Object) successful_response(section, msg = nil) (private)



112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/faalis/dashboard/sections/resource.rb', line 112

def successful_response(section, msg = nil)
  @_msg = msg

  respond_to do |f|
    if _override_views.include? section.to_sym
      f.js
      f.html
    else
      flash[:success] = msg

      path = Rails.application.routes.url_helpers.send(@index_route)
      # TODO: We really need to put setup routed on top of this method
      f.js { render "faalis/dashboard/resource/#{section}" }
      f.html { redirect_to path }
    end
  end
end

- (Object) symbolify_keys(hash) (private)

TODO: Move this method to a suitable place



149
150
151
# File 'lib/faalis/dashboard/sections/resource.rb', line 149

def symbolify_keys(hash)
  hash.inject({}){|memo,(k,v)| memo[k.to_sym] = v; memo}
end