closes #971, Add support for secondary key
This commit is contained in:
parent
a8c367156d
commit
1da2221d40
|
@ -665,7 +665,7 @@ Zotero.CSL.prototype.formatBibliography = function(itemSet, format) {
|
|||
if(item == undefined) continue;
|
||||
|
||||
// try to get custom bibliography
|
||||
var string = item.getProperty("bibliography-"+format);
|
||||
var string = item.getProperty("bibliography-"+(format == "Integration" ? "RTF" : format));
|
||||
if(!string) {
|
||||
string = new Zotero.CSL.FormattedString(context, format);
|
||||
this._processElements(item, context.layout, string, context);
|
||||
|
@ -1441,8 +1441,8 @@ Zotero.CSL.prototype._compareItem = function(a, b, context, cache) {
|
|||
var sortA = [];
|
||||
var sortB = [];
|
||||
|
||||
var aID = a.getID();
|
||||
var bID = b.getID();
|
||||
var aID = a.id;
|
||||
var bID = b.id;
|
||||
|
||||
// author
|
||||
if(context.sort.key.length()) {
|
||||
|
@ -1863,7 +1863,7 @@ Zotero.CSL.Global = new function() {
|
|||
Zotero.CSL.CitationItem = function(item) {
|
||||
if(item) {
|
||||
this.item = item;
|
||||
this.itemID = item.getID();
|
||||
this.itemID = item.id;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1967,6 +1967,9 @@ Zotero.CSL.Item = function(item) {
|
|||
throw "Zotero.CSL.Item called to wrap a non-item";
|
||||
}
|
||||
|
||||
this.id = this.zoteroItem.id;
|
||||
this.key = this.zoteroItem.key;
|
||||
|
||||
// don't return URL or accessed information for journal articles if a
|
||||
// pages field exists
|
||||
var itemType = Zotero.ItemTypes.getName(this.zoteroItem.itemTypeID);
|
||||
|
@ -1980,6 +1983,18 @@ Zotero.CSL.Item = function(item) {
|
|||
this._refreshItem();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns some identifier for the item. Used to create citations. In Zotero,
|
||||
* this is the item ID
|
||||
*
|
||||
* @deprecated
|
||||
**/
|
||||
Zotero.CSL.Item.prototype.getID = function() {
|
||||
Zotero.debug("Zotero.CSL.Item.getID() deprecated; use Zotero.CSL.Item.id");
|
||||
return this.zoteroItem.id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Refreshes item if it has been modified
|
||||
*/
|
||||
|
@ -1993,14 +2008,6 @@ Zotero.CSL.Item.prototype._refreshItem = function() {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Returns some identifier for the item. Used to create citations. In Zotero,
|
||||
* this is the item ID
|
||||
*/
|
||||
Zotero.CSL.Item.prototype.getID = function() {
|
||||
return this.zoteroItem.getID();
|
||||
}
|
||||
/*
|
||||
* Mappings for names
|
||||
*/
|
||||
|
@ -2442,6 +2449,7 @@ Zotero.CSL.ItemSet = function(items, csl) {
|
|||
|
||||
this.items = [];
|
||||
this.itemsById = {};
|
||||
this.itemsByKey = {};
|
||||
|
||||
// add items
|
||||
this.add(items);
|
||||
|
@ -2465,9 +2473,14 @@ Zotero.CSL.ItemSet = function(items, csl) {
|
|||
this.resort();
|
||||
}
|
||||
|
||||
/*
|
||||
* Gets CSL.Item objects from an item set using their IDs
|
||||
*/
|
||||
|
||||
/**
|
||||
* Gets CSL.Item objects from an item set using their ids
|
||||
*
|
||||
* @param {Array} ids An array of ids
|
||||
* @return {Array} items An array whose indexes correspond to those of ids, whose values are either
|
||||
* the CSL.Item objects or false
|
||||
**/
|
||||
Zotero.CSL.ItemSet.prototype.getItemsByIds = function(ids) {
|
||||
var items = [];
|
||||
for each(var id in ids) {
|
||||
|
@ -2480,6 +2493,25 @@ Zotero.CSL.ItemSet.prototype.getItemsByIds = function(ids) {
|
|||
return items;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets CSL.Item objects from an item set using their keys
|
||||
*
|
||||
* @param {Array} keys An array of keys
|
||||
* @return {Array} items An array whose indexes correspond to those of keys, whose values are either
|
||||
* the CSL.Item objects or false
|
||||
**/
|
||||
Zotero.CSL.ItemSet.prototype.getItemsByKeys = function(keys) {
|
||||
var items = [];
|
||||
for each(var key in keys) {
|
||||
if(this.itemsByKey[key] != undefined) {
|
||||
items.push(this.itemsByKey[key]);
|
||||
} else {
|
||||
items.push(false);
|
||||
}
|
||||
}
|
||||
return items;
|
||||
}
|
||||
|
||||
/*
|
||||
* Adds items to the given item set; must be passed either CSL.Item
|
||||
* objects or objects that may be wrapped as CSL.Item objects
|
||||
|
@ -2496,7 +2528,8 @@ Zotero.CSL.ItemSet.prototype.add = function(items) {
|
|||
|
||||
newItem.setProperty("index", this.items.length);
|
||||
|
||||
this.itemsById[newItem.getID()] = newItem;
|
||||
this.itemsById[newItem.id] = newItem;
|
||||
this.itemsByKey[newItem.key] = newItem;
|
||||
this.items.push(newItem);
|
||||
newItems.push(newItem);
|
||||
}
|
||||
|
@ -2516,7 +2549,8 @@ Zotero.CSL.ItemSet.prototype.remove = function(items) {
|
|||
} else {
|
||||
var item = this.itemsById[items[i]];
|
||||
}
|
||||
this.itemsById[item.getID()] = undefined;
|
||||
this.itemsById[item.id] = undefined;
|
||||
this.itemsByKey[item.key] = undefined;
|
||||
this.items.splice(this.items.indexOf(item), 1);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -422,9 +422,8 @@ Zotero.Integration.Request = function(xml) {
|
|||
this.status = 200;
|
||||
this.statusText = "OK";
|
||||
} catch(e) {
|
||||
Components.utils.reportError(e);
|
||||
|
||||
Zotero.debug(e);
|
||||
Components.utils.reportError(e);
|
||||
|
||||
// Get a code for this error
|
||||
var code = (e.name ? e.name : "GenericError");
|
||||
|
@ -480,9 +479,6 @@ Zotero.Integration.Request.prototype.initializeSession = function() {
|
|||
}
|
||||
|
||||
this.needPrefs = this.needPrefs || !this._session.setStyle(styleID, preferences);
|
||||
if(this.header.bibliography.length()) {
|
||||
session.loadBibliographyData(Zotero.Utilities.prototype.trim(this.header.bibliography.toString()));
|
||||
}
|
||||
} else {
|
||||
this._session = Zotero.Integration.sessions[this._sessionID];
|
||||
}
|
||||
|
@ -556,8 +552,14 @@ Zotero.Integration.Request.prototype.processCitations = function() {
|
|||
}
|
||||
}
|
||||
|
||||
// load bibliography data here
|
||||
if(this.header.bibliography.length()) {
|
||||
this._session.loadBibliographyData(Zotero.Utilities.prototype.trim(this.header.bibliography.toString()));
|
||||
}
|
||||
|
||||
this._session.updateItemSet();
|
||||
|
||||
// create new citation
|
||||
if(editCitationIndex) {
|
||||
this._session.updateCitations(editCitationIndex-1);
|
||||
var added = this._session.editCitation(editCitationIndex, editCitation);
|
||||
|
@ -572,6 +574,7 @@ Zotero.Integration.Request.prototype.processCitations = function() {
|
|||
}
|
||||
this._session.updateCitations();
|
||||
|
||||
// edit bibliography
|
||||
if(this.body.updateBibliography.@edit.toString()) {
|
||||
this._session.editBibliography();
|
||||
}
|
||||
|
@ -854,9 +857,15 @@ Zotero.Integration.Session.prototype.getCitationField = function(citation) {
|
|||
var citationItems = "";
|
||||
for(var j=0; j<citation.citationItems.length; j++) {
|
||||
var citationItem = "";
|
||||
|
||||
// ensure key is saved
|
||||
if(citation.citationItems[j].key == undefined) {
|
||||
citation.citationItems[j].key = citation.citationItems[j].item.key;
|
||||
}
|
||||
|
||||
for(var k in citation.citationItems[j]) {
|
||||
type = typeof(citation.citationItems[j][k]);
|
||||
if(citation.citationItems[j][k] && Zotero.Integration.Session._acceptableTypes.indexOf(type) !== -1) {
|
||||
if(citation.citationItems[j][k] && k != "itemID" && Zotero.Integration.Session._acceptableTypes.indexOf(type) !== -1) {
|
||||
citationItem += ',"'+k+'":'+Zotero.JSON.serialize(citation.citationItems[j][k]);
|
||||
}
|
||||
}
|
||||
|
@ -927,13 +936,23 @@ Zotero.Integration.Session.prototype.completeCitation = function(object) {
|
|||
for(var i=0; i<object.citationItems.length; i++) {
|
||||
var citationItem = object.citationItems[i];
|
||||
|
||||
var item = this.itemSet.getItemsByIds([citationItem.itemID])[0];
|
||||
var zoteroItem;
|
||||
if(citationItem.key) {
|
||||
var item = this.itemSet.getItemsByKeys([citationItem.key])[0];
|
||||
} else {
|
||||
this.updateItemIDs[citationItem.itemID] = true;
|
||||
var item = this.itemSet.getItemsByIds([citationItem.itemID])[0];
|
||||
}
|
||||
|
||||
// loop through items not in itemSet
|
||||
if(item == false) {
|
||||
item = Zotero.Items.get(citationItem.itemID);
|
||||
if(!item) return false;
|
||||
item = this.itemSet.add([item])[0];
|
||||
if(citationItem.key) {
|
||||
zoteroItem = Zotero.Items.getByKey(citationItem.key);
|
||||
} else {
|
||||
zoteroItem = Zotero.Items.get(citationItem.itemID);
|
||||
}
|
||||
if(!zoteroItem) return false;
|
||||
item = this.itemSet.add([zoteroItem])[0];
|
||||
|
||||
this.dateModified[citationItem.itemID] = item.zoteroItem.getField("dateModified", true, true);
|
||||
this.updateItemIDs[citationItem.itemID] = true;
|
||||
|
@ -941,6 +960,7 @@ Zotero.Integration.Session.prototype.completeCitation = function(object) {
|
|||
}
|
||||
|
||||
citationItem.item = item;
|
||||
if(!citationItem.itemID) citationItem.itemID = item.id;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -1182,7 +1202,7 @@ Zotero.Integration.Session.prototype.updateItemSet = function() {
|
|||
|
||||
// see if old items were deleted or changed
|
||||
for each(var item in this.itemSet.items) {
|
||||
var itemID = item.getID();
|
||||
var itemID = item.id;
|
||||
|
||||
// see if items were removed
|
||||
if(!this.citationsByItemID[itemID] && !this.uncitedItems[itemID]) {
|
||||
|
@ -1222,7 +1242,7 @@ Zotero.Integration.Session.prototype.sortItemSet = function() {
|
|||
|
||||
// add to list of updated item IDs
|
||||
for each(var item in citationChanged) {
|
||||
this.updateItemIDs[item.getID()] = true;
|
||||
this.updateItemIDs[item.id] = true;
|
||||
this.bibliographyHasChanged = true;
|
||||
}
|
||||
}
|
||||
|
@ -1364,11 +1384,16 @@ Zotero.Integration.Session.prototype.loadBibliographyData = function(json) {
|
|||
// set custom bibliography entries
|
||||
if(documentData.custom) {
|
||||
for(var itemID in documentData.custom) {
|
||||
var item = this.itemSet.getItemsByIds([itemID])[0];
|
||||
if(typeof(itemID) == "string") { // key
|
||||
var item = this.itemSet.getItemsByKeys([itemID])[0];
|
||||
} else { // item ID
|
||||
this.bibliographyDataHasChanged = true;
|
||||
var item = this.itemSet.getItemsByIds([itemID])[0];
|
||||
}
|
||||
if (!item) {
|
||||
continue;
|
||||
}
|
||||
item.setProperty("bibliography-Integration", documentData.custom[itemID]);
|
||||
item.setProperty("bibliography-RTF", documentData.custom[itemID]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1377,14 +1402,42 @@ Zotero.Integration.Session.prototype.loadBibliographyData = function(json) {
|
|||
* adds items in this.uncitedItems to itemSet, if they are not already there
|
||||
*/
|
||||
Zotero.Integration.Session.prototype.loadUncitedItems = function() {
|
||||
var needConversion = false;
|
||||
|
||||
for(var itemID in this.uncitedItems) {
|
||||
// skip "undefined"
|
||||
if(!this.uncitedItems[itemID]) continue;
|
||||
|
||||
// if not yet in item set, add to item set
|
||||
var item = this.itemSet.getItemsByIds([itemID])[0];
|
||||
if(typeof(itemID) == "string") { // key
|
||||
var item = this.itemSet.getItemsByKeys([itemID])[0];
|
||||
itemID = Zotero.Items.getByKey(itemID);
|
||||
} else { // item ID
|
||||
needConversion = true;
|
||||
var item = this.itemSet.getItemsByIds([itemID])[0];
|
||||
}
|
||||
if(!item) this.itemSet.add([itemID])[0];
|
||||
}
|
||||
|
||||
// need a second loop to convert, since we need to modify this.uncitedItems
|
||||
if(needConversion) {
|
||||
this.bibliographyDataHasChanged = true;
|
||||
|
||||
oldUncitedItems = this.uncitedItems;
|
||||
this.uncitedItems = {};
|
||||
for(var itemID in oldUncitedItems) {
|
||||
if(!oldUncitedItems[itemID]) continue;
|
||||
|
||||
if(typeof(itemID) == "string") { // key
|
||||
this.uncitedItems[itemID] = true;
|
||||
} else { // itemID
|
||||
var item = Zotero.Items.get(itemID);
|
||||
if(item) {
|
||||
this.uncitedItems[item.key] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -1394,9 +1447,11 @@ Zotero.Integration.Session.prototype.getBibliographyData = function() {
|
|||
var bibliographyData = {};
|
||||
|
||||
// add uncited if there is anything
|
||||
for(var item in this.uncitedItems) {
|
||||
bibliographyData.uncited = this.uncitedItems;
|
||||
break;
|
||||
for each(var item in this.uncitedItems) {
|
||||
if(item) {
|
||||
bibliographyData.uncited = this.uncitedItems;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// look for custom bibliography entries
|
||||
|
@ -1404,10 +1459,8 @@ Zotero.Integration.Session.prototype.getBibliographyData = function() {
|
|||
for(var i=0; i<this.itemSet.items.length; i++) {
|
||||
var custom = this.itemSet.items[i].getProperty("bibliography-Integration");
|
||||
if(custom !== "") {
|
||||
var itemID = this.itemSet.items[i].getID();
|
||||
|
||||
if(!bibliographyData.custom) bibliographyData.custom = {};
|
||||
bibliographyData.custom[itemID] = custom;
|
||||
bibliographyData.custom[this.itemSet.items[i].key] = custom;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1431,14 +1484,14 @@ Zotero.Integration.Session.BibliographyEditInterface.prototype.getItemSet = func
|
|||
}
|
||||
|
||||
Zotero.Integration.Session.BibliographyEditInterface.prototype.isCited = function(item) {
|
||||
if(this.session.citationsByItemID[item.getID()]) return true;
|
||||
if(this.session.citationsByItemID[item.id]) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
Zotero.Integration.Session.BibliographyEditInterface.prototype.add = function(item) {
|
||||
// create new item
|
||||
this.session.itemSet.add([item]);
|
||||
this.session.uncitedItems[item.getID()] = true;
|
||||
this.session.uncitedItems[item.key] = true;
|
||||
this.session.sortItemSet();
|
||||
}
|
||||
|
||||
|
@ -1448,7 +1501,7 @@ Zotero.Integration.Session.BibliographyEditInterface.prototype.remove = function
|
|||
this.session.sortItemSet();
|
||||
|
||||
// delete citations if necessary
|
||||
var itemID = item.getID();
|
||||
var itemID = item.id;
|
||||
if(this.session.citationsByItemID[itemID]) {
|
||||
for(var j=0; j<this.session.citationsByItemID[itemID].length; j++) {
|
||||
var citation = this.session.citationsByItemID[itemID][j];
|
||||
|
@ -1458,7 +1511,7 @@ Zotero.Integration.Session.BibliographyEditInterface.prototype.remove = function
|
|||
}
|
||||
|
||||
// delete uncited if neceessary
|
||||
if(this.session.uncitedItems[itemID]) this.session.uncitedItems[itemID] = undefined;
|
||||
if(this.session.uncitedItems[item.key]) this.session.uncitedItems[item.key] = undefined;
|
||||
}
|
||||
|
||||
Zotero.Integration.Session.BibliographyEditInterface.prototype.preview = function(item) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user