From 93169b1098262d22fc7126f45f266486df784f40 Mon Sep 17 00:00:00 2001 From: Wen-Tien Chang Date: Mon, 22 Feb 2010 16:10:13 +0800 Subject: [PATCH] Add Item list interface, but acts_as_list can not used --- app/controllers/admin/items_controller.rb | 12 ++++++++++++ app/views/admin/items/_component.html.erb | 7 +++---- app/views/admin/items/_link.html.erb | 5 ++--- app/views/admin/items/_page.html.erb | 7 +++---- app/views/admin/items/index.html.erb | 7 ++++++- config/locales/zh_tw.yml | 4 +++- config/routes.rb | 2 +- 7 files changed, 30 insertions(+), 14 deletions(-) diff --git a/app/controllers/admin/items_controller.rb b/app/controllers/admin/items_controller.rb index d2b60843..ad472502 100644 --- a/app/controllers/admin/items_controller.rb +++ b/app/controllers/admin/items_controller.rb @@ -9,6 +9,18 @@ class Admin::ItemsController < ApplicationController @items.unshift Item.find_by_name("root") if @parent_item.name == 'root' end + def up + @item = Item.find(params[:id]) + @item.move_higher + redirect_to admin_items_url( :parent_name => @item.parent_name ) + end + + def down + @item = Item.find(params[:id]) + @item.move_lower + redirect_to admin_items_url( :parent_name => @item.parent_name ) + end + protected def find_snippets diff --git a/app/views/admin/items/_component.html.erb b/app/views/admin/items/_component.html.erb index 1ec404bd..8542e47f 100644 --- a/app/views/admin/items/_component.html.erb +++ b/app/views/admin/items/_component.html.erb @@ -1,5 +1,5 @@ - - <%= item.class %> + + <%= item.class %> <%= link_to item.name, admin_items_path(:parent_name => item.name) %> <%=h item.title %> <%= item.position %> @@ -8,5 +8,4 @@ <%= link_to t(:show), item.url %> | <%= link_to t(:edit), edit_admin_component_path(item) %> | <%= link_to t(:delete), admin_component_path(item), :confirm => 'Are you sure?', :method => :delete %> - - \ No newline at end of file + \ No newline at end of file diff --git a/app/views/admin/items/_link.html.erb b/app/views/admin/items/_link.html.erb index db692c70..4f2b44b8 100644 --- a/app/views/admin/items/_link.html.erb +++ b/app/views/admin/items/_link.html.erb @@ -1,4 +1,4 @@ - + <%= item.class %> <%= link_to item.name, admin_items_path(:parent_name => item.name) %> <%=h item.title %> @@ -8,5 +8,4 @@ <%= link_to t(:show), item.url %> | <%= link_to t(:edit), edit_admin_link_path(item) %> | <%= link_to t(:delete), admin_link_path(item), :confirm => 'Are you sure?', :method => :delete %> - - \ No newline at end of file + \ No newline at end of file diff --git a/app/views/admin/items/_page.html.erb b/app/views/admin/items/_page.html.erb index bf217b97..56dc5cfc 100644 --- a/app/views/admin/items/_page.html.erb +++ b/app/views/admin/items/_page.html.erb @@ -1,5 +1,5 @@ - - <%= item.class %> + + <%= item.class %> <%= link_to item.name, admin_items_path(:parent_name => item.name) %> <%=h item.title %> <%= item.position %> @@ -8,5 +8,4 @@ <%= link_to t(:show), item.url %> | <%= link_to t(:edit), edit_admin_page_path(item) %> | <%= link_to t(:delete), admin_page_path(item), :confirm => 'Are you sure?', :method => :delete %> - - \ No newline at end of file + \ No newline at end of file diff --git a/app/views/admin/items/index.html.erb b/app/views/admin/items/index.html.erb index 3db021bc..8ad0de01 100644 --- a/app/views/admin/items/index.html.erb +++ b/app/views/admin/items/index.html.erb @@ -17,10 +17,15 @@ Position Published? Action + <% @items.each do |item| %> - <%= render :partial => item.class.to_s.downcase, :locals => { :item => item } %> + + <%= render :partial => item.class.to_s.downcase, :locals => { :item => item } %> + + <% end %> diff --git a/config/locales/zh_tw.yml b/config/locales/zh_tw.yml index a86547e3..18ebd351 100644 --- a/config/locales/zh_tw.yml +++ b/config/locales/zh_tw.yml @@ -15,4 +15,6 @@ zh_tw: new_layout: 新增樣板 announcement: 公告管理 asset: 資產管理 - new_asset: 新增資產 \ No newline at end of file + new_asset: 新增資產 + move_up: 往上移 + move_down: 往下移 \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index a9a7faaa..d93c86be 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -3,7 +3,7 @@ ActionController::Routing::Routes.draw do |map| map.resources :announcements map.namespace :admin do |admin| - admin.resources :items + admin.resources :items, :member => { :up => :put, :down => :put } admin.resources :pages admin.resources :links admin.resources :components