/* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ /* import-globals-from ../../../../../browser/extensions/formautofill/content/autofillEditForms.js*/ import AcceptedCards from "../components/accepted-cards.js"; import BillingAddressPicker from "./billing-address-picker.js"; import CscInput from "../components/csc-input.js"; import LabelledCheckbox from "../components/labelled-checkbox.js"; import PaymentRequestPage from "../components/payment-request-page.js"; import PaymentStateSubscriberMixin from "../mixins/PaymentStateSubscriberMixin.js"; import paymentRequest from "../paymentRequest.js"; import HandleEventMixin from "../mixins/HandleEventMixin.js"; /* import-globals-from ../unprivileged-fallbacks.js */ /** * * * XXX: Bug 1446164 - This form isn't localized when used via this custom element * as it will be much easier to share the logic once we switch to Fluent. */ export default class BasicCardForm extends HandleEventMixin( PaymentStateSubscriberMixin(PaymentRequestPage) ) { constructor() { super(); this.genericErrorText = document.createElement("div"); this.genericErrorText.setAttribute("aria-live", "polite"); this.genericErrorText.classList.add("page-error"); this.cscInput = new CscInput({ useAlwaysVisiblePlaceholder: true, inputId: "cc-csc", }); this.persistCheckbox = new LabelledCheckbox(); // The persist checkbox shouldn't be part of the record which gets saved so // exclude it from the form. this.persistCheckbox.form = ""; this.persistCheckbox.className = "persist-checkbox"; this.acceptedCardsList = new AcceptedCards(); // page footer this.cancelButton = document.createElement("button"); this.cancelButton.className = "cancel-button"; this.cancelButton.addEventListener("click", this); this.backButton = document.createElement("button"); this.backButton.className = "back-button"; this.backButton.addEventListener("click", this); this.saveButton = document.createElement("button"); this.saveButton.className = "save-button primary"; this.saveButton.addEventListener("click", this); this.footer.append(this.cancelButton, this.backButton, this.saveButton); // The markup is shared with form autofill preferences. let url = "formautofill/editCreditCard.xhtml"; this.promiseReady = this._fetchMarkup(url).then(doc => { this.form = doc.getElementById("form"); return this.form; }); } _fetchMarkup(url) { return new Promise((resolve, reject) => { let xhr = new XMLHttpRequest(); xhr.responseType = "document"; xhr.addEventListener("error", reject); xhr.addEventListener("load", evt => { resolve(xhr.response); }); xhr.open("GET", url); xhr.send(); }); } _upgradeBillingAddressPicker() { let addressRow = this.form.querySelector(".billingAddressRow"); let addressPicker = (this.billingAddressPicker = new BillingAddressPicker()); // Wrap the existing