1
0
mirror of https://github.com/MailHops/mailhops-plugin.git synced 2025-05-17 06:40:08 -07:00
mailhops-plugin/chrome/content/preferences.js
Andrew Van Tassel 7f26e8b121 Added new prefs for hosting option
Reformatted prefs into tabs
2012-05-04 02:43:04 -06:00

154 lines
6.2 KiB
JavaScript

if (!pref)
{
var pref = Components.classes["@mozilla.org/preferences-service;1"].getService ( Components.interfaces.nsIPrefBranch ) ;
}
var mailHopPreferences =
{
use_private: null,
api_url: null,
hosting: null,
loadPreferences: function()
{
this.use_private = document.getElementById("mailhop.use_private");
this.api_url = document.getElementById("mailhop.api_url");
this.hosting = document.getElementById("mailhop.hosting");
if(pref.getCharPref("mail.mailHops.map",'goog')=='goog')
document.getElementById("mailhop.map").selectedIndex = 0;
else
document.getElementById("mailhop.map").selectedIndex = 1;
if(pref.getCharPref("mail.mailHops.unit",'mi')=='mi')
document.getElementById("mailhop.unit").selectedIndex = 0;
else
document.getElementById("mailhop.unit").selectedIndex = 1;
//Display Box Options
if(pref.getCharPref("mail.mailHops.show_details",'true')=='true')
document.getElementById("mailhop.show_details").checked = true;
else
document.getElementById("mailhop.show_details").checked = false;
if(pref.getCharPref("mail.mailHops.show_lists",'true')=='true')
document.getElementById("mailhop.show_lists").checked = true;
else
document.getElementById("mailhop.show_lists").checked = false;
if(pref.getCharPref("mail.mailHops.show_auth",'true')=='true')
document.getElementById("mailhop.show_auth").checked = true;
else
document.getElementById("mailhop.show_auth").checked = false;
//Details Options
if(pref.getCharPref("mail.mailHops.show_weather",'false')=='true')
document.getElementById("mailhop.show_weather").checked = true;
else
document.getElementById("mailhop.show_weather").checked = false;
if(pref.getCharPref("mail.mailHops.show_host",'false')=='true')
document.getElementById("mailhop.show_host").checked = true;
else
document.getElementById("mailhop.show_host").checked = false;
//Auth Options
if(pref.getCharPref("mail.mailHops.show_spf",'true')=='true')
document.getElementById("mailhop.show_spf").checked = true;
else
document.getElementById("mailhop.show_spf").checked = false;
if(pref.getCharPref("mail.mailHops.show_dkim",'true')=='true')
document.getElementById("mailhop.show_dkim").checked = true;
else
document.getElementById("mailhop.show_dkim").checked = false;
if(pref.getCharPref("mail.mailHops.show_mailer",'true')=='true')
document.getElementById("mailhop.show_mailer").checked = true;
else
document.getElementById("mailhop.show_mailer").checked = false;
if(pref.getCharPref("mail.mailHops.show_dnsbl",'true')=='true')
document.getElementById("mailhop.show_dnsbl").checked = true;
else
document.getElementById("mailhop.show_dnsbl").checked = false;
//Hosting Options
if(pref.getCharPref("mail.mailHops.hosting",'personal')=='personal')
document.getElementById("mailhop.hosting").selectedIndex = 0;
else if(pref.getCharPref("mail.mailHops.hosting",'personal')=='edu')
document.getElementById("mailhop.hosting").selectedIndex = 1;
else
document.getElementById("mailhop.hosting").selectedIndex = 2;
if(pref.getCharPref("mail.mailHops.use_private",'false')=='true'){
document.getElementById("mailhop.use_private").checked = true;
this.api_url.removeAttribute("disabled");
}
else
document.getElementById("mailhop.use_private").checked = false;
this.api_url.value = pref.getCharPref("mail.mailHops.api_url",'http://api.mailhops.com');
} ,
savePreferences: function()
{
pref.setCharPref("mail.mailHops.map", document.getElementById("mailhop.map").selectedItem.value) ;
pref.setCharPref("mail.mailHops.unit", document.getElementById("mailhop.unit").selectedItem.value) ;
pref.setCharPref("mail.mailHops.show_details", String(document.getElementById("mailhop.show_details").checked)) ;
pref.setCharPref("mail.mailHops.show_weather", String(document.getElementById("mailhop.show_weather").checked)) ;
pref.setCharPref("mail.mailHops.show_host", String(document.getElementById("mailhop.show_host").checked)) ;
pref.setCharPref("mail.mailHops.show_spf", String(document.getElementById("mailhop.show_spf").checked)) ;
pref.setCharPref("mail.mailHops.show_dkim", String(document.getElementById("mailhop.show_dkim").checked)) ;
pref.setCharPref("mail.mailHops.show_mailer", String(document.getElementById("mailhop.show_mailer").checked)) ;
pref.setCharPref("mail.mailHops.show_dnsbl", String(document.getElementById("mailhop.show_dnsbl").checked)) ;
pref.setCharPref("mail.mailHops.show_lists", String(document.getElementById("mailhop.show_lists").checked)) ;
pref.setCharPref("mail.mailHops.show_auth", String(document.getElementById("mailhop.show_auth").checked)) ;
pref.setCharPref("mail.mailHops.use_private", String(document.getElementById("mailhop.use_private").checked)) ;
pref.setCharPref("mail.mailHops.hosting", document.getElementById("mailhop.hosting").selectedItem.value) ;
pref.setCharPref("mail.mailHops.api_url", String(document.getElementById("mailhop.api_url").value)) ;
}
}
function ChangePrivate(item){
if(item.checked){
mailHopPreferences.api_url.removeAttribute("disabled");
mailHopPreferences.api_url.focus();
}
else{
mailHopPreferences.api_url.setAttribute("disabled","true");
mailHopPreferences.api_url.value='http://api.mailhops.com';
}
}
function TestConnection(){
var xmlhttp = new XMLHttpRequest();
var nativeJSON = Components.classes["@mozilla.org/dom/json;1"].createInstance(Components.interfaces.nsIJSON);
var lookupURL=mailHopPreferences.api_url.value+'/v1/lookup/?pb&app='+mailHops.appVersion+'&watchmouse';
xmlhttp.open("GET", lookupURL ,true);
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4) {
try{
var data = JSON.parse(xmlhttp.responseText);
if(data && data.meta.code==200){
alert('Connection Succeeded to '+mailHopPreferences.api_url.value+'!');
} else {
//display the error
alert('Connection Failed to '+mailHopPreferences.api_url.value+'!');
}
}
catch (ex){
alert('Connection Failed to '+mailHopPreferences.api_url.value+'!');
}
}
};
xmlhttp.send(null);
}
function ResetConnection(){
mailHopPreferences.api_url.value='http://api.mailhops.com';
}