Bug 1427954 - Pass getFormFormat to EditAddress. r=sfoster

The point of this is to remove dependencies on privileged code from autofillEditForms.js so it can
be used in the unprivileged PaymentRequest dialog. The PaymentRequest dialog will be able to inject
the privileged APIs in a different way.

MozReview-Commit-ID: 6Kzq94m5hnZ

--HG--
extra : rebase_source : 6acbc6c19677b517649dc8f500f413656e6bf711
This commit is contained in:
Matthew Noorenberghe 2018-03-14 18:11:22 -07:00
parent 20d07e9fd2
commit 97c64f8ecf
2 changed files with 15 additions and 2 deletions

View File

@ -78,6 +78,14 @@ class EditAutofillForm {
}
class EditAddress extends EditAutofillForm {
/**
* @param {HTMLElement[]} elements
* @param {object} record
* @param {object} config
* @param {string[]} config.DEFAULT_REGION
* @param {function} config.getFormFormat Function to return form layout info for a given country.
* @param {string[]} config.supportedCountries
*/
constructor(elements, record, config) {
let country = record ? record.country :
config.supportedCountries.find(supported => supported == config.DEFAULT_REGION);
@ -104,7 +112,7 @@ class EditAddress extends EditAutofillForm {
* @param {string} country
*/
formatForm(country) {
const {addressLevel1Label, postalCodeLabel, fieldsOrder} = FormAutofillUtils.getFormFormat(country);
const {addressLevel1Label, postalCodeLabel, fieldsOrder} = this.getFormFormat(country);
this._elements.addressLevel1Label.dataset.localization = addressLevel1Label;
this._elements.postalCodeLabel.dataset.localization = postalCodeLabel;
this.arrangeFields(fieldsOrder);

View File

@ -77,7 +77,11 @@
<script type="application/javascript"><![CDATA[
"use strict";
let {supportedCountries, DEFAULT_REGION} = FormAutofillUtils;
let {
DEFAULT_REGION,
getFormFormat,
supportedCountries,
} = FormAutofillUtils;
let record = window.arguments && window.arguments[0];
/* import-globals-from autofillEditForms.js */
@ -85,6 +89,7 @@
form: document.getElementById("form"),
}, record, {
DEFAULT_REGION,
getFormFormat: getFormFormat.bind(FormAutofillUtils),
supportedCountries,
});