summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/controllers/menu_items_controller.rb15
-rw-r--r--app/views/menu_items/index.html.erb18
-rw-r--r--app/views/menu_items/new.html.erb34
-rw-r--r--public/javascripts/admin_search.js46
4 files changed, 59 insertions, 54 deletions
diff --git a/app/controllers/menu_items_controller.rb b/app/controllers/menu_items_controller.rb
index d6f0252..0ba56c3 100644
--- a/app/controllers/menu_items_controller.rb
+++ b/app/controllers/menu_items_controller.rb
@@ -10,20 +10,15 @@ class MenuItemsController < ApplicationController
10 end 10 end
11 11
12 def new 12 def new
13 @menu_item = MenuItem.new params[:menu_item]
13 end 14 end
14 15
15 def create 16 def create
16 respond_to do |format| 17 if MenuItem.create( params[:menu_item] )
17 format.html {} 18 redirect_to menu_items_path
18 19 else
19 format.js do 20 render :new
20 MenuItem.create params[:menu_item]
21 end
22
23
24 end 21 end
25
26
27 end 22 end
28 23
29 def edit 24 def edit
diff --git a/app/views/menu_items/index.html.erb b/app/views/menu_items/index.html.erb
index d2ff10e..db4a771 100644
--- a/app/views/menu_items/index.html.erb
+++ b/app/views/menu_items/index.html.erb
@@ -1,18 +1,12 @@
1<% content_for :subnavigation do %>
2 <%= link_to "new", new_menu_item_path %>
3<% end %>
4
5
1<h1>Menu Items</h1> 6<h1>Menu Items</h1>
2 7
3<ul> 8<ul>
4 <% @menu_items.each do |menu_item| %> 9 <% @menu_items.each do |menu_item| %>
5 <li><%= menu_item.title %></li> 10 <li><%= menu_item.title %></li>
6 <% end %> 11 <% end %>
7</ul> 12</ul> \ No newline at end of file
8
9<div id="menu_item_search">
10 <div>
11 <% form_tag admin_search_path do %>
12 <span>Add menu item: </span><%= text_field_tag :search_term %>
13 <% end %>
14 </div>
15 <div id="search_results">
16
17 </div>
18</div> \ No newline at end of file
diff --git a/app/views/menu_items/new.html.erb b/app/views/menu_items/new.html.erb
index e3f800e..64b9abb 100644
--- a/app/views/menu_items/new.html.erb
+++ b/app/views/menu_items/new.html.erb
@@ -1,2 +1,32 @@
1<h1>MenuItems#new</h1> 1<h1>Add Menu Item</h1>
2<p>Find me in app/views/menu_items/new.html.erb</p> 2
3<% form_for @menu_item do |f| %>
4 <table>
5
6 <tr>
7 <td class="description">Search</td>
8 <td>
9 <%= text_field_tag :menu_search_term %>
10 <div id="search_results">
11
12 </div>
13 </td>
14 </tr>
15 <tr>
16 <td class="description">Node Id</td>
17 <td><%= f.text_field :node_id %></td>
18 </tr>
19 <tr>
20 <td class="description">Path</td>
21 <td><%= f.text_field :path %></td>
22 </tr>
23 <tr>
24 <td class="description">Title</td>
25 <td><%= f.text_field :title %></td>
26 </tr>
27 <tr>
28 <td></td>
29 <td class="right"><%= f.submit 'Create' %></td>
30 </tr>
31 </table>
32<% end %> \ No newline at end of file
diff --git a/public/javascripts/admin_search.js b/public/javascripts/admin_search.js
index 1e6f545..186e4bc 100644
--- a/public/javascripts/admin_search.js
+++ b/public/javascripts/admin_search.js
@@ -50,7 +50,7 @@ admin_search = {
50menu_items = { 50menu_items = {
51 51
52 initialize_search : function() { 52 initialize_search : function() {
53 $("#search_term").bind("keyup", function() { 53 $("#menu_search_term").bind("keyup", function() {
54 if ($(this).attr("value")) { 54 if ($(this).attr("value")) {
55 $.ajax({ 55 $.ajax({
56 type: "GET", 56 type: "GET",
@@ -72,40 +72,26 @@ menu_items = {
72 show_results : function(results) { 72 show_results : function(results) {
73 $("#search_results").empty(); 73 $("#search_results").empty();
74 for (result in results) { 74 for (result in results) {
75 var foo = $(("<a href='#'>"+ results[result].title + "</a>")); 75 var link = $(("<a href='#'>"+ results[result].title + "</a>"));
76 $(foo).bind("click", function(){ 76 $(link).bind("click", function(){
77 menu_items.open_title_popup(); 77 menu_items.add_item_to_form(results[result]);
78 //menu_items.add_item_to_menu(results[result]);
79 return false; 78 return false;
80 }); 79 });
81 80
82 $("#search_results").append(foo); 81
82 // Sometimes I don't get jquery; wrap() didn't work *sigh*
83 // Guess I'll need a book someday or another framework
84 var wrapper = $("<div></div>");
85 $(wrapper).append(link)
86
87 $("#search_results").append(bar);
83 88
84 } 89 }
85 }, 90 },
86 91
87 open_title_popup : function() { 92 add_item_to_form : function(node) {
88 popup = $("<div><form action='#'><input id='item_title' type='text' /><input id='foobar' type='submit' /></form></div>"); 93 $("#new_menu_item #menu_item_node_id").val(node.node_id);
89 $("form", popup).submit(function(){ 94 $("#new_menu_item #menu_item_path").val("/" + node.unique_name);
90 alert("hi"); 95 $("#new_menu_item #menu_item_title").val(node.title);
91 return false; 96 }
92 });
93 $("body").append(popup);
94 },
95
96 add_item_to_menu : function(node) {
97 $.ajax({
98 type: "post",
99 url: "/menu_items/create",
100 data: {
101 "menu_item[node_id]" : node.node_id,
102 "menu_item[path]" : "/" + node.unique_name,
103 "menu_item[title]" : node.title
104 },
105 success : function() {
106 alert("s");
107 }
108 });
109 }
110
111}; \ No newline at end of file 97}; \ No newline at end of file