1 // Generated by CoffeeScript 1.3.3
4 $.fn.Readings.list = function(opts) {
5 return this.each(function() {
8 $('[data-role=header] h1').text(opts.title);
9 list = $('[data-role=listview]', this);
10 console.log("lst1 " + list.length);
12 $(".ui-listview-filter").hide();
14 render = function(objs) {
15 var divider, last_divider, obj, _i, _len;
16 console.log("lst " + list.length);
19 for (_i = 0, _len = objs.length; _i < _len; _i++) {
22 divider = obj.group();
23 if (last_divider !== divider) {
24 list.append("<li data-role=\"list-divider\">" + divider + "</li>");
25 last_divider = divider;
28 list.append(obj.render());
30 return list.listview('refresh');
33 Readings.catalogue.db.transaction(function(tx) {
34 return tx.executeSql(opts.sql, opts.params, function(tx, rs) {
35 var i, objs, _i, _ref;
37 for (i = _i = 0, _ref = rs.rows.length; 0 <= _ref ? _i < _ref : _i > _ref; i = 0 <= _ref ? ++_i : --_i) {
38 objs.push(opts.mapper(rs.rows.item(i)));
41 }, function(tx, err) {
42 window.last_error = err;
43 return alert("SQL Error while fetching list contents: " + err.message);
51 success: function(data) {
52 return render($.map(data, opts.mapper));
57 return opts.fetch(render);
62 $.fn.Readings.TagList = function(category) {
63 return this.each(function() {
65 $('[data-role=header] h1').text(Readings.config.get('categories')[category]);
66 list = $('[data-role=listview]', this);
67 if (Readings.config.get('show_filter').indexOf(category) < 0) {
68 $(".ui-listview-filter").hide();
71 url: Readings.config.get('wlurl') + ("/api/" + category),
73 success: function(data) {
74 var last_separator, separator, show_separator, t, tags, _i, _len;
75 tags = $.map(data, function(rec) {
76 return new Readings.Tag(rec, category);
79 last_separator = null;
80 show_separator = Readings.config.get('show_dividers').indexOf(category) >= 0;
81 for (_i = 0, _len = tags.length; _i < _len; _i++) {
84 separator = t.group();
85 if (last_separator !== separator) {
86 list.append("<li data-role=\"list-divider\">" + separator + "</li>");
87 last_separator = separator;
90 list.append(t.render());
92 return list.listview('refresh');