salix/modules/client/front/web-access/index.js

72 lines
1.9 KiB
JavaScript
Raw Normal View History

2017-06-03 11:01:47 +00:00
import ngModule from '../module';
2017-05-31 07:46:05 +00:00
2017-06-03 11:01:47 +00:00
export default class Controller {
2018-10-17 10:49:18 +00:00
constructor($scope, $http, vnApp, $translate) {
2017-06-03 11:01:47 +00:00
this.$ = $scope;
2017-05-31 07:46:05 +00:00
this.$http = $http;
this.vnApp = vnApp;
2018-10-17 10:49:18 +00:00
this.$translate = $translate;
2017-09-21 05:53:23 +00:00
this.canChangePassword = false;
this.canEnableCheckBox = true;
2017-05-31 07:46:05 +00:00
}
2017-05-31 07:46:05 +00:00
$onChanges() {
2017-09-21 05:53:23 +00:00
if (this.client) {
2017-05-31 07:46:05 +00:00
this.account = this.client.account;
2017-09-21 05:53:23 +00:00
this.isCustomer();
this.checkConditions();
2017-09-21 05:53:23 +00:00
}
}
isCustomer() {
2018-03-07 14:05:09 +00:00
if (this.client.id) {
this.$http.get(`/client/api/Clients/${this.client.id}/hasCustomerRole`).then(res => {
2018-03-07 14:05:09 +00:00
this.canChangePassword = res.data && res.data.isCustomer;
2017-09-21 05:53:23 +00:00
});
}
2017-05-31 07:46:05 +00:00
}
2017-09-21 06:48:25 +00:00
checkConditions() {
2018-03-07 14:05:09 +00:00
if (this.client.id) {
this.$http.get(`/client/api/Clients/${this.client.id}/isValidClient`).then(res => {
this.canEnableCheckBox = res.data;
});
}
}
2017-05-31 07:46:05 +00:00
onPassOpen() {
this.newPassword = '';
this.repeatPassword = '';
2017-06-03 11:01:47 +00:00
this.$.$apply();
2017-05-31 07:46:05 +00:00
}
2017-05-31 07:46:05 +00:00
onPassChange(response) {
2018-03-07 14:05:09 +00:00
if (response == 'ACCEPT')
2017-05-31 07:46:05 +00:00
try {
if (!this.newPassword)
throw new Error(`Passwords can't be empty`);
if (this.newPassword != this.repeatPassword)
throw new Error(`Passwords don't match`);
let account = {
password: this.newPassword
};
2017-06-03 11:01:47 +00:00
this.$http.patch(`/client/api/Accounts/${this.client.id}`, account);
2017-05-31 07:46:05 +00:00
} catch (e) {
2018-10-17 10:49:18 +00:00
this.vnApp.showError(this.$translate.instant(e.message));
2017-05-31 07:46:05 +00:00
return false;
}
return true;
}
}
2018-10-17 10:49:18 +00:00
Controller.$inject = ['$scope', '$http', 'vnApp', '$translate'];
2017-05-31 07:46:05 +00:00
2017-06-03 11:01:47 +00:00
ngModule.component('vnClientWebAccess', {
2018-05-23 12:26:51 +00:00
template: require('./index.html'),
2017-06-03 11:01:47 +00:00
controller: Controller,
2017-05-31 07:46:05 +00:00
bindings: {
client: '<'
2017-06-03 11:01:47 +00:00
}
2017-05-31 07:46:05 +00:00
});