- Open alert window if sync icon is clicked with missing or incorrect sync credentials, with button to open Sync preferences pane
Alert doesn't pop up on background sync, and auto-syncs triggered by edits are now considered background syncs (like the auto-sync when opening the Zotero pane), which means they won't pop up the conflict resolution window either.
This commit is contained in:
parent
a19802cb9d
commit
bd69d272c5
2 changed files with 69 additions and 7 deletions
|
@ -12,6 +12,8 @@ Zotero.Error = function (message, error) {
|
||||||
Zotero.Error.ERROR_UNKNOWN = 0;
|
Zotero.Error.ERROR_UNKNOWN = 0;
|
||||||
Zotero.Error.ERROR_MISSING_OBJECT = 1;
|
Zotero.Error.ERROR_MISSING_OBJECT = 1;
|
||||||
Zotero.Error.ERROR_FULL_SYNC_REQUIRED = 2;
|
Zotero.Error.ERROR_FULL_SYNC_REQUIRED = 2;
|
||||||
|
Zotero.Error.ERROR_SYNC_USERNAME_NOT_SET = 3;
|
||||||
|
Zotero.Error.ERROR_INVALID_SYNC_LOGIN = 4;
|
||||||
|
|
||||||
Zotero.Error.prototype.toString = function () {
|
Zotero.Error.prototype.toString = function () {
|
||||||
return this.message;
|
return this.message;
|
||||||
|
|
|
@ -535,7 +535,7 @@ Zotero.Sync.Runner = new function () {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_autoSyncTimer) {
|
if (_autoSyncTimer) {
|
||||||
Zotero.debug("CANCELLING");
|
Zotero.debug("Cancelling auto-sync timer");
|
||||||
_autoSyncTimer.cancel();
|
_autoSyncTimer.cancel();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -570,6 +570,16 @@ Zotero.Sync.Runner = new function () {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
if (Zotero.Sync.Storage.syncInProgress) {
|
||||||
|
Zotero.debug('Storage sync in progress -- not setting auto-sync timeout', 4);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Zotero.Sync.Server.syncInProgress) {
|
||||||
|
Zotero.debug('Sync in progress -- not setting auto-sync timeout', 4);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
Zotero.debug('Setting auto-sync timeout to ' + timeout + ' seconds');
|
Zotero.debug('Setting auto-sync timeout to ' + timeout + ' seconds');
|
||||||
_autoSyncTimer.initWithCallback(
|
_autoSyncTimer.initWithCallback(
|
||||||
callback, timeout * 1000, Components.interfaces.nsITimer.TYPE_ONE_SHOT
|
callback, timeout * 1000, Components.interfaces.nsITimer.TYPE_ONE_SHOT
|
||||||
|
@ -630,7 +640,7 @@ Zotero.Sync.Runner.EventListener = {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Zotero.Prefs.get('sync.autoSync') && Zotero.Sync.Server.enabled) {
|
if (Zotero.Prefs.get('sync.autoSync') && Zotero.Sync.Server.enabled) {
|
||||||
Zotero.Sync.Runner.setSyncTimeout();
|
Zotero.Sync.Runner.setSyncTimeout(false, false, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -848,13 +858,21 @@ Zotero.Sync.Server = new function () {
|
||||||
var url = _serverURL + "login";
|
var url = _serverURL + "login";
|
||||||
|
|
||||||
var username = Zotero.Sync.Server.username;
|
var username = Zotero.Sync.Server.username;
|
||||||
|
|
||||||
if (!username) {
|
if (!username) {
|
||||||
_error("Username not set in Zotero.Sync.Server.login()");
|
// TODO: localize
|
||||||
|
var e = new Zotero.Error("Username not set", "SYNC_USERNAME_NOT_SET");
|
||||||
|
_error(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
username = encodeURIComponent(Zotero.Sync.Server.username);
|
var password = Zotero.Sync.Server.password;
|
||||||
var password = encodeURIComponent(Zotero.Sync.Server.password);
|
if (!password) {
|
||||||
|
// TODO: localize
|
||||||
|
var e = new Zotero.Error("Password not set", "INVALID_SYNC_LOGIN");
|
||||||
|
_error(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
username = encodeURIComponent(username);
|
||||||
|
password = encodeURIComponent(password);
|
||||||
var body = _apiVersionComponent
|
var body = _apiVersionComponent
|
||||||
+ "&username=" + username
|
+ "&username=" + username
|
||||||
+ "&password=" + password;
|
+ "&password=" + password;
|
||||||
|
@ -866,7 +884,9 @@ Zotero.Sync.Server = new function () {
|
||||||
|
|
||||||
if (response.firstChild.tagName == 'error') {
|
if (response.firstChild.tagName == 'error') {
|
||||||
if (response.firstChild.getAttribute('code') == 'INVALID_LOGIN') {
|
if (response.firstChild.getAttribute('code') == 'INVALID_LOGIN') {
|
||||||
_error('Invalid login/pass');
|
// TODO: localize
|
||||||
|
var e = new Zotero.Error("Invalid login/pass", "INVALID_SYNC_LOGIN");
|
||||||
|
_error(e);
|
||||||
}
|
}
|
||||||
_error(response.firstChild.firstChild.nodeValue);
|
_error(response.firstChild.firstChild.nodeValue);
|
||||||
}
|
}
|
||||||
|
@ -1704,6 +1724,46 @@ Zotero.Sync.Server = new function () {
|
||||||
Zotero.Sync.Runner.sync(background);
|
Zotero.Sync.Runner.sync(background);
|
||||||
}, 1);
|
}, 1);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case Zotero.Error.ERROR_SYNC_USERNAME_NOT_SET:
|
||||||
|
case Zotero.Error.ERROR_INVALID_SYNC_LOGIN:
|
||||||
|
if (Zotero.Sync.Runner.background) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
setTimeout(function () {
|
||||||
|
var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
|
||||||
|
.getService(Components.interfaces.nsIWindowMediator);
|
||||||
|
var win = wm.getMostRecentWindow("navigator:browser");
|
||||||
|
|
||||||
|
var pr = Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
|
||||||
|
.getService(Components.interfaces.nsIPromptService);
|
||||||
|
var buttonFlags = (pr.BUTTON_POS_0) * (pr.BUTTON_TITLE_IS_STRING)
|
||||||
|
+ (pr.BUTTON_POS_1) * (pr.BUTTON_TITLE_CANCEL);
|
||||||
|
// TODO: localize
|
||||||
|
if (e.error == Zotero.Error.ERROR_SYNC_USERNAME_NOT_SET) {
|
||||||
|
var title = "Username Not Set";
|
||||||
|
var msg = "You must enter your zotero.org username and password in the Zotero preferences to sync with the Zotero server."
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
var title = "Invalid Username/Password";
|
||||||
|
var msg = "The Zotero sync server did not accept your username and password.\n\n"
|
||||||
|
+ "Please check that you have entered your zotero.org login information correctly in the Zotero sync preferences.";
|
||||||
|
}
|
||||||
|
var index = pr.confirmEx(
|
||||||
|
win,
|
||||||
|
title,
|
||||||
|
msg,
|
||||||
|
buttonFlags,
|
||||||
|
"Open Sync Preferences",
|
||||||
|
null, null, null, {}
|
||||||
|
);
|
||||||
|
|
||||||
|
if (index == 0) {
|
||||||
|
win.ZoteroPane.openPreferences("zotero-prefpane-sync");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}, 1);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue