1
0
mirror of https://git.tt-rss.org/git/tt-rss.git synced 2025-12-14 05:35:55 +00:00

move offline stuff to offline.js

This commit is contained in:
Andrew Dolgov
2009-02-04 10:07:15 +03:00
parent c8a9fe5b07
commit 20919a06a1
4 changed files with 1 additions and 426 deletions

113
tt-rss.js
View File

@@ -1544,117 +1544,4 @@ function init_gears() {
}
}
function init_offline() {
try {
offline_mode = true;
Element.hide("dispSwitchPrompt");
Element.hide("feedBrowserPrompt");
Element.hide("quickMenuChooser");
init_params["theme"] = "";
render_offline_feedlist();
remove_splash();
} catch (e) {
exception_error("init_offline", e);
}
}
function offline_download_parse(stage, transport) {
try {
if (transport.responseXML) {
if (stage == 0) {
var feeds = transport.responseXML.getElementsByTagName("feed");
if (feeds.length > 0) {
db.execute("DELETE FROM feeds");
}
for (var i = 0; i < feeds.length; i++) {
var id = feeds[i].getAttribute("id");
var has_icon = feeds[i].getAttribute("has_icon");
var title = feeds[i].firstChild.nodeValue;
db.execute("INSERT INTO feeds (id,title,has_icon)"+
"VALUES (?,?,?)",
[id, title, has_icon]);
}
window.setTimeout("update_offline_data("+(stage+1)+")", 60*1000);
} else {
var articles = transport.responseXML.getElementsByTagName("article");
var articles_found = 0;
for (var i = 0; i < articles.length; i++) {
var a = eval("("+articles[i].firstChild.nodeValue+")");
articles_found++;
if (a) {
var date = new Date();
var ts = Math.round(date.getTime() / 1000);
db.execute("DELETE FROM articles WHERE id = ?", [a.id]);
db.execute("INSERT INTO articles "+
"(id, feed_id, title, link, guid, updated, content, "+
"unread, marked, tags, added) "+
"VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
[a.id, a.feed_id, a.title, a.link, a.guid, a.updated,
a.content, a.unread, a.marked, a.tags, ts]);
}
}
if (articles_found > 0) {
window.setTimeout("update_offline_data("+(stage+1)+")", 60*1000);
} else {
window.setTimeout("update_offline_data(0)", 1800*1000);
var date = new Date();
var ts = Math.round(date.getTime() / 1000);
db.execute("DELETE FROM articles WHERE added < ? - 2592000", [ts]);
}
}
}
} catch (e) {
exception_error("offline_download_parse", e);
}
}
function update_offline_data(stage) {
try {
if (!stage) stage = 0;
debug("update_offline_data: stage " + stage);
// notify_progress("Loading, please wait... (" + stage +")", true);
var query = "backend.php?op=rpc&subop=download&stage=" + stage;
var rs = db.execute("SELECT MAX(id), MIN(id) FROM articles");
if (rs.isValidRow() && rs.field(0)) {
var offline_dl_max_id = rs.field(0);
var offline_dl_min_id = rs.field(1);
query = query + "&cidt=" + offline_dl_max_id;
query = query + "&cidb=" + offline_dl_min_id;
}
new Ajax.Request(query, {
onComplete: function(transport) {
offline_download_parse(stage, transport);
debug("update_offline_data: done " + stage);
} });
} catch (e) {
exception_error("initiate_offline_download", e);
}
}