first take
[ReadingsJQM.git] / js / app / TagList.js
1 (function() {
2
3   Readings.Tag = (function() {
4
5     function Tag(record) {
6       this.href = record.href;
7       this.name = record.name;
8       this.slug = $.grep(this.href.split('/'), function(e) {
9         return e !== "";
10       });
11     }
12
13     Tag.prototype.render = function() {
14       return "<li";
15     };
16
17     return Tag;
18
19   })();
20
21   $.fn.Readings.TagList = function(category) {
22     return this.each(function() {
23       var list;
24       list = $(this);
25       return $.ajax({
26         url: Readings.config.get('wlurl') + ("/api/" + this.category),
27         contentType: "json",
28         success: function(data) {
29           var t, tags, _i, _len, _results;
30           console.log(data);
31           tags = $.map(data, function(rec) {
32             return new Readings.Tag(rec);
33           });
34           list.empty();
35           _results = [];
36           for (_i = 0, _len = tags.length; _i < _len; _i++) {
37             t = tags[_i];
38             _results.push(list.append(t.render()));
39           }
40           return _results;
41         }
42       });
43     });
44   };
45
46   Readings.TagList = (function() {
47
48     TagList.prototype.defaults = null;
49
50     function TagList(list, options) {
51       this.options = $.extend(this.defaults, options);
52       if (!(list.tag_list != null)) list.tag_list = this;
53       list.tag_list;
54     }
55
56     TagList.prototype.load = function() {
57       return $.ajax({
58         url: Readings.config.get('wlurl') + ("/api/" + this.category),
59         success: function() {
60           return true;
61         }
62       });
63     };
64
65     return TagList;
66
67   })();
68
69 }).call(this);