summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorhukl <contact@smyck.org>2009-08-09 14:45:12 +0200
committerhukl <contact@smyck.org>2009-08-09 14:45:12 +0200
commit97aecb984afa6a7d8d1424f544b8e32d8c87603d (patch)
tree8939b12d327875241179c07ac975871cabdb582c /app
parent72593784d6d580ea8cc6987a83cf7b18167aba80 (diff)
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.
Diffstat (limited to 'app')
-rw-r--r--app/controllers/menu_items_controller.rb16
-rw-r--r--app/models/menu_item.rb1
-rw-r--r--app/views/layouts/admin.html.erb1
-rw-r--r--app/views/menu_items/index.html.erb12
4 files changed, 26 insertions, 4 deletions
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
3 layout 'admin' 3 layout 'admin'
4 4
5 def index 5 def index
6 @menu_items = MenuItem.all 6 @menu_items = MenuItem.all(:order => "position ASC")
7 end 7 end
8 8
9 def show 9 def show
@@ -35,7 +35,19 @@ class MenuItemsController < ApplicationController
35 end 35 end
36 end 36 end
37 37
38 def delete 38 def destroy
39 menu_item = MenuItem.find( params[:id] )
40 menu_item.destroy
41 redirect_to menu_items_path
42 end
43
44 def sort
45 params[:menu_items].each_with_index do |item_id, index|
46 menu_item = MenuItem.find(item_id)
47 menu_item.update_attributes(:position => index + 1)
48 end
49
50 render :nothing => true
39 end 51 end
40 52
41end 53end
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
2 2
3 translates :title 3 translates :title
4 4
5 acts_as_list
5end 6end
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 @@
8 <title><%= "#{params[:controller]} | #{params[:action]}" %></title> 8 <title><%= "#{params[:controller]} | #{params[:action]}" %></title>
9 <%= stylesheet_link_tag 'admin' %> 9 <%= stylesheet_link_tag 'admin' %>
10 <%= javascript_include_tag 'jquery-1.3.2.min' %> 10 <%= javascript_include_tag 'jquery-1.3.2.min' %>
11 <%= javascript_include_tag 'jquery-ui-1.7.2.custom.min' %>
11 <%= javascript_include_tag 'tiny_mce/tiny_mce.js' %> 12 <%= javascript_include_tag 'tiny_mce/tiny_mce.js' %>
12 <%= javascript_tag "var AUTH_TOKEN = #{form_authenticity_token.inspect};" if protect_against_forgery? %> 13 <%= javascript_tag "var AUTH_TOKEN = #{form_authenticity_token.inspect};" if protect_against_forgery? %>
13 <%= javascript_include_tag 'admin_search.js' %> 14 <%= 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 @@
5 5
6<h1>Menu Items</h1> 6<h1>Menu Items</h1>
7 7
8<table> 8<table id="menu_item_list">
9 <% @menu_items.each do |menu_item| %> 9 <% @menu_items.each do |menu_item| %>
10 <tr> 10 <tr id="menu_items-<%= menu_item.id %>">
11 <td><%= menu_item.title %></td> 11 <td><%= menu_item.title %></td>
12 <td><%= link_to "Edit", edit_menu_item_path(menu_item) %></td> 12 <td><%= link_to "Edit", edit_menu_item_path(menu_item) %></td>
13 <td>
14 <%= link_to(
15 "Delete",
16 menu_item_path(menu_item),
17 :method => :delete,
18 :confirm => "Are you sure?"
19 ) %>
20 </td>
13 </tr> 21 </tr>
14 <% end %> 22 <% end %>
15</table> \ No newline at end of file 23</table> \ No newline at end of file