1 let querystring = require('querystring')
2 let stream_buffers = require('stream-buffers')
5 //let account = await _require('/account.jst')
6 let breadcrumbs = await _require('/breadcrumbs.jst')
7 let menu = await env.site.get_menu('/my_account/_menu.json')
8 let navbar = await _require('/navbar.jst')
16 await breadcrumbs(env, _out)
18 //if (Object.prototype.hasOwnProperty.call(env, 'account')) {
20 // div.panel.panel-default.margin-x-xl {
21 // div.panel-heading {'Your name'}
23 // form#change-name-form(method="post" action="index.html" role="form") {
27 // label(for="change-name-form-given-names") {'Given names *'}
28 // 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 || "") {}
29 // div.help-block.with-errors {}
34 // label(for="change-name-form-family-name") {'Family name'}
35 // input.form-control#change-name-form-family-name(type="text" name="family-name" placeholder="Your family name" value=env.account.family_name || "") {}
36 // div.help-block.with-errors {}
40 // 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.'}
43 // input.btn.btn-success.btn-send(type="submit" value="Change") {}
50 // div.panel.panel-default.margin-x-xl {
51 // div.panel-heading {'Your billing address'}
53 // form#change-billing-address-form(method="post" action="index.html" role="form") {
57 // label(for="change-billing-address-form-name") {'Name *'}
58 // 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 || "") {}
59 // div.help-block.with-errors {}
66 // label(for="change-billing-address-form-company") {'Company'}
67 // input.form-control#change-billing-address-form-company(type="text" name="billing-company" value=env.account.billing_address.company || "") {}
68 // div.help-block.with-errors {}
75 // label(for="change-billing-address-form-line-1") {'Address line 1 *'}
76 // 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 || "") {}
77 // div.help-block.with-errors {}
84 // label(for="change-billing-address-form-line-2") {'Address line 2'}
85 // input.form-control#change-billing-address-form-line-2(type="text" name="billing-line-2" value=env.account.billing_address.line_2 || "") {}
86 // div.help-block.with-errors {}
93 // label(for="change-billing-address-form-city") {'City *'}
94 // 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 || "") {}
95 // div.help-block.with-errors {}
100 // label(for="change-billing-address-form-state") {'State'}
101 // input.form-control#change-billing-address-form-state(type="text" name="billing-state" placeholder="AZ" value=env.account.billing_address.state || "") {}
102 // div.help-block.with-errors {}
107 // label(for="change-billing-address-form-postal-code") {'Postal code'}
108 // input.form-control#change-billing-address-form-postal-code(type="text" name="billing-postal-code" placeholder="85123" value=env.account.billing_address.postal_code || "") {}
109 // div.help-block.with-errors {}
116 // label(for="change-billing-address-form-country") {'Country *'}
117 // 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 || "") {}
118 // div.help-block.with-errors {}
125 // label(for="change-billing-address-form-telephone") {'Telephone *'}
126 // 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 || "") {}
127 // div.help-block.with-errors {}
133 // input.btn.btn-success.btn-send(type="submit" value="Change") {}
140 // div.panel.panel-default.margin-x-xl {
141 // div.panel-heading {'Your shipping address'}
143 // form#change-shipping-address-form(method="post" action="index.html" role="form") {
147 // input.form-check-input#sign-up-form-shipping-same-as-billing(type="checkbox" name="shipping-same-as-billing" checked="checked") {}
149 // label(for="sign-up-form-shipping-same-as-billing") {
150 // 'Same as billing address'
158 // label(for="change-shipping-address-form-name") {'Name *'}
159 // 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 || "") {}
160 // div.help-block.with-errors {}
167 // label(for="change-shipping-address-form-company") {'Company'}
168 // input.form-control#change-shipping-address-form-company(type="text" name="shipping-company" value=env.account.shipping_address.company || "") {}
169 // div.help-block.with-errors {}
176 // label(for="change-shipping-address-form-line-1") {'Address line 1 *'}
177 // 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 || "") {}
178 // div.help-block.with-errors {}
185 // label(for="change-shipping-address-form-line-2") {'Address line 2'}
186 // input.form-control#change-shipping-address-form-line-2(type="text" name="shipping-line-2" value=env.account.shipping_address.line_2 || "") {}
187 // div.help-block.with-errors {}
194 // label(for="change-shipping-address-form-city") {'City *'}
195 // 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 || "") {}
196 // div.help-block.with-errors {}
201 // label(for="change-shipping-address-form-state") {'State'}
202 // input.form-control#change-shipping-address-form-state(type="text" name="shipping-state" placeholder="AZ" value=env.account.shipping_address.state || "") {}
203 // div.help-block.with-errors {}
208 // label(for="change-shipping-address-form-postal-code") {'Postal code'}
209 // input.form-control#change-shipping-address-form-postal-code(type="text" name="shipping-postal-code" placeholder="85123" value=env.account.shipping_address.postal_code || "") {}
210 // div.help-block.with-errors {}
217 // label(for="change-shipping-address-form-country") {'Country *'}
218 // 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 || "") {}
219 // div.help-block.with-errors {}
226 // label(for="change-shipping-address-form-telephone") {'Telephone *'}
227 // 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 || "") {}
228 // div.help-block.with-errors {}
234 // input.btn.btn-success.btn-send(type="submit" value="Change") {}
241 // div.panel.panel-default.margin-x-xl {
242 // div.panel-heading {'Your password'}
244 // form#change-password-form(method="post" action="index.html" role="form") {
248 // label(for="change-password-form-old-password") {'Old password *'}
249 // input.form-control#change-password-form-old-password(type="password" name="old-password" required="required" placeholder="Old password" data-error="Old password is required.") {}
250 // div.help-block.with-errors {}
255 // label(for="change-password-form-new-password") {'New password *'}
256 // input.form-control#'change-password-form-new-password'(type="password" name="new-password" required="required" placeholder="New password" data-error="New password is required.") {}
257 // div.help-block.with-errors {}
263 // input.btn.btn-success.btn-send(type="submit" value="Change") {}
270 // div.panel.panel-default.margin-x-xl {
271 // div.panel-heading {'Your contact preference'}
273 // form#change-contact-preference-form(method="post" action="index.html" role="form") {
277 // if (env.account.contact_me)
278 // input.form-check-input#change-contact-preference-form-contact-me(type="checkbox" name="contact-me" checked="checked") {}
280 // input.form-check-input#change-contact-preference-form-contact-me(type="checkbox" name="contact-me") {}
282 // label(for="change-contact-preference-form-contact-me") {
283 // 'Contact me by email with updates and special offers'
290 // input.btn.btn-success.btn-send(type="submit" value="Change") {}
301 // 'These fields are required.'
308 p {'For account maintenance, please click on one of the options below.'}
311 let entries = menu.entries
312 for (let i = 0; i < entries.length; ++i) {
313 let entry = entries[i]
314 if (Object.prototype.hasOwnProperty.call(entry, 'icon'))
316 a.nav-link(href=`${entry.dir}/index.html`) {
317 table.icon-and-text {
320 _out.push(await env.site.get_min_svg(entry.icon))
323 span.h2{`${entry.name}`}
336 // this will be called by navbar logic after sign in/out
337 function sign_in_out(status) {
338 window.location.reload()
343 // when change name form is submitted, do not reload the page
355 'given-names': $('#change-name-form-given-names').val(),
356 'family-name': $('#change-name-form-family-name').val()
358 success: (data, textStatus, jqXHR) => {
359 $('#message-modal-message').text(data)
360 $('#message-modal').modal('show')
362 error: (jqXHR, textStatus, errorThrown) => {
363 $('#message-modal-message').text(errorThrown)
364 $('#message-modal').modal('show')
371 // when change billing address form is submitted, do not reload the page
374 '#change-billing-address-form',
382 what: 'billing-address',
383 name: $('#change-billing-address-form-name').val(),
384 company: $('#change-billing-address-form-company').val(),
385 'line-1': $('#change-billing-address-form-line-1').val(),
386 'line-2': $('#change-billing-address-form-line-2').val(),
387 city: $('#change-billing-address-form-city').val(),
388 state: $('#change-billing-address-form-state').val(),
389 'postal-code': $('#change-billing-address-form-postal-code').val(),
390 country: $('#change-billing-address-form-country').val(),
391 telephone: $('#change-billing-address-form-telephone').val()
393 success: (data, textStatus, jqXHR) => {
394 $('#message-modal-message').text(data)
395 $('#message-modal').modal('show')
397 error: (jqXHR, textStatus, errorThrown) => {
398 $('#message-modal-message').text(errorThrown)
399 $('#message-modal').modal('show')
406 // when change shipping address form is submitted, do not reload the page
409 '#change-shipping-address-form',
417 what: 'shipping-address',
418 name: $('#change-shipping-address-form-name').val(),
419 company: $('#change-shipping-address-form-company').val(),
420 'line-1': $('#change-shipping-address-form-line-1').val(),
421 'line-2': $('#change-shipping-address-form-line-2').val(),
422 city: $('#change-shipping-address-form-city').val(),
423 state: $('#change-shipping-address-form-state').val(),
424 'postal-code': $('#change-shipping-address-form-postal-code').val(),
425 country: $('#change-shipping-address-form-country').val(),
426 telephone: $('#change-shipping-address-form-telephone').val()
428 success: (data, textStatus, jqXHR) => {
429 $('#message-modal-message').text(data)
430 $('#message-modal').modal('show')
432 error: (jqXHR, textStatus, errorThrown) => {
433 $('#message-modal-message').text(errorThrown)
434 $('#message-modal').modal('show')
441 // when change password form is submitted, do not reload the page
444 '#change-password-form',
453 'old-password': $('#change-password-form-old-password').val(),
454 'new-password': $('#change-password-form-new-password').val(),
456 success: (data, textStatus, jqXHR) => {
457 $('#message-modal-message').text(data)
458 $('#message-modal').modal('show')
460 error: (jqXHR, textStatus, errorThrown) => {
461 $('#message-modal-message').text(errorThrown)
462 $('#message-modal').modal('show')
470 // when change contact preference form is submitted, do not reload the page
473 '#change-contact-preference-form',
481 what: 'contact-preference',
482 'contact-me': $('#change-contact-preference-form-contact-me').prop('checked')
484 success: (data, textStatus, jqXHR) => {
485 $('#message-modal-message').text(data)
486 $('#message-modal').modal('show')
488 error: (jqXHR, textStatus, errorThrown) => {
489 $('#message-modal-message').text(errorThrown)
490 $('#message-modal').modal('show')