Add Item, Page, Component, Link inheritanced models

This commit is contained in:
Wen-Tien Chang committed 2010-01-14 18:30:53 +08:00
1 parent cd21cadfe7
commit e1440a79d8
38 files changed
+417 -175

No files matched your search

@@ -0,0 +1,53 @@
class Admin::ComponentsController < ApplicationController
layout "admin"
before_filter :find_parent_item
def show
#TODO
end
def new
@component = Component.new
@component.is_published = true
@component.parent_item_name = @parent_item.name
@component.engine_name = 'Announcement' # only support Announcement now
end
def edit
@component = Component.find(params[:id])
end
def create
@component = Component.new(params[:component])
if @component.save
flash[:notice] = 'Component was successfully created.'
redirect_to admin_items_url( :parent_item_name => @component.parent_item_name )
else
render :action => "new"
end
end
def update
@component = Component.find(params[:id])
if @component.update_attributes(params[:component])
flash[:notice] = 'Component was successfully updated.'
redirect_to admin_items_url( :parent_item_name => @component.parent_item_name )
else
render :action => "edit"
end
end
def destroy
@component = Component.find(params[:id])
@component.destroy
#TODO: destroy engine data
redirect_to admin_items_url( :parent_item_name => @component.parent_item_name )
end
end
+17
View File
@@ -0,0 +1,17 @@
class Admin::ItemsController < ApplicationController
layout "admin"
before_filter :find_parent_item
before_filter :find_snippets, :only => :index
def index
@items = Item.all( :conditions => { :parent_item_name => @parent_item.name } )
end
protected
def find_snippets
@snippets = Snippet.all( :conditions => { :parent_item_name => @parent_item.name } )
end
end
+49
View File
@@ -0,0 +1,49 @@
class Admin::LinksController < ApplicationController
layout "admin"
before_filter :find_parent_item
def show
#TODO
end
def new
@link = Link.new
@link.is_published = true
@link.parent_item_name = @parent_item.name
end
def edit
@link = Link.find(params[:id])
end
def create
@link = Link.new(params[:link])
if @link.save
flash[:notice] = 'Link was successfully created.'
redirect_to admin_items_url( :parent_item_name => @link.parent_item_name )
else
render :action => "new"
end
end
def update
@link = Link.find(params[:id])
if @link.update_attributes(params[:link])
flash[:notice] = 'Link was successfully updated.'
redirect_to admin_items_url( :parent_item_name => @link.parent_item_name )
else
render :action => "edit"
end
end
def destroy
@link = Link.find(params[:id])
@link.destroy
redirect_to admin_items_url( :parent_item_name => @link.parent_item_name )
end
end
+6 -11
View File
@@ -1,21 +1,16 @@
class Admin::PagesController < ApplicationController
layout "admin"
before_filter :find_parent_item
def index
@pages = Page.all( :conditions => { :parent_page_name => params[:parent] || "root" } )
end
def show
@page = Page.find(params[:id])
redirect_to "/#{@page.name}"
#TODO
end
def new
@page = Page.new
@page.is_published = true
@page.parent_page_name = params[:parent_page_name]
@page.parent_item_name = @parent_item.name
end
def edit
@@ -27,7 +22,7 @@ class Admin::PagesController < ApplicationController
if @page.save
flash[:notice] = 'Page was successfully created.'
redirect_to admin_pages_url( :parent_page_name => @page.parent_page_name )
redirect_to admin_items_url( :parent_item_name => @page.parent_item_name )
else
render :action => "new"
end
@@ -38,7 +33,7 @@ class Admin::PagesController < ApplicationController
if @page.update_attributes(params[:page])
flash[:notice] = 'Page was successfully updated.'
redirect_to admin_pages_url
redirect_to admin_items_url( :parent_item_name => @page.parent_item_name )
else
render :action => "edit"
end
@@ -48,7 +43,7 @@ class Admin::PagesController < ApplicationController
@page = Page.find(params[:id])
@page.destroy
redirect_to admin_pages_url
redirect_to admin_items_url( :parent_item_name => @page.parent_item_name )
end
end
+6 -27
View File
@@ -1,36 +1,15 @@
class Admin::SnippetsController < ApplicationController
layout "admin"
before_filter :find_parent_item
def index
@snippets = Snippet.all
end
def show
@snippet = Snippet.find(params[:id])
redirect_to "/#{@snippet.name}"
#TODO
end
def new
@snippet = Snippet.new
if params[:menu]
@snippet.name = "#{params[:menu]}_nav"
lis = Page.find(:all, :conditions => { :parent_page_id => params[:menu], :is_published => true }, :order => "position" ).map do |page|
if page.external_link.blank?
"<li><a href='/#{page.name}'>#{page.name}</a></li>\n"
else
"<li><a href='#{page.external_link}'>#{page.name}</a></li>\n"
end
end
VALID_LOCALES.each do |locale|
@snippet.send( :write_attribute, "content_#{locale}", "<ul>\n#{lis}</ul>" )
end
end
@snippet.parent_item_name = @parent_item.name
end
def edit
@@ -42,7 +21,7 @@ class Admin::SnippetsController < ApplicationController
if @snippet.save
flash[:notice] = 'Snippet was successfully created.'
redirect_to admin_snippets_url
redirect_to admin_items_url( :parent_item_name => @snippet.parent_item_name )
else
render :action => "new"
end
@@ -53,7 +32,7 @@ class Admin::SnippetsController < ApplicationController
if @snippet.update_attributes(params[:snippet])
flash[:notice] = 'Snippet was successfully updated.'
redirect_to admin_snippets_url
redirect_to admin_items_url( :parent_item_name => @snippet.parent_item_name )
else
render :action => "edit"
end
@@ -63,7 +42,7 @@ class Admin::SnippetsController < ApplicationController
@snippet = Snippet.find(params[:id])
@snippet.destroy
redirect_to admin_snippets_url
redirect_to admin_items_url( :parent_item_name => @snippet.parent_item_name )
end
end