Module: Acts::ArchiveController::InstanceMethods

Defined in:
lib/acts_as_archive_controller.rb

Instance Method Summary (collapse)

Instance Method Details

- (Object) index



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/acts_as_archive_controller.rb', line 20

def index
  respond_to do |format|
    node_id     = params[:super_node] || params[:node]
    record_node = Node.find(node_id)          
    instance_variable_set("@#{self.class.singular_name}_node", record_node)

    active_node = params[:active_node_id] ? Node.find(params[:active_node_id]) : nil
    archive_includes_active_node = active_node && record_node.children.include?(active_node)

    format.json do
      # TODO: Refactor line below. This works as well?
      #if !self.class.render_weeks && @year && @month
      if !self.class.render_weeks == true && @year && @month
        record_nodes = record_node.content.find_all_items_for_month(@year, @month).map { |c| c.node }
        render :json => record_nodes.map { |node| node.to_tree_node_for(current_user) }.to_json
      elsif self.class.render_weeks == true && @year && (@week = params[:week])
        record_nodes = record_node.content.find_all_items_for_week(@year, @week.to_i).map { |c| c.node }
        render :json => record_nodes.map { |node| node.to_tree_node_for(current_user) }.to_json
      else
        role        = current_user.role_on(record_node)
        common_hash = { :treeLoaderName => Node.content_type_configuration(self.class.content_class_name)[:tree_loader_name], :userRole => role ? role.name : "" }

        if @year
          self.class.render_weeks == true ? render_weeks(record_node, node_id, common_hash, active_node, archive_includes_active_node) : render_months(record_node, node_id, common_hash, active_node, archive_includes_active_node)
        else
          render_years(record_node, node_id, common_hash, active_node, archive_includes_active_node)
        end
      end
    end
  end
end

- (Object) show



13
14
15
16
17
18
# File 'lib/acts_as_archive_controller.rb', line 13

def show
  respond_to do |format|
    format.html { render :partial => 'show', :layout => 'admin/admin_show' }
    format.xml  { render :xml => record }
  end
end