summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--public/javascripts/admin_search.js123
1 files changed, 69 insertions, 54 deletions
diff --git a/public/javascripts/admin_search.js b/public/javascripts/admin_search.js
index 6d3ca93..98571de 100644
--- a/public/javascripts/admin_search.js
+++ b/public/javascripts/admin_search.js
@@ -1,12 +1,12 @@
1admin_search = { 1admin_search = {
2 2
3 initialize : function() { 3 initialize : function() {
4 $(document).bind("keydown", 'Alt+f', function(){ 4 $(document).bind("keydown", 'Alt+f', function(){
5 admin_search.display_toggle(); 5 admin_search.display_toggle();
6 return false; 6 return false;
7 }); 7 });
8 }, 8 },
9 9
10 display_toggle : function() { 10 display_toggle : function() {
11 if ($('#search_widget').css("display") != "none") { 11 if ($('#search_widget').css("display") != "none") {
12 $('#search_widget').fadeOut(); 12 $('#search_widget').fadeOut();
@@ -16,7 +16,7 @@ admin_search = {
16 $('#search_term').attr("value", ""); 16 $('#search_term').attr("value", "");
17 $('#search_term').focus(); 17 $('#search_term').focus();
18 } 18 }
19 19
20 $("#search_term").bind("keyup", function() { 20 $("#search_term").bind("keyup", function() {
21 if ($(this).attr("value")) { 21 if ($(this).attr("value")) {
22 $.ajax({ 22 $.ajax({
@@ -31,11 +31,11 @@ admin_search = {
31 } 31 }
32 else { 32 else {
33 $('#search_results').slideUp(); 33 $('#search_results').slideUp();
34 $('#search_results').empty(); 34 $('#search_results').empty();
35 } 35 }
36 }); 36 });
37 }, 37 },
38 38
39 show_results : function(results) { 39 show_results : function(results) {
40 $('#search_results').empty(); 40 $('#search_results').empty();
41 for (result in results) { 41 for (result in results) {
@@ -46,7 +46,7 @@ admin_search = {
46}; 46};
47 47
48menu_items = { 48menu_items = {
49 49
50 initialize_search : function() { 50 initialize_search : function() {
51 $("#menu_search_term").bind("keyup", function() { 51 $("#menu_search_term").bind("keyup", function() {
52 if ($(this).attr("value")) { 52 if ($(this).attr("value")) {
@@ -62,28 +62,28 @@ menu_items = {
62 } 62 }
63 else { 63 else {
64 $('#search_results').slideUp(); 64 $('#search_results').slideUp();
65 $('#search_results').empty(); 65 $('#search_results').empty();
66 } 66 }
67 }); 67 });
68 }, 68 },
69 69
70 show_results : function(results) { 70 show_results : function(results) {
71 $("#search_results").empty(); 71 $("#search_results").empty();
72 for (result in results) { 72 for (result in results) {
73 var link = $(("<a href='#'>"+ results[result].title + "</a>")); 73 var link = $(("<a href='#'>"+ results[result].title + "</a>"));
74 $(link).bind("click", menu_items.link_closure(results[result])); 74 $(link).bind("click", menu_items.link_closure(results[result]));
75 75
76 76
77 // Sometimes I don't get jquery; wrap() didn't work *sigh* 77 // Sometimes I don't get jquery; wrap() didn't work *sigh*
78 // Guess I'll need a book someday or another framework 78 // Guess I'll need a book someday or another framework
79 var wrapper = $("<div></div>"); 79 var wrapper = $("<div></div>");
80 $(wrapper).append(link) 80 $(wrapper).append(link)
81 81
82 $("#search_results").append(wrapper); 82 $("#search_results").append(wrapper);
83 83
84 } 84 }
85 }, 85 },
86 86
87 link_closure : function(node) { 87 link_closure : function(node) {
88 var barf = function(){ 88 var barf = function(){
89 $("#menu_item_node_id").val(node.node_id); 89 $("#menu_item_node_id").val(node.node_id);
@@ -91,7 +91,7 @@ menu_items = {
91 $("#menu_item_title").val(node.title); 91 $("#menu_item_title").val(node.title);
92 return false; 92 return false;
93 } 93 }
94 94
95 return barf; 95 return barf;
96 } 96 }
97}; 97};
@@ -99,7 +99,7 @@ menu_items = {
99parent_search = { 99parent_search = {
100 initialize_search : function() { 100 initialize_search : function() {
101 parent_search.initialize_radio_buttons(); 101 parent_search.initialize_radio_buttons();
102 102
103 $("#parent_search_term").bind("keyup", function() { 103 $("#parent_search_term").bind("keyup", function() {
104 if ($(this).attr("value")) { 104 if ($(this).attr("value")) {
105 $.ajax({ 105 $.ajax({
@@ -114,28 +114,31 @@ parent_search = {
114 } 114 }
115 else { 115 else {
116 $('#search_results').slideUp(); 116 $('#search_results').slideUp();
117 $('#search_results').empty(); 117 $('#search_results').empty();
118 } 118 }
119 }); 119 });
120 }, 120 },
121 121
122 show_results : function(results) { 122 show_results : function(results) {
123 $("#search_results").empty(); 123 $("#search_results").empty();
124 var found = false;
124 for (result in results) { 125 for (result in results) {
125 var link = $(("<a href='#'>"+ results[result].title + "</a>")); 126 var link = $(("<a href='#'>"+ results[result].title + "</a>"));
126 $(link).bind("click", parent_search.link_closure(results[result])); 127 $(link).bind("click", parent_search.link_closure(results[result]));
127 128
128 129
129 // Sometimes I don't get jquery; wrap() didn't work *sigh* 130 // Sometimes I don't get jquery; wrap() didn't work *sigh*
130 // Guess I'll need a book someday or another framework 131 // Guess I'll need a book someday or another framework
131 var wrapper = $("<div></div>"); 132 var wrapper = $("<div></div>");
132 $(wrapper).append(link) 133 $(wrapper).append(link);
133 134
134 $("#search_results").append(wrapper); 135 $("#search_results").append(wrapper);
135 136 found = true;
136 } 137 }
138 if (found)
139 $('#search_results').slideDown();
137 }, 140 },
138 141
139 link_closure : function(node) { 142 link_closure : function(node) {
140 var barf = function(){ 143 var barf = function(){
141 $("#parent_search_term").attr("value", node.title); 144 $("#parent_search_term").attr("value", node.title);
@@ -144,64 +147,76 @@ parent_search = {
144 $('#search_results').empty(); 147 $('#search_results').empty();
145 return false; 148 return false;
146 } 149 }
147 150
148 return barf; 151 return barf;
149 }, 152 },
150 153
151 initialize_radio_buttons : function() { 154 initialize_radio_buttons : function() {
152 $("#kind_top_level").bind("change", function(){ 155 $("#kind_top_level").bind("change", function(){
153 $("#parent_search_field").hide(); 156 $("#parent_search_field").hide();
154 }); 157 });
155 158
156 $("#kind_update").bind("change", function(){ 159 $("#kind_update").bind("change", function(){
157 $("#parent_search_field").hide(); 160 $("#parent_search_field").hide();
158 }); 161 });
159 162
160 $("#kind_generic").bind("change", function(){ 163 $("#kind_generic").bind("change", function(){
161 $("#parent_search_field").show(); 164 $("#parent_search_field").show();
162 }); 165 });
163 166
164 } 167 }
165} 168}
166 169
167move_to_search = { 170move_to_search = {
168 initialize_search : function() { 171 initialize_search : function() {
169 $("#move_to_search_term").bind("keyup", function() { 172 $("#move_to_search_term").bind("keyup", function() { move_to_search.do_search($(this))});
170 if ($(this).attr("value")) { 173 $("#move_to_search_term").bind("keydown", function() { move_to_search.do_search($(this))});
171 $.ajax({ 174 $("#move_to_search_term").bind("keypress", function() { move_to_search.do_search($(this))});
172 type: "GET", 175 $("#move_to_search_term").bind("paste", function() { move_to_search.do_search($(this))});
173 url: "/admin/menu_search", 176 $("#move_to_search_term").bind("cut", function() { move_to_search.do_search($(this))});
174 data: "search_term=" + $(this).attr("value"),
175 dataType: "json",
176 success : function(results) {
177 move_to_search.show_results(results);
178 }
179 });
180 }
181 else {
182 $('#search_results').slideUp();
183 $('#search_results').empty();
184 }
185 });
186 }, 177 },
187 178
179 do_search : function(_this) {
180 if (_this.attr("value")) {
181 $.ajax({
182 type: "GET",
183 url: "/admin/menu_search",
184 data: "search_term=" + _this.attr("value"),
185 dataType: "json",
186 success : function(results) {
187 move_to_search.show_results(results);
188 }
189 });
190 }
191 else {
192 $('#search_results').slideUp();
193 $('#search_results').empty();
194 }
195 },
196
188 show_results : function(results) { 197 show_results : function(results) {
189 $("#search_results").empty(); 198 $("#search_results").empty();
199 var found = false;
190 for (result in results) { 200 for (result in results) {
191 var link = $(("<a href='#'>"+ results[result].title + "</a>")); 201 var link = $(("<a href='#'>"+ results[result].title + "</a>"));
192 $(link).bind("click", move_to_search.link_closure(results[result])); 202 $(link).bind("click", move_to_search.link_closure(results[result]));
193 203
194 204
195 // Sometimes I don't get jquery; wrap() didn't work *sigh* 205 // Sometimes I don't get jquery; wrap() didn't work *sigh*
196 // Guess I'll need a book someday or another framework 206 // Guess I'll need a book someday or another framework
197 var wrapper = $("<div></div>"); 207 var wrapper = $("<div></div>");
198 $(wrapper).append(link) 208 $(wrapper).append(link)
199 209
200 $("#search_results").append(wrapper); 210 $("#search_results").append(wrapper);
201 211 found = true;
202 } 212 }
213 if (found)
214 $('#search_results').slideDown();
215 else
216 $('#search_results').slideUp();
217
203 }, 218 },
204 219
205 link_closure : function(node) { 220 link_closure : function(node) {
206 var barf = function(){ 221 var barf = function(){
207 $("#move_to_search_term").attr("value", node.title); 222 $("#move_to_search_term").attr("value", node.title);
@@ -210,7 +225,7 @@ move_to_search = {
210 $('#search_results').empty(); 225 $('#search_results').empty();
211 return false; 226 return false;
212 } 227 }
213 228
214 return barf; 229 return barf;
215 } 230 }
216} \ No newline at end of file 231}