X-Git-Url: https://git.mdrn.pl/ReadingsJQM.git/blobdiff_plain/45f8b33043d9aad64b1f89906323bc477efda0f3..ec887e1b76ec0d40861e67937026cc4b1d47f112:/js/app/models.js diff --git a/js/app/models.js b/js/app/models.js index d332ac1..e5722c5 100644 --- a/js/app/models.js +++ b/js/app/models.js @@ -1,4 +1,3 @@ -// Generated by CoffeeScript 1.3.3 (function() { var url_to_slug; @@ -17,13 +16,57 @@ Book.prototype.render = function() { var wlurl; wlurl = Readings.config.get('wlurl'); - return "
  • " + this.title + "

  • "; + return "
  • " + this.title + "

  • "; }; Book.prototype.group = function() { return this.authors; }; + Book.prototype.is_local = function() { + var html; + html = localStorage.getItem("html:" + this.id); + return !(html === null); + }; + + Book.prototype.get_text = function() { + var html; + if (this._local) { + html = localStorage.getItem("html:" + this.id); + if (html) return $(html); + } + return null; + }; + + Book.prototype.fetch = function(cb) { + var _this = this; + return $.ajax(Readings.config.get("wlurl" + ("/katalog/lektura/" + this.slug + ".html"), { + type: 'get', + dataType: 'html', + success: function(text) { + text = _this.mobilize_html(text); + localStorage.setItem("html:" + _this.id, text); + _this._local = 1; + return _this.db.transaction(function(tx) { + return tx.executeSql("UPDATE _local = 1 WHERE id=?", [_this.id], function(tx, rs) { + return cb(_this); + }); + }); + }, + error: function(er) { + throw Error("Error fetching book text slug=" + this.slug + ", " + er); + } + })); + }; + + Book.prototype.mobilize_html = function(html) { + var book_text; + html = $(html); + book_text = html.find("#book-id"); + html.find("#download, #header, #themes")["delete"](); + return book_text; + }; + return Book; })();