diff --git a/app/controllers/admin/pages_controller.rb b/app/controllers/admin/pages_controller.rb index 811ed6d4..c5ab9907 100644 --- a/app/controllers/admin/pages_controller.rb +++ b/app/controllers/admin/pages_controller.rb @@ -37,7 +37,7 @@ class Admin::PagesController < ApplicationController flash.now[:notice] = t('admin.create_success_page') respond_to do |format| format.html { - redirect_to admin_item_url(@item) + redirect_to admin_page_url(@item) } format.js {} end @@ -64,9 +64,21 @@ class Admin::PagesController < ApplicationController def destroy @item = Page.find(params[:id]) @item.destroy + @item.destroy_page_parts @item.destroy_i18n_variable - - redirect_to admin_items_url( :parent_id => @item.parent_id ) + respond_to do |format| + 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 diff --git a/app/helpers/admin/item_helper.rb b/app/helpers/admin/item_helper.rb index 816e6a58..c0472f17 100644 --- a/app/helpers/admin/item_helper.rb +++ b/app/helpers/admin/item_helper.rb @@ -13,7 +13,7 @@ module Admin::ItemHelper 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_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 << "" end diff --git a/app/models/item.rb b/app/models/item.rb index c9218454..dbb86c74 100644 --- a/app/models/item.rb +++ b/app/models/item.rb @@ -37,11 +37,6 @@ class Item nodes.reverse end - # Destroy the i18n_variable - def destroy_i18n_variable - self.i18n_variable.destroy rescue nil - end - # Update or create the i18n_variable record def i18n_variable=(attr) if self.i18n_variable_id diff --git a/app/models/page.rb b/app/models/page.rb index fe85ba9d..3c7ffb67 100644 --- a/app/models/page.rb +++ b/app/models/page.rb @@ -18,6 +18,14 @@ class Page < Item 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 Layout.find(layout_id) end diff --git a/app/models/page_part.rb b/app/models/page_part.rb index 39ce1b80..09f0152d 100644 --- a/app/models/page_part.rb +++ b/app/models/page_part.rb @@ -26,6 +26,10 @@ class PagePart end end + def destroy_i18n_variable + self.i18n_variable.destroy rescue nil + end + # Build the content from the i18n_variable def build_content(locales) res = '' diff --git a/app/views/admin/pages/delete.html.erb b/app/views/admin/pages/delete.html.erb new file mode 100644 index 00000000..81a4d2b5 --- /dev/null +++ b/app/views/admin/pages/delete.html.erb @@ -0,0 +1,7 @@ +<% form_for :page, :url => admin_page_path(@page), :html => { :method => :delete } do |f| %> +

<%= t('sure?') %>

+

+ <%= submit_tag t(:delete) %> + <%= link_back %> +

+<% end %> \ No newline at end of file diff --git a/app/views/admin/pages/delete.js.erb b/app/views/admin/pages/delete.js.erb new file mode 100644 index 00000000..d8771a3c --- /dev/null +++ b/app/views/admin/pages/delete.js.erb @@ -0,0 +1 @@ +$('#sidebar').html("<%= escape_javascript(render(:partial => 'admin/items/site_map_left_bar')) %>"); \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 22865695..67e45266 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -48,7 +48,11 @@ PrototypeR4::Application.routes.draw do get 'delete' end end - resources :pages + resources :pages do + member do + get 'delete' + end + end resources :page_parts resources :homes resources :snippets