ported to Web SQL
[ReadingsJQM.git] / js / app / app.js
1 // Generated by CoffeeScript 1.3.3
2 (function() {
3   var rcategory, rtag, rtagid;
4
5   window.Readings = {};
6
7   $.fn.Readings = function() {
8     var a, args, meth, _i, _len;
9     meth = arguments[0];
10     args = [];
11     for (_i = 0, _len = arguments.length; _i < _len; _i++) {
12       a = arguments[_i];
13       args.push(a);
14     }
15     args.shift();
16     return $.fn.Readings[meth].apply(this, args);
17   };
18
19   Readings.init = function() {
20     if (Readings.initialized != null) {
21       return;
22     }
23     Readings.config = new Readings.Config({
24       wlurl: 'http://readings.local',
25       categories: {
26         'author': 'autor',
27         'epoch': 'epoka',
28         'genre': 'gatunek',
29         'kind': 'rodzaj'
30       },
31       show_filter: ['authors', 'themes'],
32       show_dividers: ['authors', 'themes'],
33       db_version: '1.0'
34     });
35     Readings.catalogue = new Readings.Catalogue().open();
36     return Readings.initialized = true;
37   };
38
39   $(document).on('pageinit', '#page-categories', function(ev) {
40     Readings.init();
41     return $('#list-categories').Readings('CategoryList');
42   });
43
44   rcategory = /category=(\w+)/;
45
46   rtag = /tag=([a-z0-9-]+)/;
47
48   rtagid = /tag_id=([0-9]+)/;
49
50   $(document).on('pageinit', "#page-tags", function(ev, ui) {
51     var category;
52     category = rcategory.exec($(this).attr('data-url'));
53     if (category != null) {
54       category = category[1];
55       if (category != null) {
56         return $(this).Readings('list', {
57           sql: "SELECT * FROM tag WHERE category=? ORDER BY sort_key",
58           params: [category],
59           filter: Readings.config.get('show_filter').indexOf(category) >= 0,
60           mapper: function(rec) {
61             return new Readings.Tag(rec, category);
62           },
63           dividers: Readings.config.get('show_dividers').indexOf(category) >= 0
64         });
65       }
66     }
67     return alert('no category in query string');
68   });
69
70   $(document).on('pageinit', '#page-books', function(ev, ui) {
71     var tag, tag_id, tag_id_m,
72       _this = this;
73     tag_id_m = rtagid.exec($(this).attr('data-url'));
74     if (tag_id_m != null) {
75       tag_id = tag_id_m[1];
76     }
77     return tag = Readings.catalogue.withTag(tag_id, function(tag) {
78       return $(_this).Readings('list', {
79         fetch: function(cb) {
80           return Readings.catalogue.withBooks(tag, cb);
81         },
82         filter: true,
83         dividers: tag.category !== 'author'
84       });
85     });
86   });
87
88 }).call(this);