Show an error when a user attempts to use an invalid style

This commit is contained in:
Simon Kornblith 2011-05-30 05:25:13 +00:00
parent 9fa94d442d
commit 2ce712df70
2 changed files with 19 additions and 12 deletions

View file

@ -665,7 +665,6 @@ Zotero.Integration.Document = function(app, doc) {
Zotero.Integration.Document.prototype._createNewSession = function(data) {
data.sessionID = Zotero.randomString();
var session = Zotero.Integration.sessions[data.sessionID] = new Zotero.Integration.Session();
session.setData(data);
return session;
}
@ -684,7 +683,9 @@ Zotero.Integration.Document.prototype._getSession = function(require, dontRunSet
throw new Zotero.Integration.DisplayException("mustInsertCitation");
} else {
// Set doc prefs if no data string yet
this._session = this._createNewSession(new Zotero.Integration.DocumentData());
var data = new Zotero.Integration.DocumentData();
this._session = this._createNewSession(data);
this._session.setData(data);
if(dontRunSetDocPrefs) return false;
Zotero.Integration.activate();
@ -715,14 +716,19 @@ Zotero.Integration.Document.prototype._getSession = function(require, dontRunSet
this._session = Zotero.Integration.sessions[data.sessionID];
} else {
this._session = this._createNewSession(data);
// make sure style is defined
if(!this._session.style) {
Zotero.Integration.activate();
try {
this._session.setDocPrefs(this._app.primaryFieldType, this._app.secondaryFieldType);
} finally {
this._doc.activate();
try {
this._session.setData(data);
} catch(e) {
// make sure style is defined
if(e instanceof Zotero.Integration.DisplayException && e.name === "invalidStyle") {
Zotero.Integration.activate();
try {
this._session.setDocPrefs(this._app.primaryFieldType, this._app.secondaryFieldType);
} finally {
this._doc.activate();
}
} else {
throw e;
}
}
this._doc.setDocumentData(this._session.data.serializeXML());
@ -1278,9 +1284,9 @@ Zotero.Integration.Session.prototype.setData = function(data) {
this.styleClass = getStyle.class;
this.dateModified = new Object();
} catch(e) {
Zotero.debug(e)
Zotero.logError(e);
data.style.styleID = undefined;
return false;
throw new Zotero.Integration.DisplayException("invalidStyle");
}
return true;

View file

@ -587,6 +587,7 @@ integration.error.cannotInsertHere = Zotero fields cannot be inserted here.
integration.error.notInCitation = You must place the cursor in a Zotero citation to edit it.
integration.error.noBibliography = The current bibliographic style does not define a bibliography. If you wish to add a bibliography, please choose another style.
integration.error.deletePipe = The pipe that Zotero uses to communicate with the word processor could not be initialized. Would you like Zotero to attempt to correct this error? You will be prompted for your password.
integration.error.invalidStyle = The style you have selected does not appear to be valid. If you have created this style yourself, please ensure that it passes validation as described at http://zotero.org/support/dev/citation_styles. Alternatively, try selecting another style.
integration.replace = Replace this Zotero field?
integration.missingItem.single = This item no longer exists in your Zotero database. Do you want to select a substitute item?