Class: Admin::PagesController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- Admin::PagesController
- Defined in:
- app/controllers/admin/pages_controller.rb
Instance Method Summary collapse
-
#create ⇒ Object
POST /pages POST /pages.xml.
-
#destroy ⇒ Object
DELETE /pages/1 DELETE /pages/1.xml.
- #duplicate ⇒ Object
-
#edit ⇒ Object
GET /pages/1/edit.
- #index ⇒ Object
-
#new ⇒ Object
GET /pages/new GET /pages/new.xml.
- #parse_content ⇒ Object
-
#show ⇒ Object
GET /pages/1 GET /pages/1.xml.
- #sort ⇒ Object
-
#update ⇒ Object
PUT /pages/1 PUT /pages/1.xml.
Instance Method Details
#create ⇒ Object
POST /pages POST /pages.xml
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'app/controllers/admin/pages_controller.rb', line 49 def create @parent = Page.find_by_permalink(params[:page_id]) @page = Page.new(params[:page]) @page. = send(PageEngine.) if PageEngine. respond_to do |format| if @page.save @page.move_to_child_of @parent unless @parent.nil? return_path = params.has_key?('continue') ? edit_admin_page_path(@page) : admin_pages_path format.html { redirect_to(return_path, :notice => 'Page was successfully created.') } format.xml { render :xml => @page, :status => :created, :location => @page } else @roles = PageEngine.class_exists?('Role') ? Role.all : [] format.html { render :action => "new" } format.xml { render :xml => @page.errors, :status => :unprocessable_entity } end end end |
#destroy ⇒ Object
DELETE /pages/1 DELETE /pages/1.xml
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'app/controllers/admin/pages_controller.rb', line 99 def destroy @page = Page.find_by_permalink(params[:id]) @page.move_children_to_parent @page.destroy respond_to do |format| format.html do redirect_to(admin_pages_path) end format.xml { head :ok } format.js do @pages = Page.order(:lft).all.group_by(&:parent_id) end end end |
#duplicate ⇒ Object
130 131 132 133 134 135 136 137 138 139 |
# File 'app/controllers/admin/pages_controller.rb', line 130 def duplicate @original_page = Page.find_by_permalink params[:id], :include => [:page_parts] @page = @original_page.duplicate @pages = {} respond_to do |format| format.html { redirect_to admin_pages_path, :notice => 'Page was successfully duplicated' } format.js end end |
#edit ⇒ Object
GET /pages/1/edit
39 40 41 42 43 44 45 |
# File 'app/controllers/admin/pages_controller.rb', line 39 def edit @page = Page.includes([:parent, :page_parts]) @page = @page.includes([:required_roles, :excluded_roles]) if PageEngine.uses_roles? @page = @page.find_by_permalink(params[:id]) @parent = @page.parent @roles = PageEngine.uses_roles? ? PageEngine.role_class.classify.constantize.all : [] end |
#index ⇒ Object
4 5 6 7 8 9 10 11 |
# File 'app/controllers/admin/pages_controller.rb', line 4 def index @pages = Page.order(:lft).all.group_by(&:parent_id) respond_to do |format| format.html # index.html.erb format.xml { render :xml => @pages } end end |
#new ⇒ Object
GET /pages/new GET /pages/new.xml
26 27 28 29 30 31 32 33 34 35 36 |
# File 'app/controllers/admin/pages_controller.rb', line 26 def new @page = Page.new PageEngine.page_parts.collect { |page_part| @page.page_parts.build(:title => page_part) } @parent = Page.find_by_permalink(params[:page_id]) @roles = PageEngine.uses_roles? ? PageEngine.role_class.classify.constantize.all : [] respond_to do |format| format.html # new.html.erb format.xml { render :xml => @page } end end |
#parse_content ⇒ Object
141 142 143 144 145 146 147 148 149 150 |
# File 'app/controllers/admin/pages_controller.rb', line 141 def parse_content case params[:data_type] when 'textile' render :text => RedCloth.new(params[:data]).to_html when 'markdown' render :text => BlueCloth.new(params[:data]).to_html else render :nothing => true end end |
#show ⇒ Object
GET /pages/1 GET /pages/1.xml
15 16 17 18 19 20 21 22 |
# File 'app/controllers/admin/pages_controller.rb', line 15 def show @page = Page.find(params[:id]) respond_to do |format| format.html # show.html.erb format.xml { render :xml => @page } end end |
#sort ⇒ Object
116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'app/controllers/admin/pages_controller.rb', line 116 def sort params[:pages].values.each do |value| @page = Page.find_by_id(value[:item_id]) parent_id = value[:parent_id] == 'root' ? nil : value[:parent_id] @page.parent_id = parent_id @page.lft = value[:left].to_i - 1 @page.rgt = value[:right].to_i - 1 @page.save end render :nothing => true end |
#update ⇒ Object
PUT /pages/1 PUT /pages/1.xml
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'app/controllers/admin/pages_controller.rb', line 74 def update @page = Page.includes([:parent, :page_parts]).find(params[:the_page_id]) if PageEngine.class_exists?('Role') params[:page][:required_role_ids] ||= [] params[:page][:excluded_role_ids] ||= [] end respond_to do |format| if @page.update_attributes(params[:page]) return_path = params.has_key?('continue') ? edit_admin_page_path(@page) : admin_pages_path format.html { redirect_to(return_path, :notice => 'Page was successfully updated.') } format.xml { head :ok } else @parent = @page.parent @roles = PageEngine.class_exists?('Role') ? Role.all : [] format.html { render :action => "edit" } format.xml { render :xml => @page.errors, :status => :unprocessable_entity } end end end |