Class: Admin::LayoutsController

Inherits:
AdminController
  • Object
show all
Includes:
PagesHelper
Defined in:
app/controllers/admin/layouts_controller.rb

Overview

@File Name : admin/layouts_controller.rb

@Company Name              : Mindfire Solutions Private Limited
@Creator Name              : Vikram Kumar Mishra
@Date Created              : 2012-06-15
@Date Modified             :
@Last Modification Details :
@Purpose                   : To setup the communication between layout model and views related to layouts under namespace admin.

Instance Method Summary collapse

Methods included from PagesHelper

#arrange_page_part, #build_page_part, #build_page_part_page, #deleteable?, #get_fragments, #layout_name, #layout_parts

Instance Method Details

#find_and_use_layoutObject

purpose : To find layout id and redirect to new page path with layout id as param



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'app/controllers/admin/layouts_controller.rb', line 46

def find_and_use_layout

  # declare a local variable with default value
  query_string = "1"

  # initializing a local variable with default value false
  value = false

  # spliting the get params and assigning it to an array
  url_param = params[:layout].split(",")

  # looping through all possible layout parts
  layout_parts.each do |layout|

    if url_param.include?(layout)

      value = true

    else

      value = false

    end # end if

    # check and change string to match column name
    if layout == "left"

      layout = "lft"

    elsif layout == "right"

      layout = "rgt"

    end # end if

    query_string += " AND `" + layout +"` = " + value.to_s

  end # end loop

  # find layout id from query string
  layout_id = Layout.where(query_string).first.id

  # redirect to new page path with params layout id
  redirect_to new_admin_page_path(:layout_id => layout_id)

end

#indexObject

GET /layouts GET /layouts.json To find all layouts and display it to the user to choose one



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'app/controllers/admin/layouts_controller.rb', line 23

def index

  # find all layouts
  @layouts = Layout.all

  # find parent_id of page if child page is being created
  # if parent_id is not there i.e. child page is not being created,
  # use parent_id as 0
  @page_parent_id = (params[:parent_id]) ? params[:parent_id] : 0

  # send data in different format
  respond_to do |format|

    format.html{render :template => 'mcms_pages/admin/layouts/index'}# index.html.erb
    format.json { render json: @pages }

  end # end respond_to

end