From b981d83e5e005817a67b11ccf92dd65bb506bcd4 Mon Sep 17 00:00:00 2001 From: hukl Date: Tue, 8 Sep 2009 16:35:22 +0200 Subject: new interface for adding nodes. still needs a bit radio button magick --- public/javascripts/admin_search.js | 54 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 52 insertions(+), 2 deletions(-) (limited to 'public/javascripts/admin_search.js') diff --git a/public/javascripts/admin_search.js b/public/javascripts/admin_search.js index c8d269f..1800506 100644 --- a/public/javascripts/admin_search.js +++ b/public/javascripts/admin_search.js @@ -95,5 +95,55 @@ menu_items = { } return barf; - } -}; \ No newline at end of file + } +}; + +parent_search = { + initialize_search : function() { + $("#parent_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) { + parent_search.show_results(results); + } + }); + } + else { + $('#search_results').slideUp(); + $('#search_results').empty(); + } + }); + }, + show_results : function(results) { + $("#search_results").empty(); + for (result in results) { + var link = $((""+ results[result].title + "")); + $(link).bind("click", parent_search.link_closure(results[result])); + + + // 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(wrapper); + + } + }, + link_closure : function(node) { + var barf = function(){ + $("#parent_search_term").attr("value", node.title); + alert(node.id); + $("#parent_id").attr("value", node.node_id); + $('#search_results').slideUp(); + $('#search_results').empty(); + return false; + } + + return barf; + } +} -- cgit v1.3