www

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

reportInterface.js (2371B)


      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 var Zotero_Report_Interface = new function() {
     28 	/*
     29 	 * Load a report for the currently selected collection
     30 	 */
     31 	this.loadCollectionReport = function (event) {
     32 		var sortColumn = ZoteroPane_Local.getSortField();
     33 		var sortDirection = ZoteroPane_Local.getSortDirection();
     34 		var queryString = '?sort=' + sortColumn
     35 			+ '&direction=' + (sortDirection == 'ascending' ? 'asc' : 'desc');
     36 		
     37 		var url = 'zotero://report/';
     38 		
     39 		var source = ZoteroPane_Local.getSelectedCollection();
     40 		if (!source) {
     41 			source = ZoteroPane_Local.getSelectedSavedSearch();
     42 		}
     43 		if (!source) {
     44 			throw new Error('No collection currently selected');
     45 		}
     46 		
     47 		url += Zotero.API.getLibraryPrefix(source.libraryID) + '/';
     48 		
     49 		if (source instanceof Zotero.Collection) {
     50 			url += 'collections/' + source.key;
     51 		}
     52 		else {
     53 			url += 'searches/' + source.key;
     54 		}
     55 		
     56 		url += '/items' + queryString;
     57 		
     58 		ZoteroPane_Local.loadURI(url, event);
     59 	}
     60 	
     61 	
     62 	/*
     63 	 * Load a report for the currently selected items
     64 	 */
     65 	this.loadItemReport = function (event) {
     66 		var libraryID = ZoteroPane_Local.getSelectedLibraryID();
     67 		var items = ZoteroPane_Local.getSelectedItems();
     68 		
     69 		if (!items || !items.length) {
     70 			throw new Error('No items currently selected');
     71 		}
     72 		
     73 		var url = 'zotero://report/' + Zotero.API.getLibraryPrefix(libraryID) + '/items'
     74 			+ '?itemKey=' + items.map(item => item.key).join(',');
     75 		ZoteroPane_Local.loadURI(url, event);
     76 	}
     77 }