selectItemsDialog.js (4352B)
1 /* 2 ***** BEGIN LICENSE BLOCK ***** 3 4 Copyright © 2009 Center for History and New Media 5 George Mason University, Fairfax, Virginia, USA 6 http://zotero.org 7 8 This file is part of Zotero. 9 10 Zotero is free software: you can redistribute it and/or modify 11 it under the terms of the GNU Affero General Public License as published by 12 the Free Software Foundation, either version 3 of the License, or 13 (at your option) any later version. 14 15 Zotero is distributed in the hope that it will be useful, 16 but WITHOUT ANY WARRANTY; without even the implied warranty of 17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 GNU Affero General Public License for more details. 19 20 You should have received a copy of the GNU Affero General Public License 21 along with Zotero. If not, see <http://www.gnu.org/licenses/>. 22 23 ***** END LICENSE BLOCK ***** 24 */ 25 26 var itemsView; 27 var collectionsView; 28 var io; 29 var connectionSelectedDeferred; 30 31 /* 32 * window takes two arguments: 33 * io - used for input/output (dataOut is list of item IDs) 34 * sourcesOnly - whether only sources should be shown in the window 35 */ 36 var doLoad = Zotero.Promise.coroutine(function* () { 37 // Set font size from pref 38 var sbc = document.getElementById('zotero-select-items-container'); 39 Zotero.setFontSize(sbc); 40 41 io = window.arguments[0]; 42 if(io.wrappedJSObject) io = io.wrappedJSObject; 43 if(io.addBorder) document.getElementsByTagName("dialog")[0].style.border = "1px solid black"; 44 if(io.singleSelection) document.getElementById("zotero-items-tree").setAttribute("seltype", "single"); 45 46 setItemsPaneMessage(Zotero.getString('pane.items.loading')); 47 48 collectionsView = new Zotero.CollectionTreeView(); 49 collectionsView.hideSources = ['duplicates', 'trash', 'feeds']; 50 document.getElementById('zotero-collections-tree').view = collectionsView; 51 52 yield collectionsView.waitForLoad(); 53 54 connectionSelectedDeferred = Zotero.Promise.defer(); 55 yield connectionSelectedDeferred.promise; 56 57 if (io.select) { 58 yield collectionsView.selectItem(io.select); 59 } 60 61 Zotero.updateQuickSearchBox(document); 62 }); 63 64 function doUnload() 65 { 66 collectionsView.unregister(); 67 if(itemsView) 68 itemsView.unregister(); 69 } 70 71 var onCollectionSelected = Zotero.Promise.coroutine(function* () 72 { 73 if(itemsView) 74 itemsView.unregister(); 75 76 if(collectionsView.selection.count == 1 && collectionsView.selection.currentIndex != -1) 77 { 78 var collectionTreeRow = collectionsView.getRow(collectionsView.selection.currentIndex); 79 collectionTreeRow.setSearch(''); 80 Zotero.Prefs.set('lastViewedFolder', collectionTreeRow.id); 81 82 setItemsPaneMessage(Zotero.getString('pane.items.loading')); 83 84 // Load library data if necessary 85 var library = Zotero.Libraries.get(collectionTreeRow.ref.libraryID); 86 if (!library.getDataLoaded('item')) { 87 Zotero.debug("Waiting for items to load for library " + library.libraryID); 88 yield library.waitForDataLoad('item'); 89 } 90 91 // Create items list and wait for it to load 92 itemsView = new Zotero.ItemTreeView(collectionTreeRow); 93 itemsView.sourcesOnly = !!window.arguments[1]; 94 document.getElementById('zotero-items-tree').view = itemsView; 95 yield itemsView.waitForLoad(); 96 97 clearItemsPaneMessage(); 98 99 connectionSelectedDeferred.resolve(); 100 collectionsView.runListeners('select'); 101 } 102 }); 103 104 function onSearch() 105 { 106 if(itemsView) 107 { 108 var searchVal = document.getElementById('zotero-tb-search').value; 109 itemsView.setFilter('search', searchVal); 110 } 111 } 112 113 function onItemSelected() 114 { 115 itemsView.runListeners('select'); 116 } 117 118 function setItemsPaneMessage(content) { 119 var elem = document.getElementById('zotero-items-pane-message-box'); 120 elem.textContent = ''; 121 if (typeof content == 'string') { 122 let contentParts = content.split("\n\n"); 123 for (let part of contentParts) { 124 var desc = document.createElement('description'); 125 desc.appendChild(document.createTextNode(part)); 126 elem.appendChild(desc); 127 } 128 } 129 else { 130 elem.appendChild(content); 131 } 132 document.getElementById('zotero-items-pane-content').selectedIndex = 1; 133 } 134 135 136 function clearItemsPaneMessage() { 137 var box = document.getElementById('zotero-items-pane-message-box'); 138 document.getElementById('zotero-items-pane-content').selectedIndex = 0; 139 } 140 141 function doAccept() 142 { 143 io.dataOut = itemsView.getSelectedItems(true); 144 }