X-Git-Url: https://git.mdrn.pl/ReadingsJQM.git/blobdiff_plain/1be34458067b077d6403eb0bec498759be8fd4ca..refs/heads/readings:/js/app/models.coffee?ds=sidebyside diff --git a/js/app/models.coffee b/js/app/models.coffee index ef1c7f5..147a140 100644 --- a/js/app/models.coffee +++ b/js/app/models.coffee @@ -13,13 +13,45 @@ class Readings.Book "
  • -

    #{@title}

    +

    #{@title}

  • " group: -> @authors + is_local: -> + html = localStorage.getItem("html:#{@id}") + return not (html == null) + + get_text: -> + if @_local + html = localStorage.getItem("html:#{@id}") + return $(html) if html + null + + # fetches books content from WL + # and pass it to callback + fetch: (cb) -> + $.ajax Readings.config.get "wlurl" + "/katalog/lektura/#{@slug}.html", + type: 'get', + dataType: 'html', + success: (text) => + text = @mobilize_html text + localStorage.setItem("html:#{@id}", text) + @_local = 1 + @db.transaction (tx) => + tx.executeSql "UPDATE _local = 1 WHERE id=?", [@id], (tx, rs) => + cb this + error: (er) -> + throw Error "Error fetching book text slug=#{@slug}, #{er}" + + mobilize_html: (html) -> + html = $(html) + book_text = html.find("#book-id") + html.find("#download, #header, #themes").delete() + book_text + class Readings.Tag constructor: (record, @category) ->