diff options
Diffstat (limited to 'public/javascripts/admin_search.js')
| -rw-r--r-- | public/javascripts/admin_search.js | 54 |
1 files changed, 52 insertions, 2 deletions
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 = { | |||
| 95 | } | 95 | } |
| 96 | 96 | ||
| 97 | return barf; | 97 | return barf; |
| 98 | } | 98 | } |
| 99 | }; \ No newline at end of file | 99 | }; |
| 100 | |||
| 101 | parent_search = { | ||
| 102 | initialize_search : function() { | ||
| 103 | $("#parent_search_term").bind("keyup", function() { | ||
| 104 | if ($(this).attr("value")) { | ||
| 105 | $.ajax({ | ||
| 106 | type: "GET", | ||
| 107 | url: "/admin/menu_search", | ||
| 108 | data: "search_term=" + $(this).attr("value"), | ||
| 109 | dataType: "json", | ||
| 110 | success : function(results) { | ||
| 111 | parent_search.show_results(results); | ||
| 112 | } | ||
| 113 | }); | ||
| 114 | } | ||
| 115 | else { | ||
| 116 | $('#search_results').slideUp(); | ||
| 117 | $('#search_results').empty(); | ||
| 118 | } | ||
| 119 | }); | ||
| 120 | }, | ||
| 121 | show_results : function(results) { | ||
| 122 | $("#search_results").empty(); | ||
| 123 | for (result in results) { | ||
| 124 | var link = $(("<a href='#' rel='" + results[result].id+ "'>"+ results[result].title + "</a>")); | ||
| 125 | $(link).bind("click", parent_search.link_closure(results[result])); | ||
| 126 | |||
| 127 | |||
| 128 | // Sometimes I don't get jquery; wrap() didn't work *sigh* | ||
| 129 | // Guess I'll need a book someday or another framework | ||
| 130 | var wrapper = $("<div></div>"); | ||
| 131 | $(wrapper).append(link) | ||
| 132 | |||
| 133 | $("#search_results").append(wrapper); | ||
| 134 | |||
| 135 | } | ||
| 136 | }, | ||
| 137 | link_closure : function(node) { | ||
| 138 | var barf = function(){ | ||
| 139 | $("#parent_search_term").attr("value", node.title); | ||
| 140 | alert(node.id); | ||
| 141 | $("#parent_id").attr("value", node.node_id); | ||
| 142 | $('#search_results').slideUp(); | ||
| 143 | $('#search_results').empty(); | ||
| 144 | return false; | ||
| 145 | } | ||
| 146 | |||
| 147 | return barf; | ||
| 148 | } | ||
| 149 | } | ||
