app/controllers/spud/admin/pages_controller.rb in spud_cms-0.8.0 vs app/controllers/spud/admin/pages_controller.rb in spud_cms-0.8.1

- old
+ new

@@ -1,14 +1,14 @@ -class Spud::Admin::PagesController < Spud::Admin::ApplicationController +class Spud::Admin::PagesController < Spud::Admin::CmsController layout 'spud/admin/cms/detail' add_breadcrumb "Pages", :spud_admin_pages_path belongs_to_spud_app :pages before_filter :load_page,:only => [:edit,:update,:show,:destroy] cache_sweeper :page_sweeper,:only => [:update,:destroy] def index - @pages = SpudPage.where(:spud_page_id => nil).order(:page_order).includes(:spud_pages).paginate :page => params[:page] + @pages = SpudPage.site(session[:admin_site]).where(:spud_page_id => nil).order(:page_order).includes(:spud_pages).paginate :page => params[:page] respond_with @pages end def show @@ -37,29 +37,46 @@ add_breadcrumb "New", :new_spud_admin_page_path @templates = SpudTemplate.all @page = SpudPage.new - Spud::Cms.default_page_parts.each do |part| + parts = Spud::Cms.default_page_parts + if Spud::Core.multisite_mode_enabled && !session[:admin_site].blank? + site_config = Spud::Core.multisite_config.select{|c| c[:site_id] == session[:admin_site]} + if !site_config.blank? + cms_config = Spud::Cms.site_config_for_short_name(site_config[0][:short_name]) + parts = cms_config[:default_page_parts] if !cms_config.blank? && !cms_config[:default_page_parts].blank? + end + end + parts.each do |part| @page.spud_page_partials.new(:name => part.strip) end respond_with @page end def create @page = SpudPage.new(params[:spud_page]) + @page.site_id = session[:admin_site] flash[:notice] = "Page Saved successfully" if @page.save respond_with @page,:location => spud_admin_pages_url end def edit add_breadcrumb "#{@page.name}", :spud_admin_page_path add_breadcrumb "Edit", :edit_spud_admin_page_path @templates = SpudTemplate.all if @page.spud_page_partials.blank? - Spud::Cms.default_page_parts.each do |part| + parts = Spud::Cms.default_page_parts + if Spud::Core.multisite_mode_enabled && !session[:admin_site].blank? + site_config = Spud::Core.multisite_config.select{|c| c[:site_id] == session[:admin_site]} + if !site_config.blank? + cms_config = Spud::Cms.site_config_for_short_name(site_config[0][:short_name]) + parts = cms_config[:default_page_parts] if !cms_config.blank? && !cms_config[:default_page_parts].blank? + end + end + parts.each do |part| @page.spud_page_partials.new(:name => part.strip) end end if !@page.spud_template.blank? @page.spud_template.page_parts.split(",").each do |part| @@ -107,11 +124,19 @@ if !template.blank? && !template.page_parts.blank? template.page_parts.split(',').each do |page_part| new_page_partials << page.spud_page_partials.build(:name => page_part.strip) end else - Spud::Cms.default_page_parts.each do |part| + parts = Spud::Cms.default_page_parts + if Spud::Core.multisite_mode_enabled && !session[:admin_site].blank? + site_config = Spud::Core.multisite_config.select{|c| c[:site_id] == session[:admin_site]} + if !site_config.blank? + cms_config = Spud::Cms.site_config_for_short_name(site_config[0][:short_name]) + parts = cms_config[:default_page_parts] if !cms_config.blank? && !cms_config[:default_page_parts].blank? + end + end + parts.each do |part| new_page_partials << page.spud_page_partials.build(:name => part) end end new_page_partials.each do |partial| @@ -130,11 +155,11 @@ end end def clear Rails.cache.clear - SpudPage.published_pages.all.each do |record| + SpudPage.site(session[:admin_site]).published_pages.all.each do |record| if Spud::Cms.enable_full_page_caching if record.url_name == Spud::Cms.root_page_name expire_page root_path else expire_page page_path(:id => record.url_name) @@ -149,10 +174,10 @@ end end private def load_page - @page = SpudPage.where(:id => params[:id]).includes(:spud_page_partials).first + @page = SpudPage.site(session[:admin_site]).where(:id => params[:id]).includes(:spud_page_partials).first if @page.blank? flash[:error] = "Page not found!" redirect_to spud_admin_pages_url() and return false end return true