home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
GameStar 2005 October
/
Gamestar_77_2005-10_dvd.iso
/
Programy
/
nsb-install-8-0.exe
/
chrome
/
toolkit.jar
/
content
/
mozapps
/
autofill
/
datacardDialogs.js
< prev
next >
Wrap
Text File
|
2005-07-29
|
5KB
|
175 lines
// JavaScript common to both of these dialogs:
// - datacardUpdateDialog.xul
// - datacardSaveNewDialog.xul
const DATACARD_DIALOG_DEBUG = false;
const nsIAutoFillService = Components.interfaces.nsIAutoFillService;
var datacardUtils;
var contentDoc;
var currentURI;
var rippedValues;
function initSaveNewDialog() {
dcDebug('initSaveNewDialog()');
commonInit();
}
function initUpdateDialog() {
dcDebug('initUpdateDialog()');
commonInit();
var menulist = document.getElementById('datacardList');
menulist.removeAllItems();
var datacards = datacardUtils.GetDatacardList();
var cardForSite = datacardUtils.FindDatacardForURI(currentURI);
for (var i = 0; i < datacards.length; i++) {
menulist.appendItem(datacards[i], datacards[i]);
if (datacards[i] == cardForSite)
menulist.selectedIndex = i;
}
}
function commonInit() {
dcDebug('commonInit()');
datacardFieldIDs = window.opener.datacardFieldIDs;
datacardUtils = window.opener.datacardUtils;
contentDoc = window.opener.gBrowser.contentDocument;
currentURI = window.opener.gBrowser.currentURI;
rippedValues = window.arguments[0];
dcDebug(' set rippedValues, length='+rippedValues.length);
document.getElementById('datacardChoice').selectedIndex = 0;
document.getElementById('datacardName').focus();
window.centerWindowOnScreen();
}
function onSaveNewAccept() {
dcDebug('onSaveNewAccept()');
return commonAccept();
}
function onUpdateAccept() {
dcDebug('onUpdateAccept()');
return commonAccept();
}
function commonAccept() {
dcDebug('commonAccept()');
var radiogroup = document.getElementById('datacardChoice');
switch (radiogroup.value) {
case 'update':
dcDebug(' - update');
var name = document.getElementById('datacardList').value;
datacardUtils.SetDatacardValues(name, currentURI, rippedValues);
datacardUtils.SetDatacardForHost(currentURI.host, name);
break;
case 'saveNew':
dcDebug(' - saveNew');
var datacardName = document.getElementById('datacardName');
var value = datacardName.value.replace(/^\s+/,'').replace(/\s+$/,'');
if (!value.length) {
alert('Please enter a name for the DataCard.');
return false;
}
var name = datacardUtils.GenerateFilenamePrefixForDatacard(value);
if (datacardUtils.DatacardExists(name)) {
alert('That name is already in use. Please choose another.');
return false;
}
datacardUtils.CreateDatacard(name);
datacardUtils.SetDatacardValues(name, currentURI, rippedValues);
datacardUtils.SetDatacardForHost(currentURI.host, name);
var datacardFile = datacardUtils.GetDatacardFileByName(name);
datacardUtils.afService.SetDatacardFieldByType(
datacardFile,
nsIAutoFillService.FIELDTYPE_PROPERTY,
'WhenToFill',
'displayprompt');
datacardUtils.afService.SetDatacardFieldByType(
datacardFile,
nsIAutoFillService.FIELDTYPE_PROPERTY,
'Label',
datacardName.value);
var enc = (document.getElementById('passwordProtect').checked) ? '1' : '0';
datacardUtils.afService.SetDatacardFieldByType(
datacardFile,
nsIAutoFillService.FIELDTYPE_PROPERTY,
'Encrypted',
enc);
break;
case 'doNotSave':
dcDebug(' - doNotSave');
// Do nothing, let the dialog close
break;
case 'neverForThisSite':
dcDebug(' - neverForThisSite');
datacardUtils.BlacklistSite(currentURI);
break;
default:
dcDebug(' WARNING: unhandled choice: '+radiogroup.value);
}
return true;
}
function enableDisable() {
dcDebug('enableDisable()');
var opt = document.getElementById('datacardChoice').value;
var nameLabel = document.getElementById('nameLabel');
var datacardName = document.getElementById('datacardName');
var passwordProtect = document.getElementById('passwordProtect');
var datacardList = document.getElementById('datacardList');
if (opt == 'saveNew') {
if (nameLabel)
nameLabel.removeAttribute('disabled');
if (datacardName)
datacardName.removeAttribute('disabled');
if (passwordProtect)
passwordProtect.removeAttribute('disabled');
if (datacardList)
datacardList.setAttribute('disabled','true');
} else {
if (nameLabel)
nameLabel.setAttribute('disabled','true');
if (datacardName)
datacardName.setAttribute('disabled','true');
if (passwordProtect)
passwordProtect.setAttribute('disabled','true');
if (datacardList) {
if (opt == 'update')
datacardList.removeAttribute('disabled');
else
datacardList.setAttribute('disabled','true');
}
}
}
function onPasswordProtect(val)
{
if (val && !IsMasterPasswordSet()) {
var obj = new Object();
obj.res = '';
window.openDialog('chrome://browser/content/pref/pref-masterpass.xul',
'_blank', 'chrome,dialog,modal', 'Set Master Password', obj);
dcDebug('Datacard save/update prompt calling Master Password result: ' + obj.res);
if(obj.res != 'ok') {
dcDebug('Cancelled out of Master Password');
document.getElementById('passwordProtect').checked = false;
}
}
}
function dcDebug(msg) {
if (DATACARD_DIALOG_DEBUG)
dump('datacardDialogs.js: '+msg+'\n');
}