offline version
[wl-mobile.git] / assets / www / js / filerepo.js
1 /*
2  * This file is part of WolneLektury-Mobile, licensed under GNU Affero GPLv3 or later.
3  * Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
4  */
5
6 var FileRepo = new function() {
7         /* API for files repository */
8         var self = this;
9
10         this.init = function(success, error) {
11                 success();
12         };
13
14         this.withLocalHtml = function(book_id, success, error) {
15                 console.log('info:withLocalHtml: id:' + book_id);
16                 View.spinner('Otwieranie treści utworu');
17
18                 var url = "html/" + book_id + '.html';
19                 console.log('info:withLocalHtml: local ajax: ' + url);
20                 var xhr = new XMLHttpRequest();
21                 xhr.open('GET', url, true);
22                 xhr.onload = function() {
23                         console.log('info:withLocalHtml: fetched by local ajax: ' + url);
24                         success && success(xhr.responseText);
25                 }
26                 xhr.onerror = error;
27                 xhr.send();
28         };
29
30
31         // calls the callback with contents of the HTML file for a given book,
32         // loaded from app data
33         this.withHtml = function(id, success, error) {
34                 console.log('info:withHtml: id:' + id);
35                 self.withLocalHtml(id, success);
36         };
37 };