import ngModule from '../module'; export default class Controller { constructor($scope, $http, vnApp, $translate) { this.$ = $scope; this.$http = $http; this.vnApp = vnApp; this.$translate = $translate; this.canChangePassword = false; this.canEnableCheckBox = true; } $onChanges() { if (this.client) { this.account = this.client.account; this.isCustomer(); this.checkConditions(); } } isCustomer() { if (this.client.id) { this.$http.get(`/client/api/Clients/${this.client.id}/hasCustomerRole`).then(res => { this.canChangePassword = res.data && res.data.isCustomer; }); } } checkConditions() { if (this.client.id) { this.$http.get(`/client/api/Clients/${this.client.id}/isValidClient`).then(res => { this.canEnableCheckBox = res.data; }); } } onPassOpen() { this.newPassword = ''; this.repeatPassword = ''; this.$.$apply(); } onPassChange(response) { if (response == 'ACCEPT') { try { if (!this.newPassword) throw new Error(`You must enter a new password`); if (this.newPassword != this.repeatPassword) throw new Error(`Passwords don't match`); let account = { password: this.newPassword }; this.$http.patch(`/client/api/Accounts/${this.client.id}`, account).then(res => { this.vnApp.showSuccess(this.$translate.instant('Data saved!')); }); } catch (e) { this.vnApp.showError(this.$translate.instant(e.message)); return false; } } return true; } } Controller.$inject = ['$scope', '$http', 'vnApp', '$translate']; ngModule.component('vnClientWebAccess', { template: require('./index.html'), controller: Controller, bindings: { client: '<' } });