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