summaryrefslogtreecommitdiff
path: root/public/javascripts
diff options
context:
space:
mode:
authorhukl <contact@smyck.org>2009-08-09 11:57:44 +0200
committerhukl <contact@smyck.org>2009-08-09 11:57:44 +0200
commit9b4d055b649ad24ad1482f72d138aa73da1e4bd7 (patch)
treefa97f1877332fe05d1eb752c7ac63dce44edc32d /public/javascripts
parent550d9c1790b202175076894bf82d202bc32db5b6 (diff)
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.
Diffstat (limited to 'public/javascripts')
-rw-r--r--public/javascripts/admin_search.js46
1 files changed, 16 insertions, 30 deletions
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