Add special ctaegory "[All]" to dropdown.
[mkws-moved-to-github.git] / src / mkws-widget-categories.js
index 0b1f114..6ce09fe 100644 (file)
@@ -7,7 +7,6 @@ mkws.registerWidgetType('Categories', function() {
     }
 
     this.team.queue("authenticated").subscribe(function(authName, realm) {
-       $(that.node).append("<p><b>Categories for " + realm + "</b></p>");      
        var req = new pzHttpRequest(that.config.pazpar2_url + "?command=categories", function(err) {
            alert("HTTP call for categories failed: " + err)
        });
@@ -18,7 +17,19 @@ mkws.registerWidgetType('Categories', function() {
                return;
            }
            that.log("got categories: " + data);
-           // Parse once we've figured out the format
+
+            var text = [];
+            text.push("Select category: ");
+            text.push("<select name='mkwsCategory' " +
+                     "onchange='mkws.limitCategory(\"" + that.team.name() + "\", this.value)'>");
+            text.push("<option value=''>[All]</option>");
+            $(data).find('category').each(function() {
+                var name = $(this).find('categoryName').text();
+                var id = $(this).find('categoryId').text();
+                text.push("<option value='", id, "'>", name, "</option>");
+            });
+            text.push("</select>");
+           $(that.node).html(text.join(''));
        });
     });
 });