www

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

preferences_proxies.js (5900B)


      1 /*
      2     ***** BEGIN LICENSE BLOCK *****
      3     
      4     Copyright © 2006–2013 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 "use strict";
     27 
     28 Zotero_Preferences.Proxies = {
     29 	_proxies: null,
     30 	
     31 	
     32 	init: function () {
     33 		this.refreshProxyList();
     34 		this.updateCheckboxState();
     35 	},
     36 	
     37 	/**
     38 	 * Updates proxy autoRecognize and transparent settings based on checkboxes
     39 	 */
     40 	updateProxyPrefs: function () {
     41 		var transparent = document.getElementById('zotero-proxies-transparent').checked;
     42 		Zotero.Prefs.set("proxies.transparent", transparent);
     43 		Zotero.Prefs.set("proxies.autoRecognize", document.getElementById('zotero-proxies-autoRecognize').checked);	
     44 		Zotero.Prefs.set("proxies.showRedirectNotification", document.getElementById('zotero-proxies-showRedirectNotification').checked);
     45 		Zotero.Prefs.set("proxies.disableByDomainString", document.getElementById('zotero-proxies-disableByDomain-textbox').value);
     46 		Zotero.Prefs.set("proxies.disableByDomain", document.getElementById('zotero-proxies-disableByDomain-checkbox').checked &&
     47 				document.getElementById('zotero-proxies-disableByDomain-textbox').value != "");
     48 		
     49 		Zotero.Proxies.init();
     50 		
     51 		this.updateCheckboxState();
     52 	},
     53 	
     54 	
     55 	updateCheckboxState: function() {
     56 		var transparent = document.getElementById('zotero-proxies-transparent').checked;
     57 
     58 		document.getElementById('proxyTree-add').disabled =
     59 			document.getElementById('proxyTree-delete').disabled =
     60 			document.getElementById('proxyTree').disabled =
     61 			document.getElementById('zotero-proxies-autoRecognize').disabled =
     62 			document.getElementById('zotero-proxies-showRedirectNotification').disabled =
     63 			document.getElementById('zotero-proxies-disableByDomain-checkbox').disabled =
     64 			document.getElementById('zotero-proxies-disableByDomain-textbox').disabled =
     65 				!transparent;
     66 	},
     67 	
     68 	
     69 	/**
     70 	 * Enables UI buttons when proxy is selected
     71 	 */
     72 	enableProxyButtons: function () {
     73 		document.getElementById('proxyTree-edit').disabled = false;
     74 		document.getElementById('proxyTree-delete').disabled = false;
     75 	},
     76 	
     77 	/**
     78 	 * Adds a proxy to the proxy pane
     79 	 */
     80 	showProxyEditor: function (index) {
     81 		if(index == -1) return;
     82 		window.openDialog('chrome://zotero/content/preferences/proxyEditor.xul',
     83 			"zotero-preferences-proxyEditor", "chrome,modal,centerscreen",
     84 			index !== undefined ? this._proxies[index] : null);
     85 		this.refreshProxyList();
     86 	},
     87 	
     88 	
     89 	/**
     90 	 * Deletes the currently selected proxy
     91 	 */
     92 	deleteProxy: function () {
     93 		if(document.getElementById('proxyTree').currentIndex == -1) return;
     94 		this._proxies[document.getElementById('proxyTree').currentIndex].erase();
     95 		this.refreshProxyList();
     96 		document.getElementById('proxyTree-delete').disabled = true;
     97 	},
     98 	
     99 	
    100 	/**
    101 	 * Refreshes the proxy pane
    102 	 */
    103 	refreshProxyList: function () {
    104 		if(!document.getElementById("zotero-prefpane-proxies")) return;
    105 		
    106 		// get and sort proxies
    107 		this._proxies = Zotero.Proxies.proxies.slice();
    108 		for(var i=0; i<this._proxies.length; i++) {
    109 			if(!this._proxies[i].proxyID) {
    110 				this._proxies.splice(i, 1);
    111 				i--;
    112 			}
    113 		}
    114 		this._proxies = this._proxies.sort(function(a, b) {
    115 			if(a.multiHost) {
    116 				if(b.multiHost) {
    117 					if(a.hosts[0] < b.hosts[0]) {
    118 						return -1;
    119 					} else {
    120 						return 1;
    121 					}
    122 				} else {
    123 					return -1;
    124 				}
    125 			} else if(b.multiHost) {
    126 				return 1;
    127 			}
    128 			
    129 			if(a.scheme < b.scheme) {
    130 				return -1;
    131 			} else if(b.scheme > a.scheme) {
    132 				return 1;
    133 			}
    134 			
    135 			return 0;
    136 		});
    137 		
    138 		// erase old children
    139 		var treechildren = document.getElementById('proxyTree-rows');
    140 		while (treechildren.hasChildNodes()) {
    141 			treechildren.removeChild(treechildren.firstChild);
    142 		}
    143 		
    144 		// add proxies to list
    145 		for (var i=0; i<this._proxies.length; i++) {
    146 			var treeitem = document.createElement('treeitem');
    147 			var treerow = document.createElement('treerow');
    148 			var hostnameCell = document.createElement('treecell');
    149 			var schemeCell = document.createElement('treecell');
    150 			
    151 			hostnameCell.setAttribute('label', this._proxies[i].multiHost ? Zotero.getString("proxies.multiSite") : this._proxies[i].hosts[0]);
    152 			schemeCell.setAttribute('label', this._proxies[i].scheme);
    153 			
    154 			treerow.appendChild(hostnameCell);
    155 			treerow.appendChild(schemeCell);
    156 			treeitem.appendChild(treerow);
    157 			treechildren.appendChild(treeitem);
    158 		}
    159 		
    160 		document.getElementById('proxyTree').currentIndex = -1;
    161 		document.getElementById('proxyTree-edit').disabled = true;
    162 		document.getElementById('proxyTree-delete').disabled = true;
    163 		document.getElementById('zotero-proxies-transparent').checked = Zotero.Prefs.get("proxies.transparent");
    164 		document.getElementById('zotero-proxies-autoRecognize').checked = Zotero.Prefs.get("proxies.autoRecognize");
    165 		document.getElementById('zotero-proxies-showRedirectNotification').checked = Zotero.Prefs.get("proxies.showRedirectNotification");
    166 		document.getElementById('zotero-proxies-disableByDomain-checkbox').checked = Zotero.Prefs.get("proxies.disableByDomain");
    167 		document.getElementById('zotero-proxies-disableByDomain-textbox').value = Zotero.Prefs.get("proxies.disableByDomainString");
    168 	}
    169 };