123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- parasails.registerPage('edit-profile', {
- // ╦╔╗╔╦╔╦╗╦╔═╗╦ ╔═╗╔╦╗╔═╗╔╦╗╔═╗
- // ║║║║║ ║ ║╠═╣║ ╚═╗ ║ ╠═╣ ║ ║╣
- // ╩╝╚╝╩ ╩ ╩╩ ╩╩═╝ ╚═╝ ╩ ╩ ╩ ╩ ╚═╝
- data: {
- // Main syncing/loading state for this page.
- syncing: false,
- // Form data
- formData: { /* … */ },
- // For tracking client-side validation errors in our form.
- // > Has property set to `true` for each invalid property in `formData`.
- formErrors: { /* … */ },
- // Server error state for the form
- cloudError: '',
- },
- // ╦ ╦╔═╗╔═╗╔═╗╦ ╦╔═╗╦ ╔═╗
- // ║ ║╠╣ ║╣ ║ ╚╦╝║ ║ ║╣
- // ╩═╝╩╚ ╚═╝╚═╝ ╩ ╚═╝╩═╝╚═╝
- beforeMount: function() {
- // Attach raw data exposed by the server.
- _.extend(this, SAILS_LOCALS);
- // Set the form data.
- this.formData.fullName = this.me.fullName;
- this.formData.emailAddress = this.me.emailChangeCandidate ? this.me.emailChangeCandidate : this.me.emailAddress;
- },
- // ╦╔╗╔╔╦╗╔═╗╦═╗╔═╗╔═╗╔╦╗╦╔═╗╔╗╔╔═╗
- // ║║║║ ║ ║╣ ╠╦╝╠═╣║ ║ ║║ ║║║║╚═╗
- // ╩╝╚╝ ╩ ╚═╝╩╚═╩ ╩╚═╝ ╩ ╩╚═╝╝╚╝╚═╝
- methods: {
- submittedForm: function() {
- // Redirect to the account page on success.
- // > (Note that we re-enable the syncing state here. This is on purpose--
- // > to make sure the spinner stays there until the page navigation finishes.)
- this.syncing = true;
- window.location = '/account';
- },
- handleParsingForm: function() {
- // Clear out any pre-existing error messages.
- this.formErrors = {};
- var argins = this.formData;
- // Validate name:
- if(!argins.fullName) {
- this.formErrors.password = true;
- }
- // Validate email:
- if(!argins.emailAddress) {
- this.formErrors.emailAddress = true;
- }
- // If there were any issues, they've already now been communicated to the user,
- // so simply return undefined. (This signifies that the submission should be
- // cancelled.)
- if (Object.keys(this.formErrors).length > 0) {
- return;
- }
- return argins;
- },
- }
- });
|