Uniformized: @page and @ link in @item

Change parser for page edition.
This commit is contained in:
chris2tof committed 2011-05-25 14:50:56 +08:00
1 parent 3d97c5bfda
commit d971a8ecbe
20 files changed
+246 -73

No files matched your search

@@ -13,7 +13,6 @@ class Admin::ItemsController < ApplicationController
@item = Item.find(params[:item_id])
else
@item = Item.first(:conditions => {:parent_id => nil})
@page = @item
end
end
+17 -17
View File
@@ -7,60 +7,60 @@ class Admin::LinksController < ApplicationController
before_filter :is_admin?
def show
@link ||= Link.find(params[:id])
@item ||= Link.find(params[:id])
end
def new
@link = Link.new
@link.is_published = true
@link.parent_id = Page.find(params[:parent_id]).id rescue nil
@item = Link.new
@item.is_published = true
@item.parent_id = Page.find(params[:parent_id]).id rescue nil
end
def edit
@link = Link.find(params[:id])
@i18n_variable = @link.i18n_variable
@item = Link.find(params[:id])
@i18n_variable = @item.i18n_variable
end
def create
@link = Link.new(params[:link])
@item = Link.new(params[:link])
if @link.save
if @item.save
flash.now[:notice] = t('admin.create_success_link')
respond_to do |format|
format.html {
redirect_to admin_link_url(@link)
redirect_to admin_link_url(@item)
}
format.js {}
end
else
flash.now[:error] = t('admin.create_error_link')
@i18n_variable = @link.i18n_variable
@i18n_variable = @item.i18n_variable
render :action => "new"
end
end
def update
@link = Link.find(params[:id])
@item = Link.find(params[:id])
if @link.update_attributes(params[:link])
if @item.update_attributes(params[:link])
flash.now[:notice] = t('admin.update_success_link')
respond_to do |format|
format.html {
redirect_to admin_link_url(@link)
redirect_to admin_link_url(@item)
}
format.js {}
end
else
flash.now[:error] = t('admin.update_error_link')
@i18n_variable = @link.i18n_variable
@i18n_variable = @item.i18n_variable
render :action => "edit"
end
end
def destroy
@link = Link.find(params[:id])
@link.destroy
@link.destroy_i18n_variable
@item = Link.find(params[:id])
@item.destroy
@item.destroy_i18n_variable
respond_to do |format|
format.html {
redirect_to admin_items_url
@@ -0,0 +1,54 @@
class Admin::PagePartsController < ApplicationController
layout "content"
before_filter :authenticate_user!
before_filter :is_admin?
before_filter :set_current_item
def show
@part = PagePart.find(params[:id])
respond_to do |format|
format.html {
render 'admin/items/index'
}
format.js {}
end
end
def new
end
def edit
@part = PagePart.find(params[:id])
#@part.content = parse_content(@part.content, {:locale => 'show'})
# @part = @part.i18n_variable
end
def create
end
def update
@part = PagePart.find(params[:id])
parse_content(@part.content, {:locale => 'destroy'})
if @part.update_attributes(params[:page])
@part.content = parse_content(@part.content, {:locale => 'create'})
@part.save!
flash[:notice] = t('admin.update_success_page')
redirect_to admin_items_url( :parent_id => @part.page_id )
else
render :action => "edit"
end
end
def destroy
@item = Page.find(params[:id])
@item.destroy
@item.destroy_i18n_variable
redirect_to admin_items_url( :parent_id => @item.parent_id )
end
end
+21 -22
View File
@@ -8,10 +8,9 @@ class Admin::PagesController < ApplicationController
before_filter :set_current_item
def show
@page = Page.find(params[:id])
@item = Page.find(params[:id])
respond_to do |format|
format.html {
@item = @page
render 'admin/items/index'
}
format.js {}
@@ -19,47 +18,47 @@ class Admin::PagesController < ApplicationController
end
def new
@page = Page.new
@page.is_published = true
@page.parent_id = @parent_item.id rescue nil
@item = Page.new
@item.is_published = true
@item.parent_id = @parent_item.id rescue nil
end
def edit
@page = Page.find(params[:id])
@page.content = parse_content(@page.content, {:locale => 'show'})
@i18n_variable = @page.i18n_variable
@item = Page.find(params[:id])
@item.content = parse_content(@item.content, {:locale => 'show'})
@i18n_variable = @item.i18n_variable
end
def create
@page = Page.new(params[:page])
@page.content = parse_content(@page.content, {:locale => 'create'})
if @page.save
@item = Page.new(params[:page])
@item.content = parse_content(@item.content, {:locale => 'create'})
if @item.save
flash[:notice] = t('admin.create_success_page')
redirect_to admin_items_url( :parent_id => @page.parent_id )
redirect_to admin_items_url( :parent_id => @item.parent_id )
else
render :action => "new"
end
end
def update
@page = Page.find(params[:id])
parse_content(@page.content, {:locale => 'destroy'})
if @page.update_attributes(params[:page])
@page.content = parse_content(@page.content, {:locale => 'create'})
@page.save!
@item = Page.find(params[:id])
parse_content(@item.content, {:locale => 'destroy'})
if @item.update_attributes(params[:page])
@item.content = parse_content(@item.content, {:locale => 'create'})
@item.save!
flash[:notice] = t('admin.update_success_page')
redirect_to admin_items_url( :parent_id => @page.parent_id )
redirect_to admin_items_url( :parent_id => @item.parent_id )
else
render :action => "edit"
end
end
def destroy
@page = Page.find(params[:id])
@page.destroy
@page.destroy_i18n_variable
@item = Page.find(params[:id])
@item.destroy
@item.destroy_i18n_variable
redirect_to admin_items_url( :parent_id => @page.parent_id )
redirect_to admin_items_url( :parent_id => @item.parent_id )
end
end
+3 -3
View File
@@ -18,8 +18,8 @@ class ApplicationController < ActionController::Base
# Render the page
def render_page
if @page
render :text => parse_page(@page)
if @item
render :text => parse_page(@item)
else
render :text => '404 Not Found'
end
@@ -53,7 +53,7 @@ class ApplicationController < ActionController::Base
end
def set_current_item
session[:current_page] = params[:id] || @page.id || @link.id || @item.id rescue nil
session[:current_page] = params[:id] || @item.id rescue nil
end
end
+3 -3
View File
@@ -1,8 +1,8 @@
class PagesController < ApplicationController
def index
@page = Page.find_by_name('home')
if @page
@item = Page.find_by_name('home')
if @item
render_page
else
render :text => 'You need a home page'
@@ -14,7 +14,7 @@ class PagesController < ApplicationController
item = Item.first(:conditions => {:full_name => params[:page_name]})
case item._type
when 'Page'
@page = item
@item = item
render_page
when 'Link'
redirect_to "http://#{item[:url]}"