Sync error icon and tooltip display

This commit is contained in:
Dan Stillman 2008-07-01 00:44:52 +00:00
parent 7c4bc05193
commit 68f56c48e4
4 changed files with 47 additions and 20 deletions

View File

@ -307,7 +307,7 @@
<toolbarbutton id="zotero-tb-sync" tooltip="_child" <toolbarbutton id="zotero-tb-sync" tooltip="_child"
oncommand="Zotero.Sync.Server.sync()"> oncommand="Zotero.Sync.Server.sync()">
<tooltip <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 --> noautohide="true"><!-- localize -->
<label value="Sync with Zotero Server"/> <label value="Sync with Zotero Server"/>
<label id="zotero-last-sync-time"/> <label id="zotero-last-sync-time"/>

View File

@ -378,8 +378,7 @@ Zotero.Sync.Server = new function () {
this.logout = logout; this.logout = logout;
this.setSyncTimeout = setSyncTimeout; this.setSyncTimeout = setSyncTimeout;
this.clearSyncTimeout = clearSyncTimeout; this.clearSyncTimeout = clearSyncTimeout;
this.startSyncAnimation = startSyncAnimation; this.setSyncIcon = setSyncIcon;
this.stopSyncAnimation = stopSyncAnimation;
this.__defineGetter__('username', function () { this.__defineGetter__('username', function () {
return Zotero.Prefs.get('sync.server.username'); return Zotero.Prefs.get('sync.server.username');
@ -456,6 +455,12 @@ Zotero.Sync.Server = new function () {
this.__defineSetter__("lastLocalSyncTime", function (val) { this.__defineSetter__("lastLocalSyncTime", function (val) {
Zotero.DB.query("REPLACE INTO version VALUES ('lastlocalsync', ?)", { int: 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.nextLocalSyncDate = false;
this.apiVersion = 1; this.apiVersion = 1;
@ -467,14 +472,14 @@ Zotero.Sync.Server = new function () {
var _serverURL = ZOTERO_CONFIG.SYNC_URL; var _serverURL = ZOTERO_CONFIG.SYNC_URL;
var _apiVersionComponent = "version=" + this.apiVersion;
var _maxAttempts = 3; var _maxAttempts = 3;
var _attempts = _maxAttempts; var _attempts = _maxAttempts;
var _syncInProgress; var _syncInProgress;
var _autoSyncTimer;
var _apiVersionComponent = "version=" + this.apiVersion;
var _sessionID; var _sessionID;
var _sessionLock; var _sessionLock;
var _lastSyncError;
var _autoSyncTimer;
function init() { function init() {
@ -537,7 +542,7 @@ Zotero.Sync.Server = new function () {
function sync() { function sync() {
Zotero.Sync.Server.clearSyncTimeout(); Zotero.Sync.Server.clearSyncTimeout();
Zotero.Sync.Server.startSyncAnimation(); Zotero.Sync.Server.setSyncIcon('animate');
if (_attempts < 0) { if (_attempts < 0) {
_error('Too many attempts in Zotero.Sync.Server.sync()'); _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()'); _error('No session available in Zotero.Sync.Server.unlock()');
} }
var syncInProgress = _syncInProgress;
var url = _serverURL + "unlock"; var url = _serverURL + "unlock";
var body = _apiVersionComponent var body = _apiVersionComponent
+ '&' + Zotero.Sync.Server.sessionIDComponent; + '&' + Zotero.Sync.Server.sessionIDComponent;
@ -856,7 +863,11 @@ Zotero.Sync.Server = new function () {
callback(); 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() { 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"] var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
.getService(Components.interfaces.nsIWindowMediator); .getService(Components.interfaces.nsIWindowMediator);
var win = wm.getMostRecentWindow('navigator:browser'); var win = wm.getMostRecentWindow('navigator:browser');
win.document.getElementById('zotero-tb-sync').setAttribute('animate', 'true'); win.document.getElementById('zotero-tb-sync').setAttribute('status', status);
}
function stopSyncAnimation() {
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');
} }
@ -1075,8 +1090,14 @@ Zotero.Sync.Server = new function () {
Zotero.Sync.Server.unlock() 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); throw(e);
} }
} }

Binary file not shown.

After

Width:  |  Height:  |  Size: 843 B

View File

@ -194,13 +194,19 @@
#zotero-tb-sync { #zotero-tb-sync {
margin-top: -2px; margin-top: -2px;
margin-left: -2px; margin-left: -2px;
margin-right: -2px;
list-style-image: url(chrome://zotero/skin/arrow_rotate_static.png); 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); 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 #zotero-tb-sync #zotero-last-sync-time
{ {
color: gray; color: gray;