New approach to sign up form
[ndcode_site.git] / my_account / index.html.jst
1 let querystring = require('querystring')
2 let stream_buffers = require('stream-buffers')
3
4 return async env => {
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')
9
10   await navbar(
11     env,
12     // head
13     async _out => {},
14     // body
15     async _out => {
16       await breadcrumbs(env, _out)
17
18       //if (Object.prototype.hasOwnProperty.call(env, 'account')) {
19       //  // signed in
20       //  div.panel.panel-default.margin-x-xl {
21       //    div.panel-heading {'Your name'}
22       //    div.panel-body {
23       //      form#change-name-form(method="post" action="index.html" role="form") {
24       //        div.row {
25       //          div.col-md-6 {
26       //            div.form-group {
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 {}
30       //            }
31       //          }
32       //          div.col-md-6 {
33       //            div.form-group {
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 {}
37       //            }
38       //          }
39       //        }
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.'}
41       //        div.row {
42       //          div.col-md-12 {
43       //            input.btn.btn-success.btn-send(type="submit" value="Change") {}
44       //          }
45       //        }
46       //      }
47       //    }
48       //  }
49 //
50       //  div.panel.panel-default.margin-x-xl {
51       //    div.panel-heading {'Your billing address'}
52       //    div.panel-body {
53       //      form#change-billing-address-form(method="post" action="index.html" role="form") {
54       //        div.row {
55       //          div.col-md-12 {
56       //            div.form-group {
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 {}
60       //            }
61       //          }
62       //        }
63       //        div.row {
64       //          div.col-md-12 {
65       //            div.form-group {
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 {}
69       //            }
70       //          }
71       //        }
72       //        div.row {
73       //          div.col-md-12 {
74       //            div.form-group {
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 {}
78       //            }
79       //          }
80       //        }
81       //        div.row {
82       //          div.col-md-12 {
83       //            div.form-group {
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 {}
87       //            }
88       //          }
89       //        }
90       //        div.row {
91       //          div.col-md-6 {
92       //            div.form-group {
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 {}
96       //            }
97       //          }
98       //          div.col-md-3 {
99       //            div.form-group {
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 {}
103       //            }
104       //          }
105       //          div.col-md-3 {
106       //            div.form-group {
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 {}
110       //            }
111       //          }
112       //        }
113       //        div.row {
114       //          div.col-md-12 {
115       //            div.form-group {
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 {}
119       //            }
120       //          }
121       //        }
122       //        div.row {
123       //          div.col-md-12 {
124       //            div.form-group {
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 {}
128       //            }
129       //          }
130       //        }
131       //        div.row {
132       //          div.col-md-12 {
133       //            input.btn.btn-success.btn-send(type="submit" value="Change") {}
134       //          }
135       //        }
136       //      }
137       //    }
138       //  }
139 //
140       //  div.panel.panel-default.margin-x-xl {
141       //    div.panel-heading {'Your shipping address'}
142       //    div.panel-body {
143       //      form#change-shipping-address-form(method="post" action="index.html" role="form") {
144       //        div.row {
145       //          div.col-md-12 {
146       //            div.form-check {
147       //              input.form-check-input#sign-up-form-shipping-same-as-billing(type="checkbox" name="shipping-same-as-billing" checked="checked") {}
148       //              ' '
149       //              label(for="sign-up-form-shipping-same-as-billing") {
150       //                'Same as billing address'
151       //              }
152       //            }
153       //          }
154       //        }
155       //        div.row {
156       //          div.col-md-12 {
157       //            div.form-group {
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 {}
161       //            }
162       //          }
163       //        }
164       //        div.row {
165       //          div.col-md-12 {
166       //            div.form-group {
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 {}
170       //            }
171       //          }
172       //        }
173       //        div.row {
174       //          div.col-md-12 {
175       //            div.form-group {
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 {}
179       //            }
180       //          }
181       //        }
182       //        div.row {
183       //          div.col-md-12 {
184       //            div.form-group {
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 {}
188       //            }
189       //          }
190       //        }
191       //        div.row {
192       //          div.col-md-6 {
193       //            div.form-group {
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 {}
197       //            }
198       //          }
199       //          div.col-md-3 {
200       //            div.form-group {
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 {}
204       //            }
205       //          }
206       //          div.col-md-3 {
207       //            div.form-group {
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 {}
211       //            }
212       //          }
213       //        }
214       //        div.row {
215       //          div.col-md-12 {
216       //            div.form-group {
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 {}
220       //            }
221       //          }
222       //        }
223       //        div.row {
224       //          div.col-md-12 {
225       //            div.form-group {
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 {}
229       //            }
230       //          }
231       //        }
232       //        div.row {
233       //          div.col-md-12 {
234       //            input.btn.btn-success.btn-send(type="submit" value="Change") {}
235       //          }
236       //        }
237       //      }
238       //    }
239       //  }
240 //
241       //  div.panel.panel-default.margin-x-xl {
242       //    div.panel-heading {'Your password'}
243       //    div.panel-body {
244       //      form#change-password-form(method="post" action="index.html" role="form") {
245       //        div.row {
246       //          div.col-md-6 {
247       //            div.form-group {
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 {}
251       //            }
252       //          }
253       //          div.col-md-6 {
254       //            div.form-group {
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 {}
258       //            }
259       //          }
260       //        }
261       //        div.row {
262       //          div.col-md-12 {
263       //            input.btn.btn-success.btn-send(type="submit" value="Change") {}
264       //          }
265       //        }
266       //      }
267       //    }
268       //  }
269 //
270       //  div.panel.panel-default.margin-x-xl {
271       //    div.panel-heading {'Your contact preference'}
272       //    div.panel-body {
273       //      form#change-contact-preference-form(method="post" action="index.html" role="form") {
274       //        div.row {
275       //          div.col-md-12 {
276       //            div.form-group {
277       //              if (env.account.contact_me)
278       //                input.form-check-input#change-contact-preference-form-contact-me(type="checkbox" name="contact-me" checked="checked") {}
279       //              else
280       //                input.form-check-input#change-contact-preference-form-contact-me(type="checkbox" name="contact-me") {}
281       //              ' '
282       //              label(for="change-contact-preference-form-contact-me") {
283       //                'Contact me by email with updates and special offers'
284       //              }
285       //            }
286       //          }
287       //        }
288       //        div.row {
289       //          div.col-md-12 {
290       //            input.btn.btn-success.btn-send(type="submit" value="Change") {}
291       //          }
292       //        }
293       //      }
294       //    }
295       //  }
296 //
297       //  div.row {
298       //    div.col-md-12 {
299       //      p.text-muted {
300       //        strong {'*'}
301       //        'These fields are required.'
302       //      }
303       //    }
304       //  }
305       //}
306       //else {
307         // signed out
308         p {'For account maintenance, please click on one of the options below.'}
309
310         ul.nav.nav-stacked {
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'))
315               li {
316                 a(href=`${entry.dir}/index.html`) {
317                   table.icon-and-text {
318                     tr {
319                       td {
320                         _out.push(await env.site.get_min_svg(entry.icon))
321                       }
322                       td {
323                         span.text-h2{`${entry.name}`}
324                       }
325                     }
326                   }
327                 }
328               }
329           }
330         }
331       //}
332     },
333     // scripts
334     async _out => {
335       script {
336         // this will be called by navbar logic after sign in/out
337         function sign_in_out(status) {
338           window.location.reload()
339         }
340
341         $(document).ready(
342           () => {
343             // when change name form is submitted, do not reload the page
344             $(document).on(
345               'submit',
346               '#change-name-form',
347               e => {
348                 e.preventDefault()
349                 $.ajax(
350                   {
351                     url: 'index.html',
352                     type: 'POST',
353                     data: {
354                       what: 'name',
355                       'given-names': $('#change-name-form-given-names').val(),
356                       'family-name': $('#change-name-form-family-name').val()
357                       },
358                     success: (data, textStatus, jqXHR) => {
359                       $('#message-modal-message').text(data)
360                       $('#message-modal').modal('show')
361                     },
362                     error: (jqXHR, textStatus, errorThrown) => {
363                       $('#message-modal-message').text(errorThrown)
364                       $('#message-modal').modal('show')
365                     }
366                   }
367                 )
368               }
369             )
370
371             // when change billing address form is submitted, do not reload the page
372             $(document).on(
373               'submit',
374               '#change-billing-address-form',
375               e => {
376                 e.preventDefault()
377                 $.ajax(
378                   {
379                     url: 'index.html',
380                     type: 'POST',
381                     data: {
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()
392                       },
393                     success: (data, textStatus, jqXHR) => {
394                       $('#message-modal-message').text(data)
395                       $('#message-modal').modal('show')
396                     },
397                     error: (jqXHR, textStatus, errorThrown) => {
398                       $('#message-modal-message').text(errorThrown)
399                       $('#message-modal').modal('show')
400                     }
401                   }
402                 )
403               }
404             )
405
406             // when change shipping address form is submitted, do not reload the page
407             $(document).on(
408               'submit',
409               '#change-shipping-address-form',
410               e => {
411                 e.preventDefault()
412                 $.ajax(
413                   {
414                     url: 'index.html',
415                     type: 'POST',
416                     data: {
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()
427                       },
428                     success: (data, textStatus, jqXHR) => {
429                       $('#message-modal-message').text(data)
430                       $('#message-modal').modal('show')
431                     },
432                     error: (jqXHR, textStatus, errorThrown) => {
433                       $('#message-modal-message').text(errorThrown)
434                       $('#message-modal').modal('show')
435                     }
436                   }
437                 )
438               }
439             )
440
441             // when change password form is submitted, do not reload the page
442             $(document).on(
443               'submit',
444               '#change-password-form',
445               e => {
446                 e.preventDefault()
447                 $.ajax(
448                   {
449                     url: 'index.html',
450                     type: 'POST',
451                     data: {
452                       what: 'password',
453                       'old-password': $('#change-password-form-old-password').val(),
454                       'new-password': $('#change-password-form-new-password').val(),
455                       },
456                     success: (data, textStatus, jqXHR) => {
457                       $('#message-modal-message').text(data)
458                       $('#message-modal').modal('show')
459                     },
460                     error: (jqXHR, textStatus, errorThrown) => {
461                       $('#message-modal-message').text(errorThrown)
462                       $('#message-modal').modal('show')
463                     }
464                   }
465                 )
466               }
467             )
468
469             //return
470             // when change contact preference form is submitted, do not reload the page
471             $(document).on(
472               'submit',
473               '#change-contact-preference-form',
474               e => {
475                 e.preventDefault()
476                 $.ajax(
477                   {
478                     url: 'index.html',
479                     type: 'POST',
480                     data: {
481                       what: 'contact-preference',
482                       'contact-me': $('#change-contact-preference-form-contact-me').prop('checked')
483                       },
484                     success: (data, textStatus, jqXHR) => {
485                       $('#message-modal-message').text(data)
486                       $('#message-modal').modal('show')
487                     },
488                     error: (jqXHR, textStatus, errorThrown) => {
489                       $('#message-modal-message').text(errorThrown)
490                       $('#message-modal').modal('show')
491                     }
492                   }
493                 )
494               }
495             )
496           }
497         )
498       }
499     }
500   )
501 }