home *** CD-ROM | disk | FTP | other *** search
Text File | 2005-07-29 | 36.4 KB | 1,221 lines |
- const AUTOFILL_DEBUG = false;
- function afDebug(msg) {
- if (AUTOFILL_DEBUG)
- dump('autofill.js: '+msg+'\n');
- }
-
- var suppressEncryptedDatacards = false;
-
- var afService = datacardUtils.afService;
-
- //credit card information
- var cc_name_val;
- var cc_number_val;
- var cc_type_val;
- var cc_expire_month_val;
- var cc_expire_year_val;
- var cc_password_val;
- var cc_primary_val;
- var cardNumValue;
- var cardNumValueVerified;
- var passwordHasChanged = 0; //FALSE, Change Password flag
-
- //---variables to store form field values -----------------
- var primary_val;
- var FFtitle_val;
- var fname_val;
- var lname_val;
- var email_val;
- var phone_val;
- var workphone_val;
- var gPrefService = null;
-
- //primary address
- var street_val;
- var street2_val;
- var city_val;
- var state_val;
- var zip_val;
- var country_val;
-
- //alternative address
- var alt_street_val;
- var alt_street2_val;
- var alt_city_val;
- var alt_state_val;
- var alt_zip_val;
- var alt_country_val;
-
- var extraFields_val;
-
- //---form fields --------------------------------------------
- var primary;
- var alternative;
- var dcProtect;
- var datacardAutofillList_val;
-
- //credit card button
- var creditCardButton;
-
- var fname;
- var lname;
- var email;
- var phone;
-
- //primary address
- var street;
- var street2;
- var city;
- var state;
- var zip;
- var country;
-
- var prevAutofillStatus;
- var prevPrimaryStatus;
-
- var formHasNoData = 0; //FALSE
-
- var kPREFContractID = "@mozilla.org/preferences-service;1";
- var kPREFIID = Components.interfaces.nsIPrefService;
- var kPBIID = Components.interfaces.nsIPrefBranch;
- var PREF = null;
-
- var gTabSelectInit = false;
- var removeAllFlag = false;
- var clearFormDataCount = 0;
-
- var currentDatacard = null;
- var currentDatacardFile = null;
- var currentDatacardIsEncrypted = false;
- var currentDatacardIsDirty = false;
-
- function saveDatacardProperty(key, value)
- {
- afDebug('saveDatacardProperty('+key+', '+value+')');
- afService.SetDatacardFieldByType(currentDatacardFile,
- nsIAutoFillService.FIELDTYPE_PROPERTY,
- key,
- value);
- }
-
- function saveDatacardField(key, value)
- {
- afDebug('saveDatacardField('+key+', '+value+')');
- afService.SetDatacardFieldByType(currentDatacardFile,
- nsIAutoFillService.FIELDTYPE_REGULAR,
- key,
- value);
- }
-
- function saveDatacardAdvancedField(key, value)
- {
- afDebug('saveDatacardAdvancedField('+key+', '+value+')');
- afService.SetDatacardFieldByType(currentDatacardFile,
- nsIAutoFillService.FIELDTYPE_ADVANCED,
- key,
- value);
- }
-
- function getDictionaryValue(dict, key)
- {
- if (dict.hasKey(key)) {
- var val = dict.getValue(key);
- val.QueryInterface(Components.interfaces.nsIPrefLocalizedString);
- return val.toString();
- } else {
- return '';
- }
- }
-
-
- function saveDatacard()
- {
- // Only save if we need to
- if (!currentDatacardIsDirty) return;
-
- // If the datacard is encrypted and the master password has not been
- // entered, then we don't actually want to save it
- if (suppressEncryptedDatacards && currentDatacardIsEncrypted) return;
-
- afDebug('saveDatacard()');
- // formHasNoData = 0; //redundant, already set by read data function.
-
- FFtitle_val.value = FFtitle.value;
- fname_val.value = fname.value;
- lname_val.value = lname.value;
- email_val.value = email.value;
- phone_val.value = phone.value;
- workphone_val.value = workphone.value;
-
- dcardLabel_val.value = dcardLabel.value;
- dump("dcardLabel_val.value " + dcardLabel_val.value + "\n");
- datacardAutofillList_val.value = datacardAutofillList.value;
- dump("datacardAutofillList_val.value " + datacardAutofillList_val.value + "\n");
-
- var pri = primary.selected;
- if (pri.toString() == 'true')
- {
- street_val.value = street.value;
- street2_val.value = street2.value;
- city_val.value = city.value;
- zip_val.value = zip.value;
- state_val.value = state.value;
- country_val.value = country.value;
- }
- else
- {
- alt_street_val.value = street.value;
- alt_street2_val.value = street2.value;
- alt_city_val.value = city.value;
- alt_zip_val.value = zip.value;
- alt_state_val.value = state.value;
- alt_country_val.value = country.value;
- }
- primary = document.getElementById("PriAddr");
- alternative = document.getElementById("AltAddr");
-
- dump("Now Saving Autofill value\n");
-
- saveDatacardField('title', FFtitle_val.value);
- saveDatacardField('firstname', fname_val.value);
- saveDatacardField('lastname', lname_val.value);
- saveDatacardField('email', email_val.value);
- saveDatacardField('phone', phone_val.value);
- saveDatacardField('work_phone', workphone_val.value);
-
- saveDatacardField('street', street_val.value);
- saveDatacardField('street2', street2_val.value);
- saveDatacardField('city', city_val.value);
- saveDatacardField('zip', zip_val.value);
- saveDatacardField('state', state_val.value);
- saveDatacardField('country', country_val.value);
-
- saveDatacardField('alt_street', alt_street_val.value);
- saveDatacardField('alt_street2', alt_street2_val.value);
- saveDatacardField('alt_city', alt_city_val.value);
- saveDatacardField('alt_zip', alt_zip_val.value);
- saveDatacardField('alt_state', alt_state_val.value);
- saveDatacardField('alt_country', alt_country_val.value);
-
- var advExtras = ripExtraFieldsFromTree();
- for (var i = 0; i < advExtras.fields.length; i++) {
- saveDatacardAdvancedField(advExtras.fields[i], advExtras.values[i]);
- }
-
- var dcProtect_enabled = document.getElementById("dcProtect");
- if (dcProtect_enabled.checked)
- saveDatacardProperty("Encrypted", "1");
- else
- saveDatacardProperty("Encrypted", "0");
-
- saveDatacardProperty('Label', currentDatacard);
- saveDatacardProperty('WhenToFill', datacardAutofillList_val.value);
-
- //Credit Card
- CCardOK();
- }
-
-
- function readDatacard()
- {
- afDebug('readDatacard()');
- formHasNoData = 0;
-
- var propDict =
- afService.GetDatacardFieldsByType(
- currentDatacardFile, nsIAutoFillService.FIELDTYPE_PROPERTY);
- if (suppressEncryptedDatacards) {
- currentDatacardIsEncrypted = (getDictionaryValue(propDict, 'Encrypted') == '1');
- if (currentDatacardIsEncrypted) return;
- }
- var regularDict =
- afService.GetDatacardFieldsByType(
- currentDatacardFile, nsIAutoFillService.FIELDTYPE_REGULAR);
- var advancedDict =
- afService.GetDatacardFieldsByType(
- currentDatacardFile, nsIAutoFillService.FIELDTYPE_ADVANCED);
-
- FFtitle_val.value = getDictionaryValue(regularDict, 'title');
- fname_val.value = getDictionaryValue(regularDict, 'firstname');
- lname_val.value = getDictionaryValue(regularDict, 'lastname');
- email_val.value = getDictionaryValue(regularDict, 'email');
- phone_val.value = getDictionaryValue(regularDict, 'phone');
- workphone_val.value = getDictionaryValue(regularDict, 'work_phone');
-
- street_val.value = getDictionaryValue(regularDict, 'street');
- street2_val.value = getDictionaryValue(regularDict, 'street2');
- city_val.value = getDictionaryValue(regularDict, 'city');
- state_val.value = getDictionaryValue(regularDict, 'state');
- zip_val.value = getDictionaryValue(regularDict, 'zip');
- country_val.value = getDictionaryValue(regularDict, 'country');
- if (country_val.value == '')
- country_val.value = 'United States';
-
- alt_street_val.value = getDictionaryValue(regularDict, 'alt_street');
- alt_street2_val.value = getDictionaryValue(regularDict, 'alt_street2');
- alt_city_val.value = getDictionaryValue(regularDict, 'alt_city');
- alt_state_val.value = getDictionaryValue(regularDict, 'alt_state');
- alt_zip_val.value = getDictionaryValue(regularDict, 'alt_zip');
- alt_country_val.value = getDictionaryValue(regularDict, 'alt_country');
- if (alt_country_val.value == '')
- alt_country_val.value = 'United States';
-
- var advKeys = advancedDict.getKeys({});
- var pairs = new Array();
- for (var k = 0; k < advKeys.length; k++) {
- var key = advKeys[k];
- var val = getDictionaryValue(advancedDict, key);
- pairs[pairs.length] = key+'='+escape(val);
- }
- extraFields_val.value = pairs.join('|');
- refreshExtraFieldsUI();
-
- dcardLabel_val.value = getDictionaryValue(propDict, 'Label');
- afDebug("read datacard: " + dcardLabel_val.value);
- datacardAutofillList_val.value = getDictionaryValue(propDict, 'WhenToFill');
- dcardProtect_val.value = getDictionaryValue(propDict, 'Encrypted');
-
- if (dcardProtect_val.value == '1')
- document.getElementById("dcProtect").checked = true;
- else
- document.getElementById("dcProtect").checked = false;
-
- primary_val.value = "true";
- if (primary_val.value == 'true') {
- document.getElementById("afillRadio").selectedIndex = 0;
- } else {
- document.getElementById("afillRadio").selectedIndex = 1;
- }
-
- var pv = primary_val.value;
- if (pv != "false" && pv != "true")
- pv = "true";
-
- FFtitle.value = FFtitle_val.value;
- fname.value=fname_val.value;
- lname.value=lname_val.value;
- email.value=email_val.value;
- phone.value=phone_val.value;
- workphone.value=workphone_val.value;
- dcardLabel.value = dcardLabel_val.value;
- datacardAutofillList.value=datacardAutofillList_val.value;
- dcardProtect.value=dcardProtect_val.value;
-
- if (pv.toString()=='true') {
- dump("Now Reading Primary data!\n");
- prevPrimaryStatus="true";
- street.value=street_val.value;
- street2.value=street2_val.value;
- city.value=city_val.value;
- zip.value=zip_val.value;
- state.value=state_val.value;
- country.value=country_val.value;
- dump("primary:"+primary+"\n");
- //primary.setAttribute("selected",'true');
- } else {
- dump("Now Reading Alternate data!\n");
- prevPrimaryStatus="false";
- street.value=alt_street_val.value;
- street2.value=alt_street2_val.value;
- city.value=alt_city_val.value;
- zip.value=alt_zip_val.value;
- state.value=alt_state_val.value;
- country.value=alt_country_val.value;
- //primary.setAttribute("selected", 'true');
- }
-
- //Credit card
- initCreditCard();
- ccStartUp();
-
- currentDatacardIsDirty = false;
- }
-
-
- function Startup()
- {
- afDebug("Startup() ~~~~~~~~~~~");
-
- // Populate countries
- var countryMenuPopup = document.getElementById('countryType');
- for (var i = 0; i < countryList.length; i++) {
- var item = document.createElement('menuitem');
- item.setAttribute('value', countryList[i]);
- item.setAttribute('label', countryList[i]);
- countryMenuPopup.appendChild(item);
- }
-
- //---form fields --------------------------------------------
- primary=document.getElementById("PriAddr");
- alternative=document.getElementById("AltAddr");
-
- dcProtect=document.getElementById("dcProtect");
- FFtitle=document.getElementById("Title");
- fname=document.getElementById("FirstName");
- lname=document.getElementById("LastName");
- email=document.getElementById("EmailAddr");
- phone=document.getElementById("PhoneNum");
- workphone=document.getElementById("WorkPhoneNum");
-
- street=document.getElementById("StrAddr");
- street2=document.getElementById("StrAddr2");
- city = document.getElementById("City");
- state=document.getElementById("State");
- zip=document.getElementById("ZipCode");
- country=document.getElementById("countryList");
-
- creditCardButton=document.getElementById("ccButton");
-
- dcardLabel = document.getElementById("datacardName");
- datacardAutofillList = document.getElementById("datacardAutofillList");
- dcardProtect = document.getElementById("dcProtect");
-
- //---variables to store form field values -----------------
- primary_val=new Object();
- FFtitle_val =new Object();FFtitle_val.value="";
- fname_val=new Object();fname_val.value="";
- lname_val=new Object();lname_val.value="";
- email_val=new Object();email_val.value="";
- phone_val=new Object();phone_val.value="";
- workphone_val=new Object();workphone_val.value="";
-
- dcardLabel_val=new Object(); dcardLabel_val.value="";
- datacardAutofillList_val=new Object(); datacardAutofillList_val.value="";
- dcardProtect_val=new Object(); dcardProtect_val.value="";
-
- //primary address
- street_val=new Object();street_val.value="";
- street2_val=new Object();street2_val.value="";
- city_val=new Object();city_val.value="";
- state_val=new Object();state_val.value="";
- zip_val=new Object(); zip_val.value="";
- country_val=new Object();country_val.value="";
-
- //alternative address
- alt_street_val=new Object(); alt_street_val.value="";
- alt_street2_val=new Object(); alt_street2_val.value="";
- dump("alt_street:"+alt_street_val.value+"!\n");
- alt_city_val=new Object();alt_city_val.value="";
- alt_state_val=new Object();alt_state_val.value="";
- alt_zip_val=new Object();alt_zip_val.value="";
- alt_country_val=new Object();alt_country_val.value="";
-
- // extra fields
- extraFields_val=new Object();extraFields_val.value="";
- refreshExtraFieldsUI();
-
- //control information
- primary_val=new Object(); primary_val.value=" ";
-
- gTabSelectInit = true;
- setTab();
- populateDatacardList();
- // dataCardAutoSaveChange(); Not used
- populateBlacklist();
-
- // Register event listener to tell when datacards are being changed
- var deck = document.getElementById('datacardDetails-deck');
- deck.addEventListener('change', onDatacardChanged, true);
- deck.addEventListener('select', onDatacardChanged, true);
- deck.addEventListener('textentered', onDatacardChanged, true);
- deck.addEventListener('focus', onDatacardChanged, true);
- deck.addEventListener('command', onDatacardChanged, true);
- deck.addEventListener('keypress', onDatacardChanged, true);
-
- // setup event handler
- window.top.hPrefWindow.registerOKCallbackFunc(onAutoFillOK);
-
- // load passcard manager
- PasscardOnLoad();
-
- setTab();
- }
-
-
- function onDatacardChanged(event) {
- afDebug('onDatacardChanged()');
- currentDatacardIsDirty = true;
- }
-
-
- function refreshExtraFieldsUI() {
- afDebug('refreshExtraFieldsUI('+extraFields_val.value+')');
-
- // Clear the tree
- var treeChildren = document.getElementById('advancedTreeChildren');
- while (treeChildren.childNodes.length)
- treeChildren.removeChild(treeChildren.childNodes[treeChildren.childNodes.length-1]);
-
- if (extraFields_val.value.length) {
- document.getElementById('advancedDeck').selectedIndex = 1;
- var pairs = extraFields_val.value.split('|');
- for (var i = 0; i < pairs.length; i++) {
- var delim = pairs[i].indexOf('=');
- var fieldName = pairs[i].substring(0,delim);
- var value = unescape(pairs[i].substring(delim+1));
- var keyCell = document.createElement('treecell');
- keyCell.setAttribute('label', fieldName);
- var valCell = document.createElement('treecell');
- valCell.setAttribute('label', value);
- var row = document.createElement('treerow');
- row.appendChild(keyCell);
- row.appendChild(valCell);
- var item = document.createElement('treeitem');
- item.appendChild(row);
- treeChildren.appendChild(item);
- }
- } else {
- document.getElementById('advancedDeck').selectedIndex = 0;
- }
- }
-
-
- function ripExtraFieldsFromTree() {
- var treeChildren = document.getElementById('advancedTreeChildren');
- var pairs = new Object();
- pairs.fields = new Array();
- pairs.values = new Array();
- for (var i = 0; i < treeChildren.childNodes.length; i++) {
- var row = treeChildren.childNodes[i].firstChild;
- var fieldIdx = pairs.fields.length;
- pairs.fields[fieldIdx] = row.firstChild.getAttribute('label');
- pairs.values[fieldIdx] = row.lastChild.getAttribute('label');
- }
- //var str = pairs.join('|');
- //afDebug('ripExtraFieldsFromTree():\n ['+str+']');
- return pairs;
- }
-
-
- function populateDatacardList() {
- afDebug('populateDatacardList()');
-
- // Clear the tree
- var treeChildren = document.getElementById('datacardTreeChildren');
- while (treeChildren.childNodes.length)
- treeChildren.removeChild(treeChildren.childNodes[treeChildren.childNodes.length-1]);
-
- // Ensure at least one datacard exists
- var defaultCard;
- if (!datacardUtils.DatacardsExist()) {
- defaultCard = 'MyData';
- datacardUtils.CreateDatacard(defaultCard);
- datacardUtils.SetDefaultDatacard(defaultCard);
- } else {
- defaultCard = datacardUtils.GetDefaultDatacard();
- }
-
- // Repopulate the tree
- var datacards = datacardUtils.GetDatacardList();
- suppressEncryptedDatacards = false;
- for (var i = 0; i < datacards.length; i++) {
- // See if this datacard is encrypted
- var file = datacardUtils.GetDatacardFileByName(datacards[i]);
- var propDict =
- afService.GetDatacardFieldsByType(
- file, nsIAutoFillService.FIELDTYPE_PROPERTY);
- var isEncrypted = propDict.getValue('Encrypted');
- isEncrypted.QueryInterface(Components.interfaces.nsIPrefLocalizedString);
- isEncrypted = (isEncrypted.toString() == '1');
- if (isEncrypted && !suppressEncryptedDatacards) {
- //if (suppressEncryptedDatacards) continue;
- // This datacard is encrypted, so try loading a datafield so
- // that the user gets prompted to enter master password.
- try {
- afDebug(' - before encrypt check');
- afService.PokeEncryptedDatacard(file);
- suppressEncryptedDatacards = false;
- afDebug(' - after encrypt check');
- } catch (ex) {
- afDebug(' - skipping encrypted');
- suppressEncryptedDatacards = true;
- }
- }
- var cell = document.createElement("treecell");
- cell.setAttribute('label', datacards[i]);
- var cellProps = new Array();
- if (datacards[i] == defaultCard) {
- dump(' - marking default tree item: '+defaultCard+'\n');
- cellProps[cellProps.length] = 'default';
- }
- if (isEncrypted && suppressEncryptedDatacards) {
- cellProps[cellProps.length] = 'disabled';
- cell.setAttribute('disabled', 'true');
- }
- cell.setAttribute('properties', cellProps.join(','));
- var row = document.createElement("treerow");
- row.appendChild(cell);
- var item = document.createElement("treeitem");
- item.setAttribute('datacard', datacards[i]);
- item.appendChild(row);
- treeChildren.appendChild(item);
- }
-
- // Since there are items in the list(s), the Remove All button
- // should be enabled
- document.getElementById('datacardRemoveAllButton').removeAttribute('disabled');
-
- // Always select the first datacard
- document.getElementById('datacardTree').view.selection.select(0);
- }
-
-
- function populateBlacklist() {
- afDebug('populateBlacklist()');
-
- // Clear the tree
- var treeChildren = document.getElementById('datacardRejectsTreeChildren');
- while (treeChildren.childNodes.length)
- treeChildren.removeChild(treeChildren.childNodes[treeChildren.childNodes.length-1]);
-
- // Repopulate the tree
- var blacklist = datacardUtils.GetBlacklistedSites();
- for (var i = 0; i < blacklist.length; i++) {
- var cell = document.createElement("treecell");
- cell.setAttribute('label', blacklist[i]);
- var row = document.createElement("treerow");
- row.appendChild(cell)
- var item = document.createElement("treeitem");
- item.setAttribute('host', blacklist[i]);
- item.appendChild(row);
- treeChildren.appendChild(item);
- }
- }
-
-
- function enableId(elmId) { document.getElementById(elmId).removeAttribute('disabled'); }
- function disableId(elmId) { document.getElementById(elmId).setAttribute('disabled','true'); }
-
- const fickleFields = [ 'datacardAutofillList', 'dcProtect', 'dcSetAsDefaultBtn',
- 'Title', 'FirstName', 'LastName', 'EmailAddr',
- 'PhoneNum', 'WorkPhoneNum', 'PriAddr', 'AltAddr',
- 'StrAddr', 'StrAddr2', 'City', 'State', 'countryList',
- 'ZipCode', 'CardName', 'CardNumber', 'cardtypeList',
- 'monthList', 'yearList', 'advancedTree' ];
-
- function enableDatacardForm() {
- afDebug('enableDatacardForm()');
- for (var i = 0; i < fickleFields.length; i++) {
- enableId(fickleFields[i]);
- }
- }
-
- function disableDatacardForm() {
- afDebug('disableDatacardForm()');
- for (var i = 0; i < fickleFields.length; i++) {
- disableId(fickleFields[i]);
- document.getElementById(fickleFields[i]).value = '';
- }
- document.getElementById('dcProtect').checked = true;
- }
-
-
- // Make sure the SelectSignon and SelectReject functions are
- // mutually exclusive
- var selectionMutex = 0;
-
-
- function SelectSignon() {
- // Respect mutex
- if (selectionMutex) return;
- // Establish mutex
- selectionMutex++;
-
- afDebug('SelectSignon()');
-
- // If there is NO current selection, bail
- var tree = document.getElementById('datacardTree');
- if (tree.currentIndex == -1) {
- selectionMutex--;
- return;
- }
-
- // Clear the selection in the blacklist tree
- document.getElementById('datacardRejectsTree').view.selection.clearSelection();
-
- // Make the details tabs visible
- document.getElementById('datacardDetails-deck').selectedIndex = 1;
-
- // Save the previous datacard, if any
- // (Note: this is not ideal... it means that the prefs Cancel button
- // won't actually cancel the datacard change)
- if (currentDatacard) saveDatacard();
-
- // Load the selected datacard
- var item = tree.contentView.getItemAtIndex(tree.currentIndex);
- var datacard = item.getAttribute('datacard');
- afDebug('SelectSignon: attempt to load datacard: '+datacard);
- currentDatacard = datacard;
- currentDatacardFile = datacardUtils.GetDatacardFileByName(datacard);
- suppressEncryptedDatacards = false;
- var propDict =
- afService.GetDatacardFieldsByType(
- currentDatacardFile, nsIAutoFillService.FIELDTYPE_PROPERTY);
- currentDatacardIsEncrypted = (getDictionaryValue(propDict, 'Encrypted') == '1');
- var isMPset = IsMasterPasswordSet();
- if (!isMPset) {
- suppressEncryptedDatacards = false;
- } else if (currentDatacardIsEncrypted) {
- afDebug(" - it's ENCRYPTED");
- try {
- afService.PokeEncryptedDatacard(currentDatacardFile);
- suppressEncryptedDatacards = false;
- } catch (ex) {
- afDebug(' - CAUGHT: '+ex);
- suppressEncryptedDatacards = true;
- }
- }
-
- // Show datacard name
- afDebug(' - setting datacard name label: '+datacard);
- dcardLabel.value = datacard;
-
- if (suppressEncryptedDatacards) {
- disableDatacardForm();
- selectionMutex--;
- return;
- }
- enableDatacardForm();
-
- readDatacard();
-
- // The 'Set as Default' button should only be enabled if this datacard
- // is not already the default
- if (datacard == datacardUtils.GetDefaultDatacard())
- disableId('dcSetAsDefaultBtn');
- else
- enableId('dcSetAsDefaultBtn');
-
- // The Remove buttons should be enabled unless the selected datacard is
- // the *only* datacard
- if (tree.view.rowCount == 1) {
- disableId('datacardRemoveButton');
- disableId('datacardRemoveAllButton');
- } else {
- enableId('datacardRemoveButton');
- enableId('datacardRemoveAllButton');
- }
-
- // Release mutex
- selectionMutex--;
- }
-
-
- function SelectReject() {
- // Respect mutex
- if (selectionMutex) return;
- // Establish mutex
- selectionMutex++;
-
- afDebug('SelectReject()');
-
- // Hide the datacard details tabs
- document.getElementById('datacardDetails-deck').selectedIndex = 0;
-
- // Clear the selection in the datacards tree
- document.getElementById('datacardTree').view.selection.clearSelection();
-
- // Since an item is selected, the Remove buttons should be enabled
- document.getElementById('datacardRemoveButton').removeAttribute('disabled');
- document.getElementById('datacardRemoveAllButton').removeAttribute('disabled');
-
- // Release mutex
- selectionMutex--;
- }
-
-
- function datacardAddButton() {
- window.openDialog("chrome://mozapps/content/autofill/addRenameDatacardDialog.xul",
- "_blank", "chrome,modal,resizable=no");
- }
-
-
- function callback_NewDatacardName(label) {
- var name = datacardUtils.GenerateFilenamePrefixForDatacard(label);
- datacardUtils.CreateDatacard(name);
- populateDatacardList();
- }
-
-
- function datacardRemoveButton() {
- // Figure out which tree has the selected item
- var datacardTree = document.getElementById('datacardTree');
- if (datacardTree.view.selection.count)
- DeleteDatacard();
- else
- DeleteBlacklistSite();
- }
-
-
- function datacardRemoveAllButton() {
- // Figure out which tree has the selected item
- var datacardTree = document.getElementById('datacardTree');
- if (datacardTree.view.selection.count)
- DeleteAllDatacards();
- else
- ClearBlacklist();
- }
-
-
- function DeleteDatacard() {
- // Delete the datacard
- //var tree = document.getElementById('datacardTree');
- //var item = tree.contentView.getItemAtIndex(tree.currentIndex);
- //var datacard = item.getAttribute('datacard');
- datacardUtils.DeleteDatacard(currentDatacard);
- currentDatacard = null;
- currentDatacardFile = null;
- currentDatacardIsEncrypted = false;
-
- // Since the item that was selected is now gone, and we no longer know
- // if anything is selected, the Remove buttons should be disabled
- document.getElementById('datacardRemoveButton').setAttribute('disabled', 'true');
- document.getElementById('datacardRemoveAllButton').setAttribute('disabled', 'true');
-
- // Refresh the list
- populateDatacardList();
- }
-
-
- function DeleteAllDatacards(onlyDoEncrypted) {
- datacardUtils.DeleteAllDatacards(onlyDoEncrypted);
- document.getElementById('datacardRemoveButton').setAttribute('disabled', 'true');
- document.getElementById('datacardRemoveAllButton').setAttribute('disabled', 'true');
- currentDatacard = null;
- currentDatacardFile = null;
- currentDatacardIsEncrypted = false;
- populateDatacardList();
- }
-
-
- function DeleteBlacklistSite() {
- // Unlist the site
- var tree = document.getElementById('datacardRejectsTree');
- var item = tree.contentView.getItemAtIndex(tree.currentIndex);
- var host = item.getAttribute('host');
- datacardUtils.UnlistSite(host);
-
- // Since the item that was selected is now gone, and we no longer know
- // if anything is selected, the Remove buttons should be disabled
- document.getElementById('datacardRemoveButton').setAttribute('disabled', 'true');
- document.getElementById('datacardRemoveAllButton').setAttribute('disabled', 'true');
-
- // Refresh the list
- populateBlacklist();
- }
-
-
- function ClearBlacklist() {
- var blacklist = datacardUtils.GetBlacklistedSites();
- for (var i = 0; i < blacklist.length; i++) {
- datacardUtils.UnlistSite(blacklist[i]);
- }
- document.getElementById('datacardRemoveButton').setAttribute('disabled', 'true');
- document.getElementById('datacardRemoveAllButton').setAttribute('disabled', 'true');
- populateBlacklist();
- }
-
-
- function SetDatacardAsDefault() {
- afDebug('SetDatacardAsDefault()');
- var tree = document.getElementById('datacardTree');
- //var item = tree.contentView.getItemAtIndex(tree.currentIndex);
- //var datacard = item.getAttribute('datacard');
- datacardUtils.SetDefaultDatacard(currentDatacard);
- var index = tree.currentIndex;
- populateDatacardList();
- tree.view.selection.select(index);
- }
-
-
- /**
- * Handle Ok event
- **/
- function onAutoFillOK()
- {
- //afDebug("onAutoFillOK()");
- // if this is not the page displayed, don't continue
- var theTabBox = document.getElementById("autofilltabbox");
- if (!theTabBox || theTabBox.selectedTab.id != "formfilltab")
- return;
-
- if (reScanForm()) {
- afDebug("rescan:"+reScanForm()+"\n");
- saveDatacard();
- }
- }
-
-
- function setTab()
- {
- kPREFContractID = "@mozilla.org/preferences-service;1";
- kPBIID = Components.interfaces.nsIPrefBranch;
-
- var prefServ = Components.classes[kPREFContractID].getService(kPBIID);
- var selectedTabId = prefServ.getCharPref('browser.preferences.formfillORpasscard');
- dump("THE SELECTED TAB IS: " +selectedTabId+ "\n");
- var theTabBox = document.getElementById("autofilltabbox");
- var theTab = document.getElementById(selectedTabId);
- theTabBox.selectedTab = theTab;
- }
-
- var gCurrentRadioSelection = null;
- function afillRadioChange(radiobutton)
- {
- dump("IN afillRadioChange: \n");
- if ((radiobutton.getAttribute("id") == "PriAddr")
- && (radiobutton.getAttribute("selected") == "true"))
- {
- if (gCurrentRadioSelection && (gCurrentRadioSelection == 'PriAddr')) {
- // do nothing... this radio is already selected
- } else {
- priSelected();
- gCurrentRadioSelection = 'PriAddr';
- }
- } else {
- if (gCurrentRadioSelection && (gCurrentRadioSelection == 'AltAddr')) {
- // do nothing... this radio is already selected
- } else {
- altSelected();
- gCurrentRadioSelection = 'AltAddr';
- }
- }
- }
-
- function priSelected()
- { dump("ENTERING PRIMAY SELECTGED \n");
- if (removeAllFlag == true && clearFormDataCount < 2)
- {
- dump("PRIMAY WARNING CLEARING ALL DATA");
- refreshFormData();
- processPrimaryData();
- removeAllFlag = false;
- clearFormDataCount = clearFormDataCount + 1;
- }
- else
- {
- processPrimaryData();
-
- removeAllFlag = false;
- clearFormDataCount = 0;
- }
- saveAddressData();
-
- } //END priSelected
-
- function altSelected()
- {
- dump("ENTERING ALTERNATE SELECTGED \n");
- if (removeAllFlag == true && clearFormDataCount < 2)
- {
- dump("ALTERNATE-WARNING CLEARING ALL DATA");
- refreshFormData();
- processAlternateData();
- removeAllFlag = false;
- clearFormDataCount = clearFormDataCount + 1;
- }
- else
- {
- processAlternateData();
- removeAllFlag = false;
- clearFormDataCount = 0;
- }
- saveAddressData();
- } // function altSelected
-
- function creditCardPassword()
- {
- window.openDialog("chrome://mozapps/content/autofill/CCardPwdDialog.xul", "_blank",
- "chrome,dialog,modal");
- }
-
- function checkPWD()
- {
- try
- {
- var propDict =
- afService.GetDatacardFieldsByType(
- currentDatacardFile, nsIAutoFillService.FIELDTYPE_PROPERTY);
- var cc_passwordCheck_val = new Object();
- cc_passwordCheck_val.value = getDictionaryValue(propDict, 'cc_password');
- dump("checking password "+cc_passwordCheck_val.value+"\n");
-
- if (cc_passwordCheck_val.value == "")
- { dump( "PASSWORD OR FILES NULL \n");
- window.openDialog("chrome://mozapps/content/autofill/CCard.xul", "_blank","chrome,dialog,modal");
- }
- else
- { dump( "creditCardPassword");
- creditCardPassword();
- }
- } //END TRY
- catch (e)
- { dump( "checkPWD has FAILED\n");
- window.openDialog("chrome://mozapps/content/autofill/CCard.xul", "_blank","chrome,dialog,modal");
- }
-
- }
-
- function setPromptStatePref()
- { kPREFContractID = "@mozilla.org/preferences-service;1";
- kPBIID = Components.interfaces.nsIPrefBranch;
- var gPrefService = Components.classes[kPREFContractID].getService(kPBIID);
- var formfilluser = document.getElementById("formfill_prompter").checked;
- //alert (formfilluser);
- // FALSE = CHECKED XUL ELEMENT and TRUE = UNCHECKED XUL ELEMENT
- var userprompt;
- if (!formfilluser)
- userprompt = gPrefService.setBoolPref("formfill.user.prompt",true);
- else
- userprompt = gPrefService.setBoolPref("formfill.user.prompt",false);
-
- }
-
- function OnTabSelect()
- {
- var theTabs = document.getElementById("formfill-passcard-tabs");
- if (!theTabs)
- return;
-
- var theTab = theTabs.selectedItem;
- if (!theTab)
- return;
-
- /* TODO JVL - remove if no longer necessary
- if (theTab.id == "passcardtab")
- {
- // if the user cannot access the passcard panel due to
- // an incorrect password, select the form fill panel
- if (!SelectPasscardPanel(theTab))
- {
- theTabs.advanceSelectedTab(-1);
- }
- }
- */
-
- // HACK: don't save the preference until the page has been fully initialized
- // because OnTabSelect() will be called before Startup()
- if (gTabSelectInit)
- {
- // set as the last visted tab
- var prefServ = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch);
-
- // ensure we retrieve the current tab
- theTab = theTabs.selectedItem;
- if (theTab)
- prefServ.setCharPref('browser.preferences.formfillORpasscard', theTab.id);
- }
- }
-
- function removeFormFillData()
- {
- removeAllFlag = true;
- clearFormFillData();
- saveDatacard(); //clear buffer
-
- saveDatacardField('cc_name', '');
- saveDatacardField('cc_nunber', '');
- saveDatacardField('cc_type', '');
- saveDatacardField('cc_expire_month', '');
- saveDatacardField('cc_expire_year', '');
- saveDatacardField('cc_password', '');
- }
-
- function clearFormFillData()
- {
- document.getElementById("Title").value = "";
- document.getElementById("FirstName").value = "";
- document.getElementById("LastName").value = "";
- document.getElementById("EmailAddr").value = "";
- document.getElementById("PhoneNum").value = "";
- document.getElementById("WorkPhoneNum").value = "";
-
- document.getElementById("StrAddr").value = "";
- document.getElementById("StrAddr2").value = "";
- document.getElementById("City").value = "";
- document.getElementById("State").value = "";
- document.getElementById("ZipCode").value = "";
- document.getElementById("countryList").value = "United States";
-
- alt_street_val.value="";
- alt_street2_val.value="";
- alt_city_val.value="";
- alt_zip_val.value="";
- alt_state_val.value="";
- alt_country_val.value="";
- street.value="";
- street_val.value="";;
- street2.value="";
- street2_val.value="";
- city.value="";
- city_val.value="";;
- zip.value="";
- zip_val.value="";
- state.value="";
- state_val.value="";
- country.value="";
- country_val.value="";
- }
-
-
- function reScanForm()
- {
- FFtitle=document.getElementById("Title");
- if (FFtitle.value != "") return true;
-
- fname=document.getElementById("FirstName");
- if (fname.value != "") return true;
-
- lname=document.getElementById("LastName");
- if (lname.value != "") return true;
-
- email=document.getElementById("EmailAddr");
- if (email.value != "") return true;
-
- phone=document.getElementById("PhoneNum");
- if (phone.value != "") return true;
-
- workphone=document.getElementById("WorkPhoneNum");
- if (workphone.value != "") return true;
-
- street=document.getElementById("StrAddr");
- if (street.value != "") return true;
-
- street2=document.getElementById("StrAddr2");
- if (street2.value != "") return true;
-
- city = document.getElementById("City");
- if (city.value != "") return true;
-
- state=document.getElementById("State");
- if (state.value != "") return true;
-
- zip=document.getElementById("ZipCode");
- if (zip.value != "") return true;
-
- country=document.getElementById("countryList");
- if (country.value != "") return true;
-
- dcardLabel = document.getElementById("datacardName");
- if (dcardLabel.value != "") return true;
-
- datacardAutofillList = document.getElementById("datacardAutofillList");
- if (datacardAutofillList.value != "") return true;
-
- dcardProtect = document.getElementById("dcProtect");
- if (dcardProtect.value != "") return true;
-
- return false;
- }
-
- function refreshFormData()
- {
- street=document.getElementById("StrAddr");
- street2=document.getElementById("StrAddr2");
- city = document.getElementById("City");
- state=document.getElementById("State");
- zip=document.getElementById("ZipCode");
- country=document.getElementById("countryList");
- }
-
- function processPrimaryData()
- { //save alt address values
- alt_street_val.value=street.value;
- alt_street2_val.value=street2.value;
- alt_city_val.value=city.value;
- alt_zip_val.value=zip.value;
- alt_state_val.value=state.value;
- alt_country_val.value=country.value;
- //update UI
- street.value=street_val.value;
- street2.value=street2_val.value;
- city.value=city_val.value;
- zip.value=zip_val.value;
- state.value=state_val.value;
- country.value=country_val.value;
- }
- function processAlternateData()
- { //save pri address values
- street_val.value=street.value;
- street2_val.value=street2.value;
- city_val.value=city.value;
- zip_val.value=zip.value;
- state_val.value=state.value;
- country_val.value=country.value;
- //update UI
- street.value=alt_street_val.value;
- street2.value=alt_street2_val.value;
- city.value=alt_city_val.value;
- zip.value=alt_zip_val.value;
- state.value=alt_state_val.value;
- country.value=alt_country_val.value;
- }
-
- function saveAddressData()
- {
- FFtitle_val.value = FFtitle.value;
- fname_val.value = fname.value;
- lname_val.value = lname.value;
- email_val.value = email.value;
- phone_val.value = phone.value;
- workphone_val.value = workphone.value;
-
- var vtrue="true";
- var vfalse="false";
-
- var pri=primary.selected;
- if(pri.toString()==vtrue.toString())
- {
- street_val.value=street.value;
- street2_val.value = street2.value;
- city_val.value= city.value;
- zip_val.value = zip.value;
- state_val.value = state.value;
- country_val.value = country.value;
- }
- else
- {
- alt_street_val.value=street.value;
- alt_street2_val.value=street2.value;
- alt_city_val.value= city.value;
- alt_zip_val.value = zip.value;
- alt_state_val.value = state.value;
- alt_country_val.value = country.value;
- }
- primary=document.getElementById("PriAddr");
- alternative=document.getElementById("AltAddr");
-
- saveDatacardField('title', FFtitle_val.value);
- saveDatacardField('firstname', fname_val.value);
- saveDatacardField('lastname', lname_val.value);
- saveDatacardField('email', email_val.value);
- saveDatacardField('phone', phone_val.value);
- saveDatacardField('work_phone', workphone_val.value);
-
- saveDatacardField('street', street_val.value);
- saveDatacardField('street2', street2_val.value);
- saveDatacardField('city', city_val.value);
- saveDatacardField('zip', zip_val.value);
- saveDatacardField('state', state_val.value);
- saveDatacardField('country', country_val.value);
-
- saveDatacardField('alt_street', alt_street_val.value);
- saveDatacardField('alt_street2', alt_street2_val.value);
- saveDatacardField('alt_city', alt_city_val.value);
- saveDatacardField('alt_zip', alt_zip_val.value);
- saveDatacardField('alt_state', alt_state_val.value);
- saveDatacardField('alt_country', alt_country_val.value);
- }
-
- //the following are prototype for now...
- function OndatacardPrefTabSelect() {}
-
- function dataCardAutoSaveChange()
- {
- dump('*** changing prompt checkbox\n');
- var bAutoSave = document.getElementById('dcAutosave').checked;
- document.getElementById('dcAutosavePrompt').disabled = (!bAutoSave);
- }
-
- //-------END AUTOFILL/FORMFILL--------------------
-