From 46117a9f103e2d547be2a47724e872b3f57ce983 Mon Sep 17 00:00:00 2001 From: hukl Date: Sat, 8 Aug 2009 22:38:48 +0200 Subject: lots of new code to manage menu items - harder than expected :/ --- public/javascripts/admin_search.js | 65 +++++++++++++++++++++++++++++++++++++- 1 file changed, 64 insertions(+), 1 deletion(-) (limited to 'public/javascripts/admin_search.js') diff --git a/public/javascripts/admin_search.js b/public/javascripts/admin_search.js index 28f87a0..1e6f545 100644 --- a/public/javascripts/admin_search.js +++ b/public/javascripts/admin_search.js @@ -45,4 +45,67 @@ admin_search = { } $('#search_results').slideDown(); } -} \ No newline at end of file +}; + +menu_items = { + + initialize_search : function() { + $("#search_term").bind("keyup", function() { + if ($(this).attr("value")) { + $.ajax({ + type: "GET", + url: "/admin/menu_search", + data: "search_term=" + $(this).attr("value"), + dataType: "json", + success : function(results) { + menu_items.show_results(results); + } + }); + } + else { + $('#search_results').slideUp(); + $('#search_results').empty(); + } + }); + }, + + 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]); + return false; + }); + + $("#search_results").append(foo); + + } + }, + + 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"); + } + }); + } + +}; \ No newline at end of file -- cgit v1.3