1 class Admin::PageController < Admin::AbstractModelController
3 before_filter :initialize_meta_rows_and_buttons, :only => [:new, :edit]
8 @cache = ResponseCache.instance
12 @homepage = Page.find_by_parent_id(nil)
16 @page = request.get? ? Page.new_with_defaults(config) : Page.new
17 @page.slug = params[:slug]
18 @page.breadcrumb = params[:breadcrumb]
19 @page.parent = Page.find_by_id(params[:parent_id])
20 render :action => :edit if handle_new_or_edit_post
24 @page = Page.find(params[:id])
25 @old_page_url = @page.url
26 handle_new_or_edit_post
30 @page = Page.find(params[:id])
32 announce_pages_removed(@page.children.count + 1)
34 redirect_to page_index_url
41 announce_cache_cleared
42 redirect_to page_index_url
44 render :text => 'Do not access this URL directly.'
49 part = PagePart.new(params[:part])
50 @index = params[:index].to_i if params[:index]
51 render(:partial => 'part', :object => part, :layout => false)
55 @parent = Page.find(params[:id])
56 @level = params[:level].to_i
57 response.headers['Content-Type'] = 'text/html;charset=utf-8'
58 render(:layout => false)
62 @class_name = params[:class_name]
63 @display_name = @class_name.constantize.display_name
67 @filter_name = params[:filter_name]
68 @display_name = (@filter_name + "Filter").constantize.filter_name rescue "<none>"
73 def announce_saved(message = nil)
74 flash[:notice] = message || "Your page has been saved below."
77 def announce_pages_removed(count)
78 flash[:notice] = if count > 1
79 "The pages were successfully removed from the site."
81 "The page was successfully removed from the site."
85 def announce_cache_cleared
86 flash[:notice] = "The page cache was successfully cleared."
89 def initialize_meta_rows_and_buttons
90 @buttons_partials ||= []
92 @meta << {:field => "slug", :type => "text_field", :args => [{:class => 'textbox', :maxlength => 100}]}
93 @meta << {:field => "breadcrumb", :type => "text_field", :args => [{:class => 'textbox', :maxlength => 160}]}
99 (params[:part]||{}).each {|k,v| parts_to_update[v[:name]] = v }
102 @page.parts.each do |part|
103 if(attrs = parts_to_update.delete(part.name))
104 part.attributes = part.attributes.merge(attrs)
106 parts_to_remove << part
109 parts_to_update.values.each do |attrs|
110 @page.parts.build(attrs)
112 if result = @page.save
113 new_parts = @page.parts - parts_to_remove
114 new_parts.each { |part| part.save }
115 @page.parts = new_parts
120 def clear_model_cache
121 @cache.expire_response(@old_page_url || @page.url)