8b2b00f26e82eaddcbb6dcdd4ca258fb0e26517c
[mkws-moved-to-github.git] / src / mkws-widget-categories.js
1 mkws.registerWidgetType('categories', function() {
2   var that = this;
3
4   this.team.queue("authenticated").subscribe(function(authName, realm) {
5     var req = new pzHttpRequest(mkws.pazpar2_url() + "?command=categories", function(err) {
6       alert("HTTP call for categories failed: " + err)
7     });
8
9     req.get(null, function(data) {
10       if (!$.isXMLDoc(data)) {
11         alert("categories response document is not XML");
12         return;
13       }
14       that.info("got categories: " + data);
15
16       var text = [];
17       text.push("Select category: ");
18       text.push("<select name='mkws-category mkwsCategory' " +
19                 "onchange='mkws.limitCategory(\"" + that.team.name() + "\", this.value)'>");
20       text.push("<option value=''>[All]</option>");
21       $(data).find('category').each(function() {
22         var name = $(this).find('categoryName').text();
23         var id = $(this).find('categoryId').text();
24         text.push("<option value='", id, "'>", name, "</option>");
25       });
26       text.push("</select>");
27       that.node.html(text.join(''));
28     });
29   });
30 });