edit-profile.page.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. parasails.registerPage('edit-profile', {
  2. // ╦╔╗╔╦╔╦╗╦╔═╗╦ ╔═╗╔╦╗╔═╗╔╦╗╔═╗
  3. // ║║║║║ ║ ║╠═╣║ ╚═╗ ║ ╠═╣ ║ ║╣
  4. // ╩╝╚╝╩ ╩ ╩╩ ╩╩═╝ ╚═╝ ╩ ╩ ╩ ╩ ╚═╝
  5. data: {
  6. // Main syncing/loading state for this page.
  7. syncing: false,
  8. // Form data
  9. formData: { /* … */ },
  10. // For tracking client-side validation errors in our form.
  11. // > Has property set to `true` for each invalid property in `formData`.
  12. formErrors: { /* … */ },
  13. // Server error state for the form
  14. cloudError: '',
  15. },
  16. // ╦ ╦╔═╗╔═╗╔═╗╦ ╦╔═╗╦ ╔═╗
  17. // ║ ║╠╣ ║╣ ║ ╚╦╝║ ║ ║╣
  18. // ╩═╝╩╚ ╚═╝╚═╝ ╩ ╚═╝╩═╝╚═╝
  19. beforeMount: function() {
  20. // Attach raw data exposed by the server.
  21. _.extend(this, SAILS_LOCALS);
  22. // Set the form data.
  23. this.formData.fullName = this.me.fullName;
  24. this.formData.emailAddress = this.me.emailChangeCandidate ? this.me.emailChangeCandidate : this.me.emailAddress;
  25. },
  26. // ╦╔╗╔╔╦╗╔═╗╦═╗╔═╗╔═╗╔╦╗╦╔═╗╔╗╔╔═╗
  27. // ║║║║ ║ ║╣ ╠╦╝╠═╣║ ║ ║║ ║║║║╚═╗
  28. // ╩╝╚╝ ╩ ╚═╝╩╚═╩ ╩╚═╝ ╩ ╩╚═╝╝╚╝╚═╝
  29. methods: {
  30. submittedForm: function() {
  31. // Redirect to the account page on success.
  32. // > (Note that we re-enable the syncing state here. This is on purpose--
  33. // > to make sure the spinner stays there until the page navigation finishes.)
  34. this.syncing = true;
  35. window.location = '/account';
  36. },
  37. handleParsingForm: function() {
  38. // Clear out any pre-existing error messages.
  39. this.formErrors = {};
  40. var argins = this.formData;
  41. // Validate name:
  42. if(!argins.fullName) {
  43. this.formErrors.password = true;
  44. }
  45. // Validate email:
  46. if(!argins.emailAddress) {
  47. this.formErrors.emailAddress = true;
  48. }
  49. // If there were any issues, they've already now been communicated to the user,
  50. // so simply return undefined. (This signifies that the submission should be
  51. // cancelled.)
  52. if (Object.keys(this.formErrors).length > 0) {
  53. return;
  54. }
  55. return argins;
  56. },
  57. }
  58. });