Class: Releaf::Content::NodesController

Inherits:
ActionController
  • Object
show all
Defined in:
app/controllers/releaf/content/nodes_controller.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.resource_classObject



61
62
63
64
65
# File 'app/controllers/releaf/content/nodes_controller.rb', line 61

def self.resource_class
  # find first key in content resources config that has this class as controller
  model_class_name = Releaf::Content.resources.find{|_model_name, options| options[:controller] == name }.first
  model_class_name.constantize
end

Instance Method Details

#add_resource_breadcrumb(resource) ⇒ Object

override base_controller method for adding content tree ancestors to breadcrumbs



44
45
46
47
48
49
# File 'app/controllers/releaf/content/nodes_controller.rb', line 44

def add_resource_breadcrumb(resource)
  ancestor_nodes(resource).each do |node|
    @breadcrumbs << { name: node, url: url_for( action: :edit, id: node.id ) }
  end
  super
end

#ancestor_nodes(resource) ⇒ Object



51
52
53
54
55
56
57
58
59
# File 'app/controllers/releaf/content/nodes_controller.rb', line 51

def ancestor_nodes(resource)
  if resource.persisted?
    resource.ancestors.reorder(:depth)
  elsif resource.new_record? && resource.parent
    resource.parent.ancestors.reorder(:depth) + [resource.parent]
  else
    []
  end
end

#content_type_dialogObject



16
17
18
19
20
# File 'app/controllers/releaf/content/nodes_controller.rb', line 16

def content_type_dialog
  @content_types = resource_class.valid_node_content_classes(params[:parent_id]).sort do |a, b|
    I18n.t(a.name.underscore, scope: 'admin.content_types') <=> I18n.t(b.name.underscore, scope: 'admin.content_types')
  end
end

#copyObject



30
31
32
33
34
# File 'app/controllers/releaf/content/nodes_controller.rb', line 30

def copy
  copy_move_common do |resource|
    resource.copy params[:new_parent_id]
  end
end

#copy_dialogObject



22
23
24
# File 'app/controllers/releaf/content/nodes_controller.rb', line 22

def copy_dialog
  copy_move_dialog_common
end

#featuresObject



4
5
6
# File 'app/controllers/releaf/content/nodes_controller.rb', line 4

def features
  super - [:create_another, :search]
end

#generate_urlObject



8
9
10
11
12
13
14
# File 'app/controllers/releaf/content/nodes_controller.rb', line 8

def generate_url
  tmp_resource = prepare_resource
  tmp_resource.name = params[:name]
  tmp_resource.reasign_slug

  render plain: tmp_resource.slug
end

#moveObject



36
37
38
39
40
# File 'app/controllers/releaf/content/nodes_controller.rb', line 36

def move
  copy_move_common do |resource|
    resource.move params[:new_parent_id]
  end
end

#move_dialogObject



26
27
28
# File 'app/controllers/releaf/content/nodes_controller.rb', line 26

def move_dialog
  copy_move_dialog_common
end