Bug 62294 - Implement the ability to add a prefix or suffix when inserting a quotation

This commit is contained in:
Artur
2025-11-20 19:12:18 +03:00
parent 920a10dc34
commit f7b6ece57b
9 changed files with 77 additions and 19 deletions

View File

@ -106,6 +106,10 @@
<div id="SyncDataDiv" class="flexCol">
<button id="synchronizeBtn" class="button control btn-text-default i18n">Synchronize</button>
</div>
<div id="prefixSuffixDiv">
<input id="prefixField" autocomplete="off" class="form-control i18n" type="text" placeholder="Prefix" />
<input id="suffixField" autocomplete="off" class="form-control i18n" type="text" placeholder="Suffix" />
</div>
<div id="styleWrapper">
<div class="label">
<label for="styleSelect" class="i18n">Style</label>
@ -206,9 +210,9 @@
</div>
<div id="div_temp" class="hidden"></div>
<script src="scripts/zotero-environment.js"></script>
<script src="scripts/zotero-api-checker.js"></script>
<script src="scripts/zotero.js"></script>
<script src="scripts/zotero/zotero-environment.js"></script>
<script src="scripts/zotero/zotero-api-checker.js"></script>
<script src="scripts/zotero/zotero.js"></script>
<script src="scripts/code.js"></script>
</body>
</html>

View File

@ -200,6 +200,16 @@ input[type="text"] {
margin: 0px 0px 15px 8px;
}
#prefixSuffixDiv {
display: flex;
gap: 8px;
margin-bottom: 8px;
margin-left: 8px;
}
#prefixSuffixDiv input[type="text"] {
width: 50%;
}
#styleWrapper {
display: flex;

View File

@ -40,7 +40,7 @@ function CitationDocService(
/** @type {number} */
this._repeatTimeout;
/**
* @type {{ updateItems: (arg0: string[]) => void; makeCitationCluster: (arg0: SuppressAuthor[]) => string; makeBibliography: () => any[][]; } | null}
* @type {{ updateItems: (arg0: string[]) => void; makeCitationCluster: (arg0: InfoForCitationCluster[]) => string; makeBibliography: () => any[][]; } | null}
*/
this._formatter = null;
}
@ -315,7 +315,7 @@ CitationDocService.prototype.updateAddinFields = function (fields) {
);
field.Content = supSubPositions.text;
});*/
console.log("updateAddinFields", fields);
//console.log("updateAddinFields", fields);
return new Promise(function (resolve) {
window.Asc.plugin.executeMethod("UpdateAddinFields", [fields], resolve);
}) /*.then(function () {

View File

@ -16,7 +16,7 @@
*
*/
/// <reference path="./zotero.js" />
/// <reference path="./zotero/zotero.js" />
/// <reference path="./csl/citation/citation.js" />
/// <reference path="./csl/styles/styles-manager.js" />
@ -440,7 +440,6 @@
const promises = [];
const selectedGroup = getSelectedGroup();
console.log(selectedGroup);
return sdk.getUserGroups().then(function (userGroups) {
let groups = [];
@ -1003,6 +1002,28 @@
});
};
/**
* @returns {string}
*/
function getPrefix() {
const prefixInput = document.getElementById("prefixField");
if (prefixInput && prefixInput.value) {
return prefixInput.value;
}
return "";
}
/**
* @returns {string}
*/
function getSuffix() {
const suffixInput = document.getElementById("suffixField");
if (suffixInput && suffixInput.value) {
return suffixInput.value;
}
return "";
}
function displaySearchItems(append, res, err, isGroup, showNotFound) {
var holder = elements.docsHolder;
@ -1269,7 +1290,7 @@
cslCitation = new CSLCitation(keysL.length, citationID);
cslCitation.fillFromObject(citationObject);
keysL = cslCitation.getSuppressAuthors();
keysL = cslCitation.getInfoForCitationCluster();
elements.tempDiv.innerHTML = formatter.makeCitationCluster(keysL);
field["Content"] = elements.tempDiv.innerText;
if (bSyncronize && cslCitation) {
@ -1447,9 +1468,19 @@
return;
}
const prefix = getPrefix();
const suffix = getSuffix();
var cslCitation = new CSLCitation(CSLCitationStorage.size, "");
for (var citationID in selected.items) {
var item = convertToCSL(selected.items[citationID]);
if (prefix !== "") {
item.prefix = prefix;
}
if (suffix !== "") {
item.suffix = suffix;
}
cslCitation.fillFromObject(item);
}
@ -1470,6 +1501,7 @@
var bUpdateItems = false;
var keys = [];
var keysL = [];
cslCitation.getCitationItems().forEach(function(item) {
if (!CSLCitationStorage.has(item.id)) {
@ -1477,7 +1509,7 @@
}
CSLCitationStorage.set(item.id, item);
keys.push(item.id);
keysL.push(item.getSuppressAuthor());
keysL.push(item.getInfoForCitationCluster());
});
try {
@ -1503,7 +1535,7 @@
// TODO есть проблема, что в плагине мы индексы обновили, а вот в документе нет (по идее надо обновить и индексы в документе перед вставкой)
// но тогда у нас уедет селект и новое поле вставится не там, поэтому пока обновлять приходится в конце
// такая же проблем с вставкой библиографии (при обнолении индексов в плагине надо бы их обновлять и в документе тоже)
return updateCslItems(true, true, false, false);
// return updateCslItems(true, true, false, false);
});
} catch (e) {

View File

@ -74,13 +74,21 @@ CitationItem.prototype.fillFromObject = function (itemObject) {
};
/**
* @returns {SuppressAuthor}
* @returns {InfoForCitationCluster}
*/
CitationItem.prototype.getSuppressAuthor = function () {
return {
CitationItem.prototype.getInfoForCitationCluster = function () {
/** @type {InfoForCitationCluster} */
let info = {
id: this.id,
"suppress-author": this._suppressAuthor,
};
if (this._prefix) {
info.prefix = this._prefix;
}
if (this._suffix) {
info.suffix = this._suffix;
}
return info;
};
CitationItem.prototype.getItemData = function () {
@ -258,6 +266,8 @@ CitationItem.prototype.toFlatJSON = function (index) {
) {
oldItem.groupID = String(this._itemData.getCustomProperty("groupID"));
}
if (this._prefix !== undefined) oldItem.prefix = this._prefix;
if (this._suffix !== undefined) oldItem.suffix = this._suffix;
return oldItem;
};

View File

@ -2,9 +2,11 @@
/// <reference path="./citation-item.js" />
/**
* @typedef {Object} SuppressAuthor
* @typedef {Object} InfoForCitationCluster
* @property {string|number} id
* @property {boolean} `suppress-author`
* @property {string} [prefix]
* @property {string} [suffix]
*/
/**
@ -200,11 +202,11 @@ CSLCitation.prototype.getCitationItems = function () {
/**
*
* @returns {Array<SuppressAuthor>}
* @returns {Array<InfoForCitationCluster>}
*/
CSLCitation.prototype.getSuppressAuthors = function () {
CSLCitation.prototype.getInfoForCitationCluster = function () {
return this._citationItems.map(function (item) {
return item.getSuppressAuthor();
return item.getInfoForCitationCluster();
}, this);
};

View File

@ -1,5 +1,5 @@
// @ts-check
/// <reference path="./types-global.js" />
/// <reference path="../types-global.js" />
/// <reference path="./zotero.js" />
/// <reference path="./zotero-environment.js" />

View File

@ -17,7 +17,7 @@
*/
// @ts-check
/// <reference path="./types-global.js" />
/// <reference path="../types-global.js" />
/// <reference path="./zotero-environment.js" />
/**