www

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | Submodules | README | LICENSE

selectitems.js (3477B)


      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 /**
     27  * @namespace Singleton to interface with the browser when ingesting data
     28  */
     29 var Zotero_Ingester_Interface_SelectItems = function() {}
     30 
     31 //////////////////////////////////////////////////////////////////////////////
     32 //
     33 // Public Zotero_Ingester_Interface_SelectItems methods
     34 //
     35 //////////////////////////////////////////////////////////////////////////////
     36 
     37 /**
     38  * Presents items to select in the select box. Assumes window.arguments[0].dataIn is an object with
     39  * URLs as keys and descriptions as values
     40  */
     41 Zotero_Ingester_Interface_SelectItems.init = function() {
     42 	// Set font size from pref
     43 	var sbc = document.getElementById('zotero-select-items-container');
     44 	Zotero.setFontSize(sbc);
     45 	
     46 	this.io = window.arguments[0];
     47 	var listbox = document.getElementById("zotero-selectitems-links");
     48 	
     49 	for(var i in this.io.dataIn) {	// we could use a tree for this if we wanted to
     50 		var item = this.io.dataIn[i];
     51 
     52 		var title, checked = false;
     53 		if(item && typeof(item) == "object" && item.title !== undefined) {
     54 			title = item.title;
     55 			checked = !!item.checked;
     56 		} else {
     57 			title = item;
     58 		}
     59 
     60 		var itemNode = document.createElement("listitem");
     61 		itemNode.setAttribute("type", "checkbox");
     62 		itemNode.setAttribute("value", i);
     63 		itemNode.setAttribute("label", title);
     64 		itemNode.setAttribute("checked", checked);
     65 		listbox.appendChild(itemNode);
     66 	}
     67 	
     68 	// Check item if there is only one
     69 	if (listbox.itemCount === 1) {
     70 		listbox.getItemAtIndex(0).setAttribute("checked", true);
     71 	}
     72 }
     73 
     74 /**
     75  * Selects or deselects all items
     76  * @param {Boolean} deselect If true, deselect all items instead of selecting all items
     77  */
     78 Zotero_Ingester_Interface_SelectItems.selectAll = function(deselect) {
     79 	var listbox = document.getElementById("zotero-selectitems-links");
     80 	for (var i=0; i<listbox.childNodes.length; i++){
     81 		listbox.childNodes[i].setAttribute('checked', !deselect);
     82 	}
     83 }
     84 
     85 /**
     86  * Called when "OK" button is pressed to populate window.arguments[0].dataOut with selected items
     87  */
     88 Zotero_Ingester_Interface_SelectItems.acceptSelection = function() {
     89 	var listbox = document.getElementById("zotero-selectitems-links");
     90 	
     91 	var returnObject = false;
     92 	this.io.dataOut = new Object();
     93 	
     94 	// collect scrapeURLList from listbox
     95 	for(var i=0; i<listbox.childNodes.length; i++) {
     96 		var itemNode = listbox.childNodes[i];
     97 		if(itemNode.getAttribute("checked") == "true") {
     98 			this.io.dataOut[itemNode.getAttribute("value")] = itemNode.getAttribute("label");
     99 			returnObject = true;
    100 		}
    101 	}
    102 	
    103 	if(!returnObject) this.io.dataOut = null;
    104 }