www

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | Submodules | README | LICENSE

commit d48adde7edd08bc0ac3311c5b743c080fb2e27d3
parent 50941734b8253deb1d89d833672706b80bcef91c
Author: Dan Stillman <dstillman@zotero.org>
Date:   Tue,  1 Jul 2008 00:44:52 +0000

Sync error icon and tooltip display


Diffstat:
Mchrome/content/zotero/overlay.xul | 2+-
Mchrome/content/zotero/xpcom/sync.js | 57+++++++++++++++++++++++++++++++++++++++------------------
Achrome/skin/default/zotero/arrow_rotate_error.png | 0
Mchrome/skin/default/zotero/overlay.css | 8+++++++-
4 files changed, 47 insertions(+), 20 deletions(-)

diff --git a/chrome/content/zotero/overlay.xul b/chrome/content/zotero/overlay.xul @@ -307,7 +307,7 @@ <toolbarbutton id="zotero-tb-sync" tooltip="_child" oncommand="Zotero.Sync.Server.sync()"> <tooltip - onpopupshowing="this.firstChild.nextSibling.value = 'Last sync: ' + (Zotero.Sync.Server.lastLocalSyncTime ? new Date(Zotero.Sync.Server.lastLocalSyncTime * 1000).toLocaleString() : 'Not yet synced')" + onpopupshowing="if (Zotero.Sync.Server.lastSyncError) { this.firstChild.nextSibling.value = 'Last error: ' + Zotero.Sync.Server.lastSyncError; return; } this.firstChild.nextSibling.value = 'Last sync: ' + (Zotero.Sync.Server.lastLocalSyncTime ? new Date(Zotero.Sync.Server.lastLocalSyncTime * 1000).toLocaleString() : 'Not yet synced')" noautohide="true"><!-- localize --> <label value="Sync with Zotero Server"/> <label id="zotero-last-sync-time"/> diff --git a/chrome/content/zotero/xpcom/sync.js b/chrome/content/zotero/xpcom/sync.js @@ -378,8 +378,7 @@ Zotero.Sync.Server = new function () { this.logout = logout; this.setSyncTimeout = setSyncTimeout; this.clearSyncTimeout = clearSyncTimeout; - this.startSyncAnimation = startSyncAnimation; - this.stopSyncAnimation = stopSyncAnimation; + this.setSyncIcon = setSyncIcon; this.__defineGetter__('username', function () { return Zotero.Prefs.get('sync.server.username'); @@ -456,6 +455,12 @@ Zotero.Sync.Server = new function () { this.__defineSetter__("lastLocalSyncTime", function (val) { Zotero.DB.query("REPLACE INTO version VALUES ('lastlocalsync', ?)", { int: val }); }); + this.__defineGetter__("lastSyncError", function () { + return _lastSyncError; + }); + this.__defineSetter__("lastSyncError", function (val) { + _lastSyncError = val ? val : ''; + }); this.nextLocalSyncDate = false; this.apiVersion = 1; @@ -467,14 +472,14 @@ Zotero.Sync.Server = new function () { var _serverURL = ZOTERO_CONFIG.SYNC_URL; + var _apiVersionComponent = "version=" + this.apiVersion; var _maxAttempts = 3; var _attempts = _maxAttempts; var _syncInProgress; - - var _autoSyncTimer; - var _apiVersionComponent = "version=" + this.apiVersion; var _sessionID; var _sessionLock; + var _lastSyncError; + var _autoSyncTimer; function init() { @@ -537,7 +542,7 @@ Zotero.Sync.Server = new function () { function sync() { Zotero.Sync.Server.clearSyncTimeout(); - Zotero.Sync.Server.startSyncAnimation(); + Zotero.Sync.Server.setSyncIcon('animate'); if (_attempts < 0) { _error('Too many attempts in Zotero.Sync.Server.sync()'); @@ -831,6 +836,8 @@ Zotero.Sync.Server = new function () { _error('No session available in Zotero.Sync.Server.unlock()'); } + var syncInProgress = _syncInProgress; + var url = _serverURL + "unlock"; var body = _apiVersionComponent + '&' + Zotero.Sync.Server.sessionIDComponent; @@ -856,7 +863,11 @@ Zotero.Sync.Server = new function () { callback(); } - Zotero.Sync.Server.stopSyncAnimation(); + // Reset sync icon and last error + if (syncInProgress) { + Zotero.Sync.Server.lastSyncError = ''; + Zotero.Sync.Server.setSyncIcon(); + } }); } @@ -1021,19 +1032,23 @@ Zotero.Sync.Server = new function () { } - function startSyncAnimation() { - var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"] - .getService(Components.interfaces.nsIWindowMediator); - var win = wm.getMostRecentWindow('navigator:browser'); - win.document.getElementById('zotero-tb-sync').setAttribute('animate', 'true'); - } - - - function stopSyncAnimation() { + function setSyncIcon(status) { + status = status ? status : ''; + + switch (status) { + case '': + case 'animate': + case 'error': + break; + + default: + throw ("Invalid sync icon status '" + status + "' in Zotero.Sync.Server.setSyncIcon()"); + } + var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"] .getService(Components.interfaces.nsIWindowMediator); var win = wm.getMostRecentWindow('navigator:browser'); - win.document.getElementById('zotero-tb-sync').removeAttribute('animate'); + win.document.getElementById('zotero-tb-sync').setAttribute('status', status); } @@ -1075,8 +1090,14 @@ Zotero.Sync.Server = new function () { Zotero.Sync.Server.unlock() } - Zotero.Sync.Server.stopSyncAnimation(); + Zotero.Sync.Server.setSyncIcon('error'); + if (e.name) { + Zotero.Sync.Server.lastSyncError = e.name; + } + else { + Zotero.Sync.Server.lastSyncError = e; + } throw(e); } } diff --git a/chrome/skin/default/zotero/arrow_rotate_error.png b/chrome/skin/default/zotero/arrow_rotate_error.png Binary files differ. diff --git a/chrome/skin/default/zotero/overlay.css b/chrome/skin/default/zotero/overlay.css @@ -194,13 +194,19 @@ #zotero-tb-sync { margin-top: -2px; margin-left: -2px; + margin-right: -2px; list-style-image: url(chrome://zotero/skin/arrow_rotate_static.png); } -#zotero-tb-sync[animate=true] { +#zotero-tb-sync[status=animate] { list-style-image: url(chrome://zotero/skin/arrow_rotate_animated.png); } +#zotero-tb-sync[status=error] { + list-style-image: url(chrome://zotero/skin/arrow_rotate_error.png); +} + + #zotero-tb-sync #zotero-last-sync-time { color: gray;