Getting more information about citations before inserting them into a page

This commit is contained in:
Artur
2025-10-27 18:00:11 +03:00
parent cb47baa8c9
commit f5b693dc88

View File

@ -1160,7 +1160,7 @@
updateAllOrAddBib(bUpadteAll, bPastBib, bSyncronize);
if (bPastLink) {
formatInsertLink();
insertSelectedCitations();
}
};
@ -1226,7 +1226,7 @@
});
};
function formatInsertLink() {
function insertSelectedCitations() {
if (!selectedStyle) {
showError(getMessage("Style is not selected"));
return;
@ -1236,14 +1236,25 @@
return;
}
var bUpdateItems = false;
var keys = [];
var keysL = [];
var cslCitation = new CSLCitation(CSLCitationStorage.size, "");
for (var citationID in selected.items) {
var item = convertToCSL(selected.items[citationID]);
cslCitation.fillFromObject(item);
}
return getSelectedInJsonFormat().then(function(items) {
items.forEach(function(item) {
cslCitation.fillFromObject(item);
});
return formatInsertLink(cslCitation);
});
}
function formatInsertLink(cslCitation) {
var bUpdateItems = false;
var keys = [];
var keysL = [];
cslCitation.getCitationItems().forEach(function(item) {
if (!CSLCitationStorage.has(item.id)) {
bUpdateItems = true;
@ -1302,6 +1313,61 @@
};
function getSelectedInJsonFormat() {
var arrUsrItems = [];
var arrGroupsItems = {};
for (var citationID in selected.items) {
var item = selected.items[citationID];
var userID = item["userID"];
var groupID = item["groupID"];
if (userID) {
arrUsrItems.push(item.id);
} else if (groupID) {
if (!arrGroupsItems[groupID]) {
arrGroupsItems[groupID] = [];
}
arrGroupsItems[groupID].push(item.id);
}
}
var promises = [];
if (arrUsrItems.length) {
promises.push(
sdk.getItems(null, arrUsrItems, 'json')
.then(function(res) {
var items = ( res.items || [] );
return items
})
.catch(function(err) {
console.error(err);
})
);
}
for (var groupID in arrGroupsItems) {
if (Object.hasOwnProperty.call(arrGroupsItems, groupID)) {
promises.push(
sdk.groups(null, groupID, arrGroupsItems[groupID], 'json')
.then(function(res) {
var items = ( res.items || [] );
return items
})
.catch(function(err) {
console.error(err);
})
);
}
}
return Promise.all(promises).then(function(res) {
var items = [];
res.forEach(function(resItems) {
items = items.concat(resItems);
});
return items;
});
};
function synchronizeData() {
// form an array for request (one array for user and other for groups)
// todo now we should make full update (because when we make refresh, we check fields into the document). Fix it in new version (when we change refreshing and updating processes)