!import
1 //@line 39 "/home/visbrero/mnt/roisin/rev_control/hg/mozilla/mail/components/preferences/connection.js"
2
3 var gConnectionsDialog = {
beforeAccept
4 beforeAccept: function ()
5 {
6 var proxyTypePref = document.getElementById("network.proxy.type");
7 if (proxyTypePref.value == 2) {
8 this.doAutoconfigURLFixup();
9 return true;
10 }
11
12 if (proxyTypePref.value != 1)
13 return true;
14
15 var httpProxyURLPref = document.getElementById("network.proxy.http");
16 var httpProxyPortPref = document.getElementById("network.proxy.http_port");
17 var shareProxiesPref = document.getElementById("network.proxy.share_proxy_settings");
18 if (shareProxiesPref.value) {
19 var proxyPrefs = ["ssl", "socks"];
20 for (var i = 0; i < proxyPrefs.length; ++i) {
21 var proxyServerURLPref = document.getElementById("network.proxy." + proxyPrefs[i]);
22 var proxyPortPref = document.getElementById("network.proxy." + proxyPrefs[i] + "_port");
23 var backupServerURLPref = document.getElementById("network.proxy.backup." + proxyPrefs[i]);
24 var backupPortPref = document.getElementById("network.proxy.backup." + proxyPrefs[i] + "_port");
25 backupServerURLPref.value = proxyServerURLPref.value;
26 backupPortPref.value = proxyPortPref.value;
27 proxyServerURLPref.value = httpProxyURLPref.value;
28 proxyPortPref.value = httpProxyPortPref.value;
29 }
30 }
31
32 return true;
33 },
34
proxyTypeChanged
35 proxyTypeChanged: function ()
36 {
37 var proxyTypePref = document.getElementById("network.proxy.type");
38
39 // Update http
40 var httpProxyURLPref = document.getElementById("network.proxy.http");
41 httpProxyURLPref.disabled = proxyTypePref.value != 1;
42 var httpProxyPortPref = document.getElementById("network.proxy.http_port");
43 httpProxyPortPref.disabled = proxyTypePref.value != 1;
44
45 // Now update the other protocols
46 this.updateProtocolPrefs();
47
48 var shareProxiesPref = document.getElementById("network.proxy.share_proxy_settings");
49 shareProxiesPref.disabled = proxyTypePref.value != 1;
50
51 var noProxiesPref = document.getElementById("network.proxy.no_proxies_on");
52 noProxiesPref.disabled = proxyTypePref.value != 1;
53
54 var autoconfigURLPref = document.getElementById("network.proxy.autoconfig_url");
55 autoconfigURLPref.disabled = proxyTypePref.value != 2;
56
57 this.updateReloadButton();
58 },
59
updateReloadButton
60 updateReloadButton: function ()
61 {
62 // Disable the "Reload PAC" button if the selected proxy type is not PAC or
63 // if the current value of the PAC textbox does not match the value stored
64 // in prefs. Likewise, disable the reload button if PAC is not configured
65 // in prefs.
66
67 var typedURL = document.getElementById("networkProxyAutoconfigURL").value;
68 var proxyTypeCur = document.getElementById("network.proxy.type").value;
69
70 var prefs =
71 Components.classes["@mozilla.org/preferences-service;1"].
72 getService(Components.interfaces.nsIPrefBranch);
73 var pacURL = prefs.getCharPref("network.proxy.autoconfig_url");
74 var proxyType = prefs.getIntPref("network.proxy.type");
75
76 var disableReloadPref =
77 document.getElementById("pref.advanced.proxies.disable_button.reload");
78 disableReloadPref.disabled =
79 (proxyTypeCur != 2 || proxyType != 2 || typedURL != pacURL);
80 },
81
readProxyType
82 readProxyType: function ()
83 {
84 this.proxyTypeChanged();
85 return undefined;
86 },
87
updateProtocolPrefs
88 updateProtocolPrefs: function ()
89 {
90 var proxyTypePref = document.getElementById("network.proxy.type");
91 var shareProxiesPref = document.getElementById("network.proxy.share_proxy_settings");
92 var proxyPrefs = ["ssl", "socks"];
93 for (var i = 0; i < proxyPrefs.length; ++i) {
94 var proxyServerURLPref = document.getElementById("network.proxy." + proxyPrefs[i]);
95 var proxyPortPref = document.getElementById("network.proxy." + proxyPrefs[i] + "_port");
96
97 // Restore previous per-proxy custom settings, if present.
98 if (!shareProxiesPref.value) {
99 var backupServerURLPref = document.getElementById("network.proxy.backup." + proxyPrefs[i]);
100 var backupPortPref = document.getElementById("network.proxy.backup." + proxyPrefs[i] + "_port");
101 if (backupServerURLPref.hasUserValue) {
102 proxyServerURLPref.value = backupServerURLPref.value;
103 backupServerURLPref.reset();
104 }
105 if (backupPortPref.hasUserValue) {
106 proxyPortPref.value = backupPortPref.value;
107 backupPortPref.reset();
108 }
109 }
110
111 proxyServerURLPref.updateElements();
112 proxyPortPref.updateElements();
113 proxyServerURLPref.disabled = proxyTypePref.value != 1 || shareProxiesPref.value;
114 proxyPortPref.disabled = proxyServerURLPref.disabled;
115 }
116 var socksVersionPref = document.getElementById("network.proxy.socks_version");
117 socksVersionPref.disabled = proxyTypePref.value != 1 || shareProxiesPref.value;
118
119 return undefined;
120 },
121
readProxyProtocolPref
122 readProxyProtocolPref: function (aProtocol, aIsPort)
123 {
124 var shareProxiesPref = document.getElementById("network.proxy.share_proxy_settings");
125 if (shareProxiesPref.value) {
126 var pref = document.getElementById("network.proxy.http" + (aIsPort ? "_port" : ""));
127 return pref.value;
128 }
129
130 var backupPref = document.getElementById("network.proxy.backup." + aProtocol + (aIsPort ? "_port" : ""));
131 return backupPref.hasUserValue ? backupPref.value : undefined;
132 },
133
reloadPAC
134 reloadPAC: function ()
135 {
136 Components.classes["@mozilla.org/network/protocol-proxy-service;1"].
137 getService().reloadPAC();
138 },
139
doAutoconfigURLFixup
140 doAutoconfigURLFixup: function ()
141 {
142 var autoURL = document.getElementById("networkProxyAutoconfigURL");
143 var autoURLPref = document.getElementById("network.proxy.autoconfig_url");
144 var URIFixup = Components.classes["@mozilla.org/docshell/urifixup;1"]
145 .getService(Components.interfaces.nsIURIFixup);
146 try {
147 autoURLPref.value = autoURL.value = URIFixup.createFixupURI(autoURL.value, 0).spec;
148 } catch(ex) {}
149 },
150
readHTTPProxyServer
151 readHTTPProxyServer: function ()
152 {
153 var shareProxiesPref = document.getElementById("network.proxy.share_proxy_settings");
154 if (shareProxiesPref.value)
155 this.updateProtocolPrefs();
156 return undefined;
157 },
158
readHTTPProxyPort
159 readHTTPProxyPort: function ()
160 {
161 var shareProxiesPref = document.getElementById("network.proxy.share_proxy_settings");
162 if (shareProxiesPref.value)
163 this.updateProtocolPrefs();
164 return undefined;
165 }
166 };