Delete page.

This commit is contained in:
chris2tof 2011-06-01 12:00:41 +08:00
parent ddc7c74436
commit 7b5ea870a0
8 changed files with 41 additions and 10 deletions

View File

@ -37,7 +37,7 @@ class Admin::PagesController < ApplicationController
flash.now[:notice] = t('admin.create_success_page') flash.now[:notice] = t('admin.create_success_page')
respond_to do |format| respond_to do |format|
format.html { format.html {
redirect_to admin_item_url(@item) redirect_to admin_page_url(@item)
} }
format.js {} format.js {}
end end
@ -64,9 +64,21 @@ class Admin::PagesController < ApplicationController
def destroy def destroy
@item = Page.find(params[:id]) @item = Page.find(params[:id])
@item.destroy @item.destroy
@item.destroy_page_parts
@item.destroy_i18n_variable @item.destroy_i18n_variable
respond_to do |format|
redirect_to admin_items_url( :parent_id => @item.parent_id ) format.html {
redirect_to admin_items_url( :parent_id => @item.parent_id )
}
format.js {}
end
end
def delete
respond_to do |format|
format.html {}
format.js { destroy }
end
end end
end end

View File

@ -13,7 +13,7 @@ module Admin::ItemHelper
ret << (link_to node.name, dest) ret << (link_to node.name, dest)
ret << ' | ' << (link_to t('admin.new_page'), new_admin_page_path(:parent_id => node.id)) if node._type.eql?('Page') ret << ' | ' << (link_to t('admin.new_page'), new_admin_page_path(:parent_id => node.id)) if node._type.eql?('Page')
ret << ' | ' << (link_to t('admin.new_link'), new_admin_link_path(:parent_id => node.id)) if node._type.eql?('Page') ret << ' | ' << (link_to t('admin.new_link'), new_admin_link_path(:parent_id => node.id)) if node._type.eql?('Page')
ret << ' | ' << (link_to t(:delete), delete_admin_link_path(node, :authenticity_token => form_authenticity_token), :confirm => t('sure?'), :class => 'delete') if node._type.eql?('Link') ret << ' | ' << (link_to t(:delete), eval("delete_admin_#{node._type.downcase}_path(node, :authenticity_token => form_authenticity_token)"), :confirm => t('sure?'), :class => 'delete')
ret << render_children(node) ret << render_children(node)
ret << "</li>" ret << "</li>"
end end

View File

@ -37,11 +37,6 @@ class Item
nodes.reverse nodes.reverse
end end
# Destroy the i18n_variable
def destroy_i18n_variable
self.i18n_variable.destroy rescue nil
end
# Update or create the i18n_variable record # Update or create the i18n_variable record
def i18n_variable=(attr) def i18n_variable=(attr)
if self.i18n_variable_id if self.i18n_variable_id

View File

@ -18,6 +18,14 @@ class Page < Item
end end
end end
# Destroy the page_parts
def destroy_page_parts
self.page_parts.each do |part|
part.destroy_i18n_variable
part.destroy
end
end
def get_layout def get_layout
Layout.find(layout_id) Layout.find(layout_id)
end end

View File

@ -26,6 +26,10 @@ class PagePart
end end
end end
def destroy_i18n_variable
self.i18n_variable.destroy rescue nil
end
# Build the content from the i18n_variable # Build the content from the i18n_variable
def build_content(locales) def build_content(locales)
res = '' res = ''

View File

@ -0,0 +1,7 @@
<% form_for :page, :url => admin_page_path(@page), :html => { :method => :delete } do |f| %>
<h2><%= t('sure?') %></h2>
<p>
<%= submit_tag t(:delete) %>
<%= link_back %>
</p>
<% end %>

View File

@ -0,0 +1 @@
$('#sidebar').html("<%= escape_javascript(render(:partial => 'admin/items/site_map_left_bar')) %>");

View File

@ -48,7 +48,11 @@ PrototypeR4::Application.routes.draw do
get 'delete' get 'delete'
end end
end end
resources :pages resources :pages do
member do
get 'delete'
end
end
resources :page_parts resources :page_parts
resources :homes resources :homes
resources :snippets resources :snippets