+let querystring = require('querystring')
+let stream_buffers = require('stream-buffers')
+
+return async env => {
+ //let account = await _require('/account.jst')
+ let breadcrumbs = await _require('/breadcrumbs.jst')
+ let menu = await env.site.get_menu('/my_account/_menu.json')
+ let navbar = await _require('/navbar.jst')
+
+ await navbar(
+ env,
+ // head
+ async _out => {},
+ // body
+ async _out => {
+ await breadcrumbs(env, _out)
+
+ //if (Object.prototype.hasOwnProperty.call(env, 'account')) {
+ // // signed in
+ // div.panel.panel-default.margin-x-xl {
+ // div.panel-heading {'Your name'}
+ // div.panel-body {
+ // form#change-name-form(method="post" action="index.html" role="form") {
+ // div.row {
+ // div.col-md-6 {
+ // div.form-group {
+ // label(for="change-name-form-given-names") {'Given names *'}
+ // input.form-control#change-name-form-given-names(type="text" name="given-names" required="required" placeholder="Your given names" data-error="Given names are required." value=env.account.given_names || "") {}
+ // div.help-block.with-errors {}
+ // }
+ // }
+ // div.col-md-6 {
+ // div.form-group {
+ // label(for="change-name-form-family-name") {'Family name'}
+ // input.form-control#change-name-form-family-name(type="text" name="family-name" placeholder="Your family name" value=env.account.family_name || "") {}
+ // div.help-block.with-errors {}
+ // }
+ // }
+ // }
+ // p {'Note: If your name is one word or does not fit given names/family name pattern, then please enter given names only; we will address you by your given names. Your given names will be visible to other users if you comment on our blog. Your email and family name will remain private.'}
+ // div.row {
+ // div.col-md-12 {
+ // input.btn.btn-success.btn-send(type="submit" value="Change") {}
+ // }
+ // }
+ // }
+ // }
+ // }
+//
+ // div.panel.panel-default.margin-x-xl {
+ // div.panel-heading {'Your billing address'}
+ // div.panel-body {
+ // form#change-billing-address-form(method="post" action="index.html" role="form") {
+ // div.row {
+ // div.col-md-12 {
+ // div.form-group {
+ // label(for="change-billing-address-form-name") {'Name *'}
+ // input.form-control#change-billing-address-form-name(type="text" name="billing-name" required="required" placeholder="Jane Roe" data-error="Name is required." value=env.account.billing_address.name || "") {}
+ // div.help-block.with-errors {}
+ // }
+ // }
+ // }
+ // div.row {
+ // div.col-md-12 {
+ // div.form-group {
+ // label(for="change-billing-address-form-company") {'Company'}
+ // input.form-control#change-billing-address-form-company(type="text" name="billing-company" value=env.account.billing_address.company || "") {}
+ // div.help-block.with-errors {}
+ // }
+ // }
+ // }
+ // div.row {
+ // div.col-md-12 {
+ // div.form-group {
+ // label(for="change-billing-address-form-line-1") {'Address line 1 *'}
+ // input.form-control#change-billing-address-form-line-1(type="text" name="billing-line-1" required="required" placeholder="100 Main St" data-error="Address line 1 is required." value=env.account.billing_address.line_1 || "") {}
+ // div.help-block.with-errors {}
+ // }
+ // }
+ // }
+ // div.row {
+ // div.col-md-12 {
+ // div.form-group {
+ // label(for="change-billing-address-form-line-2") {'Address line 2'}
+ // input.form-control#change-billing-address-form-line-2(type="text" name="billing-line-2" value=env.account.billing_address.line_2 || "") {}
+ // div.help-block.with-errors {}
+ // }
+ // }
+ // }
+ // div.row {
+ // div.col-md-6 {
+ // div.form-group {
+ // label(for="change-billing-address-form-city") {'City *'}
+ // input.form-control#change-billing-address-form-city(type="text" name="billing-city" placeholder="Phoenix" required="required" data-error="City is required." value=env.account.billing_address.city || "") {}
+ // div.help-block.with-errors {}
+ // }
+ // }
+ // div.col-md-3 {
+ // div.form-group {
+ // label(for="change-billing-address-form-state") {'State'}
+ // input.form-control#change-billing-address-form-state(type="text" name="billing-state" placeholder="AZ" value=env.account.billing_address.state || "") {}
+ // div.help-block.with-errors {}
+ // }
+ // }
+ // div.col-md-3 {
+ // div.form-group {
+ // label(for="change-billing-address-form-postal-code") {'Postal code'}
+ // input.form-control#change-billing-address-form-postal-code(type="text" name="billing-postal-code" placeholder="85123" value=env.account.billing_address.postal_code || "") {}
+ // div.help-block.with-errors {}
+ // }
+ // }
+ // }
+ // div.row {
+ // div.col-md-12 {
+ // div.form-group {
+ // label(for="change-billing-address-form-country") {'Country *'}
+ // input.form-control#change-billing-address-form-country(type="text" name="billing-country" required="required" placeholder="USA" data-error="Country is required." value=env.account.billing_address.country || "") {}
+ // div.help-block.with-errors {}
+ // }
+ // }
+ // }
+ // div.row {
+ // div.col-md-12 {
+ // div.form-group {
+ // label(for="change-billing-address-form-telephone") {'Telephone *'}
+ // input.form-control#change-billing-address-form-telephone(type="text" name="billing-telephone" required="required" placeholder="+1-123-456-7890" data-error="Telephone is required." value=env.account.billing_address.telephone || "") {}
+ // div.help-block.with-errors {}
+ // }
+ // }
+ // }
+ // div.row {
+ // div.col-md-12 {
+ // input.btn.btn-success.btn-send(type="submit" value="Change") {}
+ // }
+ // }
+ // }
+ // }
+ // }
+//
+ // div.panel.panel-default.margin-x-xl {
+ // div.panel-heading {'Your shipping address'}
+ // div.panel-body {
+ // form#change-shipping-address-form(method="post" action="index.html" role="form") {
+ // div.row {
+ // div.col-md-12 {
+ // div.form-check {
+ // input.form-check-input#sign-up-form-shipping-same-as-billing(type="checkbox" name="shipping-same-as-billing" checked="checked") {}
+ // ' '
+ // label(for="sign-up-form-shipping-same-as-billing") {
+ // 'Same as billing address'
+ // }
+ // }
+ // }
+ // }
+ // div.row {
+ // div.col-md-12 {
+ // div.form-group {
+ // label(for="change-shipping-address-form-name") {'Name *'}
+ // input.form-control#change-shipping-address-form-name(type="text" name="shipping-name" required="required" placeholder="Jane Roe" data-error="Name is required." value=env.account.shipping_address.name || "") {}
+ // div.help-block.with-errors {}
+ // }
+ // }
+ // }
+ // div.row {
+ // div.col-md-12 {
+ // div.form-group {
+ // label(for="change-shipping-address-form-company") {'Company'}
+ // input.form-control#change-shipping-address-form-company(type="text" name="shipping-company" value=env.account.shipping_address.company || "") {}
+ // div.help-block.with-errors {}
+ // }
+ // }
+ // }
+ // div.row {
+ // div.col-md-12 {
+ // div.form-group {
+ // label(for="change-shipping-address-form-line-1") {'Address line 1 *'}
+ // input.form-control#change-shipping-address-form-line-1(type="text" name="shipping-line-1" required="required" placeholder="100 Main St" data-error="Address line 1 is required." value=env.account.shipping_address.line_1 || "") {}
+ // div.help-block.with-errors {}
+ // }
+ // }
+ // }
+ // div.row {
+ // div.col-md-12 {
+ // div.form-group {
+ // label(for="change-shipping-address-form-line-2") {'Address line 2'}
+ // input.form-control#change-shipping-address-form-line-2(type="text" name="shipping-line-2" value=env.account.shipping_address.line_2 || "") {}
+ // div.help-block.with-errors {}
+ // }
+ // }
+ // }
+ // div.row {
+ // div.col-md-6 {
+ // div.form-group {
+ // label(for="change-shipping-address-form-city") {'City *'}
+ // input.form-control#change-shipping-address-form-city(type="text" name="shipping-city" placeholder="Phoenix" required="required" data-error="City is required." value=env.account.shipping_address.city || "") {}
+ // div.help-block.with-errors {}
+ // }
+ // }
+ // div.col-md-3 {
+ // div.form-group {
+ // label(for="change-shipping-address-form-state") {'State'}
+ // input.form-control#change-shipping-address-form-state(type="text" name="shipping-state" placeholder="AZ" value=env.account.shipping_address.state || "") {}
+ // div.help-block.with-errors {}
+ // }
+ // }
+ // div.col-md-3 {
+ // div.form-group {
+ // label(for="change-shipping-address-form-postal-code") {'Postal code'}
+ // input.form-control#change-shipping-address-form-postal-code(type="text" name="shipping-postal-code" placeholder="85123" value=env.account.shipping_address.postal_code || "") {}
+ // div.help-block.with-errors {}
+ // }
+ // }
+ // }
+ // div.row {
+ // div.col-md-12 {
+ // div.form-group {
+ // label(for="change-shipping-address-form-country") {'Country *'}
+ // input.form-control#change-shipping-address-form-country(type="text" name="shipping-country" required="required" placeholder="USA" data-error="Country is required." value=env.account.shipping_address.country || "") {}
+ // div.help-block.with-errors {}
+ // }
+ // }
+ // }
+ // div.row {
+ // div.col-md-12 {
+ // div.form-group {
+ // label(for="change-shipping-address-form-telephone") {'Telephone *'}
+ // input.form-control#change-shipping-address-form-telephone(type="text" name="shipping-telephone" required="required" placeholder="+1-123-456-7890" data-error="Telephone is required." value=env.account.shipping_address.telephone || "") {}
+ // div.help-block.with-errors {}
+ // }
+ // }
+ // }
+ // div.row {
+ // div.col-md-12 {
+ // input.btn.btn-success.btn-send(type="submit" value="Change") {}
+ // }
+ // }
+ // }
+ // }
+ // }
+//
+ // div.panel.panel-default.margin-x-xl {
+ // div.panel-heading {'Your password'}
+ // div.panel-body {
+ // form#change-password-form(method="post" action="index.html" role="form") {
+ // div.row {
+ // div.col-md-6 {
+ // div.form-group {
+ // label(for="change-password-form-old-password") {'Old password *'}
+ // input.form-control#change-password-form-old-password(type="password" name="old-password" required="required" placeholder="Old password" data-error="Old password is required.") {}
+ // div.help-block.with-errors {}
+ // }
+ // }
+ // div.col-md-6 {
+ // div.form-group {
+ // label(for="change-password-form-new-password") {'New password *'}
+ // input.form-control#'change-password-form-new-password'(type="password" name="new-password" required="required" placeholder="New password" data-error="New password is required.") {}
+ // div.help-block.with-errors {}
+ // }
+ // }
+ // }
+ // div.row {
+ // div.col-md-12 {
+ // input.btn.btn-success.btn-send(type="submit" value="Change") {}
+ // }
+ // }
+ // }
+ // }
+ // }
+//
+ // div.panel.panel-default.margin-x-xl {
+ // div.panel-heading {'Your contact preference'}
+ // div.panel-body {
+ // form#change-contact-preference-form(method="post" action="index.html" role="form") {
+ // div.row {
+ // div.col-md-12 {
+ // div.form-group {
+ // if (env.account.contact_me)
+ // input.form-check-input#change-contact-preference-form-contact-me(type="checkbox" name="contact-me" checked="checked") {}
+ // else
+ // input.form-check-input#change-contact-preference-form-contact-me(type="checkbox" name="contact-me") {}
+ // ' '
+ // label(for="change-contact-preference-form-contact-me") {
+ // 'Contact me by email with updates and special offers'
+ // }
+ // }
+ // }
+ // }
+ // div.row {
+ // div.col-md-12 {
+ // input.btn.btn-success.btn-send(type="submit" value="Change") {}
+ // }
+ // }
+ // }
+ // }
+ // }
+//
+ // div.row {
+ // div.col-md-12 {
+ // p.text-muted {
+ // strong {'*'}
+ // 'These fields are required.'
+ // }
+ // }
+ // }
+ //}
+ //else {
+ // signed out
+ p {'For account maintenance, please click on one of the options below.'}
+
+ ul.nav.nav-stacked {
+ let entries = menu.entries
+ for (let i = 0; i < entries.length; ++i) {
+ let entry = entries[i]
+ if (Object.prototype.hasOwnProperty.call(entry, 'icon'))
+ li {
+ a(href=`${entry.dir}/index.html`) {
+ table.icon-and-text {
+ tr {
+ td {
+ _out.push(await env.site.get_min_svg(entry.icon))
+ }
+ td {
+ span.text-h2{`${entry.name}`}
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ //}
+ },
+ // scripts
+ async _out => {
+ script {
+ // this will be called by navbar logic after sign in/out
+ function sign_in_out(status) {
+ window.location.reload()
+ }
+
+ $(document).ready(
+ () => {
+ // when change name form is submitted, do not reload the page
+ $(document).on(
+ 'submit',
+ '#change-name-form',
+ e => {
+ e.preventDefault()
+ $.ajax(
+ {
+ url: 'index.html',
+ type: 'POST',
+ data: {
+ what: 'name',
+ 'given-names': $('#change-name-form-given-names').val(),
+ 'family-name': $('#change-name-form-family-name').val()
+ },
+ success: (data, textStatus, jqXHR) => {
+ $('#message-modal-message').text(data)
+ $('#message-modal').modal('show')
+ },
+ error: (jqXHR, textStatus, errorThrown) => {
+ $('#message-modal-message').text(errorThrown)
+ $('#message-modal').modal('show')
+ }
+ }
+ )
+ }
+ )
+
+ // when change billing address form is submitted, do not reload the page
+ $(document).on(
+ 'submit',
+ '#change-billing-address-form',
+ e => {
+ e.preventDefault()
+ $.ajax(
+ {
+ url: 'index.html',
+ type: 'POST',
+ data: {
+ what: 'billing-address',
+ name: $('#change-billing-address-form-name').val(),
+ company: $('#change-billing-address-form-company').val(),
+ 'line-1': $('#change-billing-address-form-line-1').val(),
+ 'line-2': $('#change-billing-address-form-line-2').val(),
+ city: $('#change-billing-address-form-city').val(),
+ state: $('#change-billing-address-form-state').val(),
+ 'postal-code': $('#change-billing-address-form-postal-code').val(),
+ country: $('#change-billing-address-form-country').val(),
+ telephone: $('#change-billing-address-form-telephone').val()
+ },
+ success: (data, textStatus, jqXHR) => {
+ $('#message-modal-message').text(data)
+ $('#message-modal').modal('show')
+ },
+ error: (jqXHR, textStatus, errorThrown) => {
+ $('#message-modal-message').text(errorThrown)
+ $('#message-modal').modal('show')
+ }
+ }
+ )
+ }
+ )
+
+ // when change shipping address form is submitted, do not reload the page
+ $(document).on(
+ 'submit',
+ '#change-shipping-address-form',
+ e => {
+ e.preventDefault()
+ $.ajax(
+ {
+ url: 'index.html',
+ type: 'POST',
+ data: {
+ what: 'shipping-address',
+ name: $('#change-shipping-address-form-name').val(),
+ company: $('#change-shipping-address-form-company').val(),
+ 'line-1': $('#change-shipping-address-form-line-1').val(),
+ 'line-2': $('#change-shipping-address-form-line-2').val(),
+ city: $('#change-shipping-address-form-city').val(),
+ state: $('#change-shipping-address-form-state').val(),
+ 'postal-code': $('#change-shipping-address-form-postal-code').val(),
+ country: $('#change-shipping-address-form-country').val(),
+ telephone: $('#change-shipping-address-form-telephone').val()
+ },
+ success: (data, textStatus, jqXHR) => {
+ $('#message-modal-message').text(data)
+ $('#message-modal').modal('show')
+ },
+ error: (jqXHR, textStatus, errorThrown) => {
+ $('#message-modal-message').text(errorThrown)
+ $('#message-modal').modal('show')
+ }
+ }
+ )
+ }
+ )
+
+ // when change password form is submitted, do not reload the page
+ $(document).on(
+ 'submit',
+ '#change-password-form',
+ e => {
+ e.preventDefault()
+ $.ajax(
+ {
+ url: 'index.html',
+ type: 'POST',
+ data: {
+ what: 'password',
+ 'old-password': $('#change-password-form-old-password').val(),
+ 'new-password': $('#change-password-form-new-password').val(),
+ },
+ success: (data, textStatus, jqXHR) => {
+ $('#message-modal-message').text(data)
+ $('#message-modal').modal('show')
+ },
+ error: (jqXHR, textStatus, errorThrown) => {
+ $('#message-modal-message').text(errorThrown)
+ $('#message-modal').modal('show')
+ }
+ }
+ )
+ }
+ )
+
+ //return
+ // when change contact preference form is submitted, do not reload the page
+ $(document).on(
+ 'submit',
+ '#change-contact-preference-form',
+ e => {
+ e.preventDefault()
+ $.ajax(
+ {
+ url: 'index.html',
+ type: 'POST',
+ data: {
+ what: 'contact-preference',
+ 'contact-me': $('#change-contact-preference-form-contact-me').prop('checked')
+ },
+ success: (data, textStatus, jqXHR) => {
+ $('#message-modal-message').text(data)
+ $('#message-modal').modal('show')
+ },
+ error: (jqXHR, textStatus, errorThrown) => {
+ $('#message-modal-message').text(errorThrown)
+ $('#message-modal').modal('show')
+ }
+ }
+ )
+ }
+ )
+ }
+ )
+ }
+ }
+ )
+}