diff --git a/chrome/chromeFiles/content/scholar/addCitationDialog.js b/chrome/chromeFiles/content/scholar/addCitationDialog.js new file mode 100644 index 000000000..48f26204e --- /dev/null +++ b/chrome/chromeFiles/content/scholar/addCitationDialog.js @@ -0,0 +1,143 @@ +/* + Zotero + Copyright (C) 2006 Center for History and New Media, George Mason University, Fairfax, VA + http://chnm.gmu.edu/ +*/ + +var Scholar_Citation_Dialog = new function () { + var _itemLocators = new Object(); + var _itemLocatorTypes = new Object(); + var _multipleSourcesOn = false; + var _lastSelected = null; + + this.load = load; + this.toggleMultipleSources = toggleMultipleSources; + this.treeItemSelected = treeItemSelected; + this.listItemSelected = listItemSelected; + this.addCitation = addCitation; + this.deleteCitation = deleteCitation; + this.accept = accept; + + function load() { + document.getElementById("multiple-sources-button").label = Scholar.getString("citation.multipleSources"); + + // load (from selectItemsDialog.js) + doLoad(); + } + + function toggleMultipleSources() { + if(_multipleSourcesOn) { + document.getElementById("multiple-sources").hidden = true; + document.getElementById("add-citation-dialog").width = "600"; + document.getElementById("multiple-sources-button").label = Scholar.getString("citation.multipleSources"); + window.sizeToContent(); + window.moveTo((window.screenX+75), window.screenY); + } else { + document.getElementById("multiple-sources").hidden = undefined; + document.getElementById("add-citation-dialog").width = "750"; + document.getElementById("multiple-sources-button").label = Scholar.getString("citation.singleSource"); + window.sizeToContent(); + window.moveTo((window.screenX-75), window.screenY); + } + + _multipleSourcesOn = !_multipleSourcesOn; + } + + function treeItemSelected() { + if(_multipleSourcesOn) { + // get selected item (from selectItemsDialog.js) + var item = getSelectedItems(true); + + // if item has already been added, disable add button + document.getElementById("citation-add").disabled = (!item.length || _itemLocators[item[0]] != undefined ? true : false); + } + } + + function listItemSelected() { + var pagesBox = document.getElementById("item-locator"); + var locatorTypeBox = document.getElementById("item-locator-type"); + if(_lastSelected) { + _itemLocators[_lastSelected.value] = pagesBox.value; + _itemLocatorTypes[_lastSelected.value] = locatorTypeBox.selectedIndex; + } + + var selectedListItem = document.getElementById("citation-list").getSelectedItem(0); + + if(selectedListItem) { + document.getElementById("citation-delete").disabled = pagesBox.disabled = locatorTypeBox.disabled = false; + pagesBox.value = _itemLocators[selectedListItem.value]; + locatorTypeBox.selectedIndex = _itemLocatorTypes[selectedListItem.value]; + } else { + document.getElementById("citation-delete").disabled = pagesBox.disabled = locatorTypeBox.disabled = true; + pagesBox.value = ""; + locatorTypeBox.selectedIndex = -1; + } + + _lastSelected = selectedListItem; + } + + function addCitation() { + // get selected item (from selectItemsDialog.js) + var item = getSelectedItems(); + item = item[0]; + var itemID = item.getID(); + + // add to list + var itemNode = document.createElement("listitem"); + itemNode.setAttribute("value", itemID); + itemNode.setAttribute("label", item.getField("title")); + itemNode.setAttribute("class", "listitem-iconic"); + itemNode.setAttribute("image", "chrome://scholar/skin/treeitem-"+Scholar.ItemTypes.getName(item.getType())+".png"); + document.getElementById("citation-list").appendChild(itemNode); + + // don't let someone select it again + document.getElementById("citation-add").disabled = true; + + // flag + _itemLocators[itemID] = document.getElementById("tree-locator").value; + _itemLocatorTypes[itemID] = document.getElementById("tree-locator-type").selectedIndex; + document.getElementById("tree-locator").value = ""; + } + + function deleteCitation() { + var citationList = document.getElementById("citation-list"); + var selectedListItem = citationList.getSelectedItem(0); + + // remove from _itemLocators + _itemLocators[selectedListItem.value] = _itemLocatorType[selectedListItem.value] = undefined; + + // remove from list + citationList.removeChild(selectedListItem); + } + + function accept() { + var io = window.arguments[0]; + if(_multipleSourcesOn) { + treeItemSelected(); // store locator info + + var citationList = document.getElementById("citation-list"); + var listLength = citationList.childNodes.length; + + if(listLength) { + io.items = new Array(); + io.locatorTypes = new Array(); + io.locators = new Array(); + + for(var i=0; i + + + + + + + + + +