diff --git a/chrome/content/zotero/preferences/preferences_export.js b/chrome/content/zotero/preferences/preferences_export.js index af6d7b0ac3..e66b0cbaf9 100644 --- a/chrome/content/zotero/preferences/preferences_export.js +++ b/chrome/content/zotero/preferences/preferences_export.js @@ -146,7 +146,7 @@ Zotero_Preferences.Export = { }, - showQuickCopySiteEditor: function (index) { + showQuickCopySiteEditor: Zotero.Promise.coroutine(function* (index) { var treechildren = document.getElementById('quickCopy-siteSettings-rows'); if (index != undefined && index > -1 && index < treechildren.childNodes.length) { @@ -156,29 +156,28 @@ Zotero_Preferences.Export = { var asHTML = treerow.childNodes[2].getAttribute('label') != ''; } - Zotero.QuickCopy.getSettingFromFormattedName(format) - .then(function (format) { - if (asHTML) { - format = format.replace('bibliography=', 'bibliography/html='); - } - - var io = {domain: domain, format: format, ok: false}; - window.openDialog('chrome://zotero/content/preferences/quickCopySiteEditor.xul', "zotero-preferences-quickCopySiteEditor", "chrome, modal", io); - - if (!io.ok) { - return; - } - - if (domain && domain != io.domain) { - Zotero.DB.query("DELETE FROM settings WHERE setting='quickCopySite' AND key=?", [domain]); - } - - Zotero.DB.query("REPLACE INTO settings VALUES ('quickCopySite', ?, ?)", [io.domain, io.format]); - - this.refreshQuickCopySiteList(); - }.bind(this)) - .done(); - }, + var format = yield Zotero.QuickCopy.getSettingFromFormattedName(format); + if (asHTML) { + format = format.replace('bibliography=', 'bibliography/html='); + } + + var io = {domain: domain, format: format, ok: false}; + window.openDialog('chrome://zotero/content/preferences/quickCopySiteEditor.xul', "zotero-preferences-quickCopySiteEditor", "chrome, modal", io); + + if (!io.ok) { + return; + } + + if (domain && domain != io.domain) { + yield Zotero.DB.queryAsync("DELETE FROM settings WHERE setting='quickCopySite' AND key=?", [domain]); + } + + yield Zotero.DB.queryAsync("REPLACE INTO settings VALUES ('quickCopySite', ?, ?)", [io.domain, io.format]); + + yield Zotero.QuickCopy.loadSiteSettings(); + + yield this.refreshQuickCopySiteList(); + }), refreshQuickCopySiteList: Zotero.Promise.coroutine(function* () { @@ -200,29 +199,28 @@ Zotero_Preferences.Export = { domainCell.setAttribute('label', siteData[i].domainPath); - yield Zotero.QuickCopy.getFormattedNameFromSetting(siteData[i].format) - .then(function (formatted) { - formatCell.setAttribute('label', formatted); - var copyAsHTML = Zotero.QuickCopy.getContentType(siteData[i].format) == 'html'; - HTMLCell.setAttribute('label', copyAsHTML ? ' ✓ ' : ''); - - treerow.appendChild(domainCell); - treerow.appendChild(formatCell); - treerow.appendChild(HTMLCell); - treeitem.appendChild(treerow); - treechildren.appendChild(treeitem); - }); + var formatted = yield Zotero.QuickCopy.getFormattedNameFromSetting(siteData[i].format); + formatCell.setAttribute('label', formatted); + var copyAsHTML = Zotero.QuickCopy.getContentType(siteData[i].format) == 'html'; + HTMLCell.setAttribute('label', copyAsHTML ? ' ✓ ' : ''); + + treerow.appendChild(domainCell); + treerow.appendChild(formatCell); + treerow.appendChild(HTMLCell); + treeitem.appendChild(treerow); + treechildren.appendChild(treeitem); } }), - deleteSelectedQuickCopySite: function () { + deleteSelectedQuickCopySite: Zotero.Promise.coroutine(function* () { var tree = document.getElementById('quickCopy-siteSettings'); var treeitem = tree.lastChild.childNodes[tree.currentIndex]; var domainPath = treeitem.firstChild.firstChild.getAttribute('label'); - Zotero.DB.query("DELETE FROM settings WHERE setting='quickCopySite' AND key=?", [domainPath]); + yield Zotero.DB.queryAsync("DELETE FROM settings WHERE setting='quickCopySite' AND key=?", [domainPath]); + yield Zotero.QuickCopy.loadSiteSettings(); this.refreshQuickCopySiteList(); - }, + }), updateQuickCopyInstructions: function () { diff --git a/chrome/content/zotero/xpcom/data/cachedTypes.js b/chrome/content/zotero/xpcom/data/cachedTypes.js index 1cf5c2fb44..1c076877f0 100644 --- a/chrome/content/zotero/xpcom/data/cachedTypes.js +++ b/chrome/content/zotero/xpcom/data/cachedTypes.js @@ -167,14 +167,13 @@ Zotero.CreatorTypes = new function() { this.getTypesForItemType = getTypesForItemType; this.isValidForItemType = isValidForItemType; - this.getPrimaryIDForType = getPrimaryIDForType; this._typeDesc = 'creator type'; this._idCol = 'creatorTypeID'; this._nameCol = 'creatorType'; this._table = 'creatorTypes'; - var _primaryIDCache = {}; + var _primaryIDCache; var _hasCreatorTypeCache = {}; var _creatorTypesByItemType = {}; var _isValidForItemType = {}; @@ -200,6 +199,16 @@ Zotero.CreatorTypes = new function() { name: row.name }); } + + // Load primary creator type ids + _primaryIDCache = {}; + var sql = "SELECT itemTypeID, creatorTypeID FROM itemTypeCreatorTypes " + + "WHERE primaryField=1"; + var rows = yield Zotero.DB.queryAsync(sql); + for (let i=0; i