endlich!!!
[ReadingsJQM.git] / js / app / TagList.js
1 // Generated by CoffeeScript 1.3.3
2 (function() {
3
4   Readings.Tag = (function() {
5
6     function Tag(record) {
7       this.href = record.href;
8       this.name = record.name;
9       this.slug = $.grep(this.href.split('/'), function(e) {
10         return e !== "";
11       });
12     }
13
14     Tag.prototype.render = function() {
15       return "<li><a href=\"#\">" + this.name + "</a></li>";
16     };
17
18     return Tag;
19
20   })();
21
22   $.fn.Readings.TagList = function(category) {
23     return this.each(function() {
24       var list;
25       $('[data-role=header] h1').text(Readings.config.get('categories')[category]);
26       list = $('[data-role=listview]', this);
27       return $.ajax({
28         url: Readings.config.get('wlurl') + ("/api/" + category),
29         contentType: "json",
30         success: function(data) {
31           var t, tags, _i, _len;
32           console.log(data);
33           tags = $.map(data, function(rec) {
34             return new Readings.Tag(rec);
35           });
36           list.empty();
37           for (_i = 0, _len = tags.length; _i < _len; _i++) {
38             t = tags[_i];
39             list.append(t.render());
40           }
41           return list.listview('refresh');
42         }
43       });
44     });
45   };
46
47 }).call(this);