class ChangePasswordViewController extends TimeCardsViewController { constructor(element) { super(element); this.successDialog = new Dialog("The password has been successfully updated.", null, Dialog.BUTTONS_OK_ONLY); this.onPasswordChangeErrorBound = this.onPasswordChangeError.bind(this); } viewWillAppear() { TimeCards.dataManager.addStoreErrorListener("user", this.onPasswordChangeErrorBound); this.reset(); } viewWillDisappear() { TimeCards.dataManager.removeStoreErrorListener("user", this.onPasswordChangeErrorBound); } reset() { this.oldPasswordField.value = ""; this.newPasswordField.value = ""; this.saveButton.disabled = true; } onFieldChanged(event) { this.saveButton.disabled = !this.changePasswordForm.checkValidity(); } onFormSubmitted(event) { event.preventDefault(); TimeCards.dataManager.store("user", Authentication.currentUser.user_id, { old_password: this.oldPasswordField.value, password: this.newPasswordField.value }, this.onPasswordChanged.bind(this)); } onPasswordChanged(response) { this.dismissModally(); this.successDialog.show(); } onPasswordChangeError(key, entity, error) { //Do nothing if key is not current user. if (key != Authentication.currentUser.user_id) { return; } //Reset disabled state of save button. this.onFieldChanged(); } } UIKit.registerViewControllerType(ChangePasswordViewController);