summaryrefslogtreecommitdiff
path: root/public/javascripts/admin_search.js
blob: d645cca8c4344467a45bcca7ebb0deaf684c19de (plain)
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
admin_search = {
  
  initialize : function() {
    $("#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 {
        $('#results').empty(); 
      }
    });
  },
  
  show_results : function(results) {
    $('#results').empty();
    for (result in results) {
      $('#results').append("<p>" + results[result].title + "</p>");
    }
  }
}