- Eliminate some error messages in translate.js

- Zotero.ItemFields.isValidForType() should not throw on error
This commit is contained in:
Simon Kornblith 2011-07-03 08:28:30 +00:00
parent ca8c7ba584
commit f5af708995
2 changed files with 8 additions and 3 deletions

View file

@ -115,7 +115,7 @@ Zotero.ItemFields = new function() {
this.isValidForType = function(fieldIdOrName, typeIdOrName) { this.isValidForType = function(fieldIdOrName, typeIdOrName) {
// mimics itemFields.js // mimics itemFields.js
if(!Zotero.Connector_Types["fields"][fieldIdOrName] if(!Zotero.Connector_Types["fields"][fieldIdOrName]
|| !Zotero.Connector_Types["itemTypes"][typeIdOrName]) throw "Invalid field or type ID"; || !Zotero.Connector_Types["itemTypes"][typeIdOrName]) return false;
return Zotero.Connector_Types["itemTypes"][typeIdOrName].fields.indexOf( return Zotero.Connector_Types["itemTypes"][typeIdOrName].fields.indexOf(
Zotero.Connector_Types["fields"][fieldIdOrName].id) !== -1; Zotero.Connector_Types["fields"][fieldIdOrName].id) !== -1;
@ -123,7 +123,7 @@ Zotero.ItemFields = new function() {
this.getFieldIDFromTypeAndBase = function(itemType, baseField) { this.getFieldIDFromTypeAndBase = function(itemType, baseField) {
if(!Zotero.Connector_Types["fields"][baseField] if(!Zotero.Connector_Types["fields"][baseField]
|| !Zotero.Connector_Types["itemTypes"][itemType]) throw "Invalid field or type ID"; || !Zotero.Connector_Types["itemTypes"][itemType]) throw new Error("Invalid field or type ID");
// get as ID // get as ID
baseField = Zotero.Connector_Types["fields"][baseField].id; baseField = Zotero.Connector_Types["fields"][baseField].id;

View file

@ -465,6 +465,7 @@ Zotero.Translate.Sandbox = {
} }
// create short title // create short title
Zotero.debug("item type is "+item.itemType);
if(item.shortTitle === undefined && Zotero.Utilities.fieldIsValidForType("shortTitle", item.itemType)) { if(item.shortTitle === undefined && Zotero.Utilities.fieldIsValidForType("shortTitle", item.itemType)) {
// only set if changes have been made // only set if changes have been made
var setShortTitle = false; var setShortTitle = false;
@ -793,7 +794,7 @@ Zotero.Translate.Base.prototype = {
*/ */
"getTranslators":function(getAllTranslators) { "getTranslators":function(getAllTranslators) {
// do not allow simultaneous instances of getTranslators // do not allow simultaneous instances of getTranslators
if(this._currentState == "detect") throw new Error("getTranslators: detection is already running"); if(this._currentState === "detect") throw new Error("getTranslators: detection is already running");
this._currentState = "detect"; this._currentState = "detect";
this._getAllTranslators = getAllTranslators; this._getAllTranslators = getAllTranslators;
this._getTranslatorsGetPotentialTranslators(); this._getTranslatorsGetPotentialTranslators();
@ -1426,6 +1427,8 @@ Zotero.Translate.Import.prototype._getTranslatorsGetPotentialTranslators = funct
*/ */
Zotero.Translate.Import.prototype.getTranslators = function() { Zotero.Translate.Import.prototype.getTranslators = function() {
if(!this._string && !this.location) { if(!this._string && !this.location) {
if(this._currentState === "detect") throw new Error("getTranslators: detection is already running");
this._currentState = "detect";
this._foundTranslators = Zotero.Translators.getAllForType(this.type); this._foundTranslators = Zotero.Translators.getAllForType(this.type);
this._potentialTranslators = []; this._potentialTranslators = [];
this.complete(true); this.complete(true);
@ -1562,6 +1565,8 @@ Zotero.Translate.Export.prototype.complete = Zotero.Translate.Import.prototype.c
* Overload {@link Zotero.Translate.Base#getTranslators} to return all translators immediately * Overload {@link Zotero.Translate.Base#getTranslators} to return all translators immediately
*/ */
Zotero.Translate.Export.prototype.getTranslators = function() { Zotero.Translate.Export.prototype.getTranslators = function() {
if(this._currentState === "detect") throw new Error("getTranslators: detection is already running");
this._currentState = "detect";
this._foundTranslators = Zotero.Translators.getAllForType(this.type); this._foundTranslators = Zotero.Translators.getAllForType(this.type);
this._potentialTranslators = []; this._potentialTranslators = [];
this.complete(true); this.complete(true);