X-Git-Url: https://git.mdrn.pl/ReadingsJQM.git/blobdiff_plain/bdd9d26375a6489d7ff8eac944e29b0789f04a20..1be34458067b077d6403eb0bec498759be8fd4ca:/js/app/app.js?ds=sidebyside diff --git a/js/app/app.js b/js/app/app.js index b5e2ba2..b95b86e 100644 --- a/js/app/app.js +++ b/js/app/app.js @@ -1,6 +1,5 @@ -// Generated by CoffeeScript 1.3.3 (function() { - var rcategory; + var rcategory, rtag, rtagid; window.Readings = {}; @@ -17,21 +16,21 @@ }; Readings.init = function() { - if (Readings.initialized != null) { - return; - } + if (Readings.initialized != null) return; Readings.config = new Readings.Config({ - wlurl: 'http://readings.local', + wlurl: 'http://dev.wolnelektury.pl', + initdburl: 'http://dev.wolnelektury.pl/media/api/mobile/initial/initial.sql', categories: { - 'authors': 'autor', - 'epochs': 'epoka', - 'genres': 'gatunek', - 'kinds': 'rodzaj', - 'themes': 'motyw' + 'author': 'autor', + 'epoch': 'epoka', + 'genre': 'gatunek', + 'kind': 'rodzaj' }, show_filter: ['authors', 'themes'], - show_dividers: ['authors', 'themes'] + show_dividers: ['authors', 'themes'], + db_version: '1.0' }); + Readings.catalogue = new Readings.Catalogue().open(); return Readings.initialized = true; }; @@ -42,22 +41,44 @@ rcategory = /category=(\w+)/; + rtag = /tag=([a-z0-9-]+)/; + + rtagid = /tag_id=([0-9]+)/; + $(document).on('pageinit', "#page-tags", function(ev, ui) { var category; category = rcategory.exec($(this).attr('data-url')); - if ((category != null) && (category[1] != null)) { - return $(this).Readings('list', { - category: category[1], - url: Readings.config.get('wlurl') + ("/api/" + category[1]), - filter: Readings.config.get('show_filter').indexOf(category[1]) >= 0, - mapper: function(rec) { - return new Readings.Tag(rec, category[1]); + if (category != null) { + category = category[1]; + if (category != null) { + return $(this).Readings('list', { + sql: "SELECT * FROM tag WHERE category=? ORDER BY sort_key", + params: [category], + filter: Readings.config.get('show_filter').indexOf(category) >= 0, + mapper: function(rec) { + return new Readings.Tag(rec, category); + }, + dividers: Readings.config.get('show_dividers').indexOf(category) >= 0 + }); + } + } + return alert('no category in query string'); + }); + + $(document).on('pageinit', '#page-books', function(ev, ui) { + var tag, tag_id, tag_id_m, + _this = this; + tag_id_m = rtagid.exec($(this).attr('data-url')); + if (tag_id_m != null) tag_id = tag_id_m[1]; + return tag = Readings.catalogue.withTag(tag_id, function(tag) { + return $(_this).Readings('list', { + fetch: function(cb) { + return Readings.catalogue.withBooks(tag, cb); }, - dividers: Readings.config.get('show_dividers').indexOf(category[1]) >= 0 + filter: true, + dividers: tag.category !== 'author' }); - } else { - return alert('no category in query string'); - } + }); }); }).call(this);