1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
|
admin_search = {
initialize : function() {
$("#search_widget").hide();
$(document).bind("keydown", 'Alt+f', function(){
admin_search.display_toggle();
return false;
});
},
display_toggle : function() {
if ($('#search_widget').css("display") != "none") {
$('#search_widget').fadeOut();
}
else {
$('#search_widget').fadeIn();
$('#search_term').attr("value", "");
$('#search_term').focus();
}
$("#search_term").bind("keyup", function() {
if ($(this).attr("value")) {
$.ajax({
type: "GET",
url: "/admin/search",
data: "search_term=" + $(this).attr("value"),
dataType: "json",
success : function(results) {
admin_search.show_results(results);
}
});
}
else {
$('#search_results').slideUp();
$('#search_results').empty();
}
});
},
show_results : function(results) {
$('#search_results').empty();
for (result in results) {
$('#search_results').append("<p><a href='"+ results[result].edit_path + "'>" + results[result].title + "</a></p>");
}
$('#search_results').slideDown();
}
};
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 = $(("<a href='#'>"+ results[result].title + "</a>"));
$(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 = $("<div><form action='#'><input id='item_title' type='text' /><input id='foobar' type='submit' /></form></div>");
$("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");
}
});
}
};
|