- this.withLocal = function(win, fail) {
- if (self.root) {
- self.root.getDirectory('html', {}, function(dir) {
- var reader = dir.createReader();
- reader.readEntries(win, fail);
- });
- }
- else {
- win && win([]);
- }
- }
-
-
- // downloads HTML file from server, saves it in cache and calls success with file contents
- this.withHtmlFromServer = function(book_id, success, error) {
- console.log('info:withHtmlFromServer: id:' + book_id);
- // read file from WL
- Catalogue.withBook(book_id, function(book) {
- var url = WL + book.html_file;
- console.log('info:withHtmlFromServer: fetching url: ' + url);
-
- View.spinner("Pobieranie treści utworu z sieci");
-
- if (self.root) {
- Downloader.downloadFile(url, self.root.fullPath + "/html/", ""+book_id, true,
- function(data){
- console.log('info:withHtmlFromServer: loaded file from WL');
- self.withLocalHtml(book_id, success, error);
- }, function(data) {
- console.log('error downloading file!')
- error && error("error: " + data);
- });
- }
- else {
- // there's no big fs, so we'll just get the text from AJAX
- console.log('info:withHtmlFromServer: ajax: ' + url);
- var xhr = new XMLHttpRequest();
- xhr.open("GET", url);
- xhr.onload = function() {
- console.log('info:withHtmlFromServer: fetched by ajax: ' + url);
- success && success(xhr.responseText);
- }
- xhr.onerror = function() {
- console.log('error downloading file!')
- error && error("error: " + data);
- }
- xhr.send();
- }
- });
- };
-