class Activa::PagesController < Activa::ApplicationController respond_to :html before_filter :authenticate_activa_user, :except => %w(show index) before_filter :find_page_by_uri, :only => :show before_filter :find_page, :only => %w(edit update destroy) layout 'admin', :except => %w(index show) def index @pages = Activa::Page.roots end def show end def new @page = Activa::Page.new @page.parent_id = params[:parent_id].to_i respond_with(@page) end def edit end def create @page = Activa::Page.new(params[:page]) # Publish page immediately if params[:commit].present? if @page.publish flash.notice = I18n.t 'controllers.pages.create.published_notice' smart_redirect_to(@page) and return end # Save page as a draft and continue editing elsif params[:save_as_draft].present? if @page.save_as_draft flash.notice = I18n.t 'controllers.pages.create.draft_notice' redirect_to(activa.edit_page_path(@page)) and return end end respond_with(@page) end def update if params[:commit].present? if @page.update_attributes(params[:page])#@page.publish#(params[:page]) flash.notice = I18n.t 'controllers.pages.create.published_notice' smart_redirect_to(@page) and return end elsif params[:save_as_draft].present? if @page.update_as_draft(params[:page]) redirect_to(activa.edit_page_path(@page)) and return end end respond_with(@page) end def destroy if @page.destroy flash.notice = I18n.t 'controllers.pages.destroy.notice' redirect_to(activa.pages_path) and return end respond_with(@page) and return end def slug render :json => { :slug => params[:title].to_s.to_url } end def position render :json => Activa::Page.move( params[:first_node_id], params[:second_node_id], params[:nesting] ) end private def smart_redirect_to(page) redirect_to(page.uri) end def find_page_by_uri @page = Activa::Page.retrieve(params[:id]) || not_found! end def find_page @page = Activa::Page.find(params[:id]) end end