fixes #1668, Items added in multiple mode not recognized unless visible (twice)

fix Accept button issue by using getAttribute() rather than id property, but also scroll to newly inserted citation, since it's probably the desirable behavior
This commit is contained in:
Simon Kornblith 2010-06-18 18:19:52 +00:00
parent 8026fcd14d
commit 4556ea3f10

View file

@ -298,8 +298,8 @@ var Zotero_Citation_Dialog = new function () {
*/ */
function add() { function add() {
var item = itemsView.getSelectedItems()[0]; // treeview from selectItemsDialog.js var item = itemsView.getSelectedItems()[0]; // treeview from selectItemsDialog.js
_itemSelected(item.getID()); _itemSelected(item.id);
_addItem(item); _citationList.ensureElementIsVisible(_addItem(item));
// don't let someone select it again // don't let someone select it again
document.getElementById("add").disabled = true; document.getElementById("add").disabled = true;
@ -307,7 +307,7 @@ var Zotero_Citation_Dialog = new function () {
// allow user to press OK // allow user to press OK
_updateAccept(); _updateAccept();
_updatePreview(); _updatePreview();
sortCitation(); sortCitation(item.id);
} }
/* /*
@ -338,7 +338,7 @@ var Zotero_Citation_Dialog = new function () {
/* /*
* Sorts the list of citations * Sorts the list of citations
*/ */
function sortCitation() { function sortCitation(scrollToItemID) {
if(!_sortCheckbox) return; if(!_sortCheckbox) return;
if(!_sortCheckbox.checked) { if(!_sortCheckbox.checked) {
io.citation.properties.unsorted = true; io.citation.properties.unsorted = true;
@ -357,12 +357,16 @@ var Zotero_Citation_Dialog = new function () {
io.previewFunction(); io.previewFunction();
// add items back to list // add items back to list
var scrollTo = null;
for(var i=0; i<io.citation.sortedItems.length; i++) { for(var i=0; i<io.citation.sortedItems.length; i++) {
var itemID = io.citation.sortedItems[i][0].id; var itemID = io.citation.sortedItems[i][0].id;
var item = Zotero.Items.get(itemID); var item = Zotero.Items.get(itemID);
_addItem(item); var itemNode = _addItem(item);
if(itemID == selectedItemID) _citationList.selectedIndex = i; if(itemID == selectedItemID) _citationList.selectedIndex = i;
if(scrollToItemID && itemID == scrollToItemID) scrollTo = itemNode;
} }
if(scrollTo) _citationList.ensureElementIsVisible(scrollTo);
} }
/* /*
@ -542,12 +546,12 @@ var Zotero_Citation_Dialog = new function () {
var locatorTypeElements = document.getElementById("label").getElementsByTagName("menuitem"); var locatorTypeElements = document.getElementById("label").getElementsByTagName("menuitem");
if(_multipleSourcesOn) { if(_multipleSourcesOn) {
_itemSelected(); // store locator info _itemSelected(); // store locator info
var listLength = _citationList.childNodes.length; var listLength = _citationList.getRowCount();
var citationItems = new Array(); var citationItems = new Array();
if(listLength) { if(listLength) {
// generate citationItems // generate citationItems
for(var i=0; i<listLength; i++) { for(var i=0; i<listLength; i++) {
var itemID = _citationList.childNodes[i].value; var itemID = _citationList.getItemAtIndex(i).getAttribute("value");
var citationItem = _itemData[itemID]; var citationItem = _itemData[itemID];
citationItem.id = itemID; citationItem.id = itemID;
@ -584,11 +588,12 @@ var Zotero_Citation_Dialog = new function () {
*/ */
function _addItem(item) { function _addItem(item) {
var itemNode = document.createElement("listitem"); var itemNode = document.createElement("listitem");
itemNode.setAttribute("value", item.getID()); itemNode.setAttribute("value", item.id);
itemNode.setAttribute("label", item.getField("title")); itemNode.setAttribute("label", item.getField("title"));
itemNode.setAttribute("class", "listitem-iconic"); itemNode.setAttribute("class", "listitem-iconic");
itemNode.setAttribute("image", item.getImageSrc()); itemNode.setAttribute("image", item.getImageSrc());
_citationList.appendChild(itemNode); _citationList.appendChild(itemNode);
return itemNode;
} }
/* /*