From 9efd7cc07d025c4d61b276736233b770c2dcaee9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adomas=20Ven=C4=8Dkauskas?= Date: Wed, 3 Jul 2019 15:18:39 +0300 Subject: [PATCH] Retracted item citation warning changes Allows the user to suppress the item retraction warnings from the citation dialog and makes the retraction warning suppression global. See #1710 --- .../zotero/integration/addCitationDialog.js | 45 +++++++++------- .../content/zotero/integration/quickFormat.js | 53 +++++++++++-------- chrome/content/zotero/xpcom/integration.js | 9 ++-- 3 files changed, 63 insertions(+), 44 deletions(-) diff --git a/chrome/content/zotero/integration/addCitationDialog.js b/chrome/content/zotero/integration/addCitationDialog.js index 5b57832522..ecf1e80946 100644 --- a/chrome/content/zotero/integration/addCitationDialog.js +++ b/chrome/content/zotero/integration/addCitationDialog.js @@ -604,28 +604,33 @@ var Zotero_Citation_Dialog = new function () { if (io.citation.citationItems.length) { for (let item of io.citation.citationItems) { - if (Zotero.Retractions.isRetracted({id: parseInt(item.id)})) { - var ps = Services.prompt; - var buttonFlags = ps.BUTTON_POS_0 * ps.BUTTON_TITLE_IS_STRING - + ps.BUTTON_POS_1 * ps.BUTTON_TITLE_CANCEL - + ps.BUTTON_POS_2 * ps.BUTTON_TITLE_IS_STRING; - var result = ps.confirmEx(null, - Zotero.getString('general.warning'), - Zotero.getString('retraction.citeWarning.text1') + '\n\n' - + Zotero.getString('retraction.citeWarning.text2'), - buttonFlags, - Zotero.getString('general.continue'), - null, - Zotero.getString('pane.items.showItemInLibrary'), - null, {}); - if (result > 0) { - if (result == 2) { - _showItemInLibrary(parseInt(item.id)); + if (Zotero.Retractions.isRetracted({ id: parseInt(item.id) })) { + if (Zotero.Retractions.shouldShowCitationWarning({ id: parseInt(item.id) })) { + var ps = Services.prompt; + var buttonFlags = ps.BUTTON_POS_0 * ps.BUTTON_TITLE_IS_STRING + + ps.BUTTON_POS_1 * ps.BUTTON_TITLE_CANCEL + + ps.BUTTON_POS_2 * ps.BUTTON_TITLE_IS_STRING; + var checkbox = { value: false }; + var result = ps.confirmEx(null, + Zotero.getString('general.warning'), + Zotero.getString('retraction.citeWarning.text1') + '\n\n' + + Zotero.getString('retraction.citeWarning.text2'), + buttonFlags, + Zotero.getString('general.continue'), + null, + Zotero.getString('pane.items.showItemInLibrary'), + Zotero.getString('retraction.citationWarning.dontWarn'), checkbox); + if (result > 0) { + if (result == 2) { + _showItemInLibrary(parseInt(item.id)); + } + return false; } - return false; + if (checkbox.value) { + Zotero.Retractions.disableCitationWarningsForItem({ id: parseInt(item.id) }); + } + item.ignoreRetraction = true; } - item.ignoreRetraction = true; - break; } } } diff --git a/chrome/content/zotero/integration/quickFormat.js b/chrome/content/zotero/integration/quickFormat.js index 1a332ac531..95b0a1af94 100644 --- a/chrome/content/zotero/integration/quickFormat.js +++ b/chrome/content/zotero/integration/quickFormat.js @@ -721,28 +721,39 @@ var Zotero_QuickFormat = new function () { citationItem.uris = item.cslURIs; citationItem.itemData = item.cslItemData; } - else if (Zotero.Retractions.isRetracted({id: parseInt(citationItem.id)})) { - referencePanel.hidden = true; - var ps = Services.prompt; - var buttonFlags = ps.BUTTON_POS_0 * ps.BUTTON_TITLE_IS_STRING - + ps.BUTTON_POS_1 * ps.BUTTON_TITLE_CANCEL - + ps.BUTTON_POS_2 * ps.BUTTON_TITLE_IS_STRING; - var result = ps.confirmEx(null, - Zotero.getString('general.warning'), - Zotero.getString('retraction.citeWarning.text1') + '\n\n' - + Zotero.getString('retraction.citeWarning.text2'), - buttonFlags, - Zotero.getString('general.continue'), - null, - Zotero.getString('pane.items.showItemInLibrary'), - null, {}); - referencePanel.hidden = false; - if (result > 0) { - if (result == 2) { - Zotero_QuickFormat.showInLibrary(parseInt(citationItem.id)); + else if (Zotero.Retractions.isRetracted({ id: parseInt(citationItem.id) })) { + citationItem.id = parseInt(citationItem.id); + if (Zotero.Retractions.shouldShowCitationWarning(citationItem)) { + referencePanel.hidden = true; + var ps = Services.prompt; + var buttonFlags = ps.BUTTON_POS_0 * ps.BUTTON_TITLE_IS_STRING + + ps.BUTTON_POS_1 * ps.BUTTON_TITLE_CANCEL + + ps.BUTTON_POS_2 * ps.BUTTON_TITLE_IS_STRING; + var checkbox = { value: false }; + var result = ps.confirmEx(null, + Zotero.getString('general.warning'), + Zotero.getString('retraction.citeWarning.text1') + '\n\n' + + Zotero.getString('retraction.citeWarning.text2'), + buttonFlags, + Zotero.getString('general.continue'), + null, + Zotero.getString('pane.items.showItemInLibrary'), + Zotero.getString('retraction.citationWarning.dontWarn'), checkbox); + referencePanel.hidden = false; + if (result > 0) { + if (result == 2) { + Zotero_QuickFormat.showInLibrary(parseInt(citationItem.id)); + } + return false; } - return false; - } else { + else { + if (checkbox.value) { + Zotero.Retractions.disableCitationWarningsForItem(citationItem); + } + citationItem.ignoreRetraction = true; + } + } + else { citationItem.ignoreRetraction = true; } } diff --git a/chrome/content/zotero/xpcom/integration.js b/chrome/content/zotero/xpcom/integration.js index baa6661921..5845a737a3 100644 --- a/chrome/content/zotero/xpcom/integration.js +++ b/chrome/content/zotero/xpcom/integration.js @@ -1145,7 +1145,7 @@ Zotero.Integration.Fields.prototype._updateDocument = async function(forceCitati // If we're looking to reset the text even if it matches previous text (i.e. style change) if (forceCitations == FORCE_CITATIONS_RESET_TEXT // Or metadata has changed thus changing the formatted citation - || ((citation.properties.formattedCitation !== formattedCitation + || ((formattedCitation && citation.properties.formattedCitation !== formattedCitation // Or plaintext has changed and user does not want to keep the change || plaintextChanged) && !citation.properties.dontUpdate)) { @@ -1944,6 +1944,9 @@ Zotero.Integration.Session.prototype.handleRetractedItems = async function () { const dealWithRetracted = (citedItem, inLibrary) => { let dontPromptAgain = this.promptForRetraction(citedItem, inLibrary); if (dontPromptAgain) { + if (citedItem.id) { + Zotero.Retractions.disableCitationWarningsForItem(citedItem); + } let itemID = citedItem.id || citedItem.cslItemID; for (let citation of this.citationsByItemID[itemID]) { for (let item of citation.citationItems) { @@ -1970,9 +1973,9 @@ Zotero.Integration.Session.prototype.handleRetractedItems = async function () { } } } - var retractedIndices = await Zotero.Retractions.getRetractionsFromJSON( + var retractedIndices = await Promise.race(Zotero.Retractions.getRetractionsFromJSON( embeddedZoteroItems.map(item => item.toJSON()) - ); + ), Zotero.Promise.delay(1000).then(() => [])); for (let index of retractedIndices) { dealWithRetracted(embeddedZoteroItems[index]); }