From 9b4d055b649ad24ad1482f72d138aa73da1e4bd7 Mon Sep 17 00:00:00 2001 From: hukl Date: Sun, 9 Aug 2009 11:57:44 +0200 Subject: refactored the way new menu items are created. went back to rest and added the js ajax search to fill out the form for you. much cleaner, unobtrusive approach. --- public/javascripts/admin_search.js | 46 +++++++++++++------------------------- 1 file changed, 16 insertions(+), 30 deletions(-) (limited to 'public/javascripts') 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 = { menu_items = { initialize_search : function() { - $("#search_term").bind("keyup", function() { + $("#menu_search_term").bind("keyup", function() { if ($(this).attr("value")) { $.ajax({ type: "GET", @@ -72,40 +72,26 @@ menu_items = { show_results : function(results) { $("#search_results").empty(); for (result in results) { - var foo = $((""+ results[result].title + "")); - $(foo).bind("click", function(){ - menu_items.open_title_popup(); - //menu_items.add_item_to_menu(results[result]); + var link = $((""+ results[result].title + "")); + $(link).bind("click", function(){ + menu_items.add_item_to_form(results[result]); return false; }); - $("#search_results").append(foo); + + // Sometimes I don't get jquery; wrap() didn't work *sigh* + // Guess I'll need a book someday or another framework + var wrapper = $("
"); + $(wrapper).append(link) + + $("#search_results").append(bar); } }, - open_title_popup : function() { - popup = $("
"); - $("form", popup).submit(function(){ - alert("hi"); - return false; - }); - $("body").append(popup); - }, - - add_item_to_menu : function(node) { - $.ajax({ - type: "post", - url: "/menu_items/create", - data: { - "menu_item[node_id]" : node.node_id, - "menu_item[path]" : "/" + node.unique_name, - "menu_item[title]" : node.title - }, - success : function() { - alert("s"); - } - }); - } - + add_item_to_form : function(node) { + $("#new_menu_item #menu_item_node_id").val(node.node_id); + $("#new_menu_item #menu_item_path").val("/" + node.unique_name); + $("#new_menu_item #menu_item_title").val(node.title); + } }; \ No newline at end of file -- cgit v1.3