From 97aecb984afa6a7d8d1424f544b8e32d8c87603d Mon Sep 17 00:00:00 2001 From: hukl Date: Sun, 9 Aug 2009 14:45:12 +0200 Subject: added sorting (via drag and drop) and deleting of menu items. Its not perfect though and needs more styling. I'm unsure about the proper route for the sort action. Will investigate. --- app/controllers/menu_items_controller.rb | 16 ++++++++++++++-- app/models/menu_item.rb | 1 + app/views/layouts/admin.html.erb | 1 + app/views/menu_items/index.html.erb | 12 ++++++++++-- 4 files changed, 26 insertions(+), 4 deletions(-) (limited to 'app') diff --git a/app/controllers/menu_items_controller.rb b/app/controllers/menu_items_controller.rb index 7b71693..dac78d9 100644 --- a/app/controllers/menu_items_controller.rb +++ b/app/controllers/menu_items_controller.rb @@ -3,7 +3,7 @@ class MenuItemsController < ApplicationController layout 'admin' def index - @menu_items = MenuItem.all + @menu_items = MenuItem.all(:order => "position ASC") end def show @@ -35,7 +35,19 @@ class MenuItemsController < ApplicationController end end - def delete + def destroy + menu_item = MenuItem.find( params[:id] ) + menu_item.destroy + redirect_to menu_items_path + end + + def sort + params[:menu_items].each_with_index do |item_id, index| + menu_item = MenuItem.find(item_id) + menu_item.update_attributes(:position => index + 1) + end + + render :nothing => true end end diff --git a/app/models/menu_item.rb b/app/models/menu_item.rb index 666fdf4..e86be0e 100644 --- a/app/models/menu_item.rb +++ b/app/models/menu_item.rb @@ -2,4 +2,5 @@ class MenuItem < ActiveRecord::Base translates :title + acts_as_list end diff --git a/app/views/layouts/admin.html.erb b/app/views/layouts/admin.html.erb index aaef927..2d88070 100644 --- a/app/views/layouts/admin.html.erb +++ b/app/views/layouts/admin.html.erb @@ -8,6 +8,7 @@ <%= "#{params[:controller]} | #{params[:action]}" %> <%= stylesheet_link_tag 'admin' %> <%= javascript_include_tag 'jquery-1.3.2.min' %> + <%= javascript_include_tag 'jquery-ui-1.7.2.custom.min' %> <%= javascript_include_tag 'tiny_mce/tiny_mce.js' %> <%= javascript_tag "var AUTH_TOKEN = #{form_authenticity_token.inspect};" if protect_against_forgery? %> <%= javascript_include_tag 'admin_search.js' %> diff --git a/app/views/menu_items/index.html.erb b/app/views/menu_items/index.html.erb index 00a9b05..f4316bf 100644 --- a/app/views/menu_items/index.html.erb +++ b/app/views/menu_items/index.html.erb @@ -5,11 +5,19 @@

Menu Items

- +
<% @menu_items.each do |menu_item| %> - + + <% end %> \ No newline at end of file -- cgit v1.3