if (stage == 0) {
+ $("offlineModeSyncMsg").innerHTML = __("Synchronizing feeds...");
+
var feeds = transport.responseXML.getElementsByTagName("feed");
if (feeds.length > 0) {
[id, title, has_icon, cat_id]);
}
+ $("offlineModeSyncMsg").innerHTML = __("Synchronizing categories...");
+
var cats = transport.responseXML.getElementsByTagName("category");
if (feeds.length > 0) {
[id, title, collapsed]);
}
+ $("offlineModeSyncMsg").innerHTML = __("Synchronizing labels...");
+
var labels = transport.responseXML.getElementsByTagName("label");
if (labels.length > 0) {
[id, caption, fg_color, bg_color]);
}
- sync_timer = window.setTimeout("update_offline_data("+(stage+1)+")", 10*1000);
+ $("offlineModeSyncMsg").innerHTML = __("Synchronizing articles...");
+
+ sync_timer = window.setTimeout("update_offline_data("+(stage+1)+")", 2*1000);
} else {
var articles = transport.responseXML.getElementsByTagName("article");
if (articles_found >= limit || has_sync_data) {
sync_timer = window.setTimeout("update_offline_data("+(stage+1)+")",
- 5*1000);
+ 3*1000);
debug("<b>update_offline_data: done " + stage + " HSD: " +
has_sync_data + "</b>");
} else {
$("offlineModeSyncMsg").innerHTML = msg;
}
- var hide_elems = $$("div.hideWhenSyncing");
-
- for (var j = 0; j < hide_elems.length; j++) {
- Element.show(hide_elems[j]);
- }
+ offlineSyncShowHideElems(false);
sync_in_progress = false;
if (pic) {
pic.src = "images/offline.png";
- var msg = __("Last sync: Error receiving data");
+ var msg = __("Last sync: Error receiving data.");
articles_synced = 0;
$("offlineModeSyncMsg").innerHTML = msg;
}
- var hide_elems = $$("div.hideWhenSyncing");
-
- for (var j = 0; j < hide_elems.length; j++) {
- Element.show(hide_elems[j]);
- }
-
+ offlineSyncShowHideElems(false);
}
} catch (e) {
}
}
- var hide_elems = $$("div.hideWhenSyncing");
+ offlineSyncShowHideElems(true);
- for (var j = 0; j < hide_elems.length; j++) {
- Element.hide(hide_elems[j]);
- }
-
sync_in_progress = true;
new Ajax.Request(query, {
try {
if (window.google && google.gears) {
- localServer = google.gears.factory.create("beta.localserver");
+
+ try {
+ localServer = google.gears.factory.create("beta.localserver");
+ } catch (e) {
+ return;
+ }
+
store = localServer.createManagedStore("tt-rss");
store.manifestUrl = "manifest.json.php";
// debug("[Local store] currentVersion = " + store.currentVersion);
+ var rs = db.execute("SELECT COUNT(*) FROM articles");
+ var count = 0;
+ if (rs.isValidRow()) {
+ count = rs.field(0);
+ }
+
+ rs.close();
+
+ if (count == 0) {
+ notify_error("You have to synchronize some articles before going into offline mode.");
+ return;
+ }
+
if (confirm(__("Switch Tiny Tiny RSS into offline mode?"))) {
store.checkForUpdate();
var timerId = window.setInterval(function() {
if (store.currentVersion) {
window.clearInterval(timerId);
- //debug("[Local store] sync complete: " + store.currentVersion);
- window.location.href = "tt-rss.php";
+ debug("[Local store] sync complete: " + store.currentVersion);
+
+ //window.location.href = "tt-rss.php";
+
+ offlineDownloadStop();
+ offline_mode = true;
+ init_offline();
+
+ notify_info("Tiny Tiny RSS is in offline mode.");
+
} else if (store.updateStatus == 3) {
debug("[Local store] sync error: " + store.lastErrorMessage);
+ notify_error(store.lastErrorMessage, true);
} }, 500);
}
}
function offlineDownloadStop() {
try {
if (db && sync_in_progress && getInitParam("offline_enabled") == "1") {
- window.clearTimeout(sync_timer);
+
+ sync_in_progress = false;
+
+ if (sync_timer) {
+ window.clearTimeout(sync_timer);
+ sync_timer = false;
+ }
+
+ var pic = $("offlineModePic");
+
+ if (pic) {
+ pic.src = "images/offline.png";
+ var msg = __("Last sync: Cancelled.");
+ articles_synced = 0;
+ $("offlineModeSyncMsg").innerHTML = msg;
+ }
+
+ offlineSyncShowHideElems(false);
+
}
} catch (e) {
exception_error("offlineDownloadStart", e);
db.execute("DELETE FROM article_labels");
db.execute("DELETE FROM labels");
db.execute("DELETE FROM feeds");
+ db.execute("DELETE FROM cache");
- notify_info("Offline data removed.");
+ notify_info("Local data removed.");
}
}
} catch (e) {
exception_error("offlineUpdateStore", e);
}
}
+
+function offlineSyncShowHideElems(syncing) {
+ try {
+
+ var elems = $$("div.hideWhenSyncing");
+
+ for (var j = 0; j < elems.length; j++) {
+ if (syncing) {
+ Element.hide(elems[j]);
+ } else {
+ Element.show(elems[j]);
+ }
+ }
+
+ var elems = $$("div.showWhenSyncing");
+
+ for (var j = 0; j < elems.length; j++) {
+ if (syncing) {
+ Element.show(elems[j]);
+ } else {
+ Element.hide(elems[j]);
+ }
+ }
+
+ } catch (e) {
+ exception_error("offlineSyncShowHideElems", e);
+ }
+}
onmouseout="enable_selection(true)"
onclick="toggleOfflineModeInfo()"
src="images/offline.png" style="display:none"
- title="<?php echo __('Offline mode') ?>"/>
+ title="<?php echo __('Offline reading') ?>"/>
<div id="offlineModeDrop" style="display : none">
<div id="offlineModeSyncMsg">---</div>
+
+ <div class="showWhenSyncing" style="display : none">
+ <a href="javascript:offlineDownloadStop()">
+ <?php echo __('Cancel synchronization') ?></a></div>
<div class="hideWhenSyncing">
<a href="javascript:offlineDownloadStart()">
- <?php echo __('Start synchronization') ?></a></div>
+ <?php echo __('Synchronize') ?></a></div>
<div class="hideWhenSyncing"><a href="javascript:offlineClearData()">
- <?php echo __('Remove offline data') ?></a></div>
+ <?php echo __('Remove stored data') ?></a></div>
<div><a href="javascript:gotoOffline()">
<?php echo __('Go offline') ?></a></div>
</div>