2017-06-03 11:01:47 +00:00
|
|
|
import ngModule from '../module';
|
2020-03-17 10:17:50 +00:00
|
|
|
import Section from 'salix/components/section';
|
2017-05-31 07:46:05 +00:00
|
|
|
|
2020-03-17 10:17:50 +00:00
|
|
|
export default class Controller extends Section {
|
|
|
|
constructor($element, $) {
|
|
|
|
super($element, $);
|
2017-09-21 05:53:23 +00:00
|
|
|
this.canChangePassword = false;
|
2018-03-07 11:24:47 +00:00
|
|
|
this.canEnableCheckBox = true;
|
2017-05-31 07:46:05 +00:00
|
|
|
}
|
2018-03-07 11:24:47 +00:00
|
|
|
|
2023-05-12 07:02:55 +00:00
|
|
|
set client(value) {
|
|
|
|
this._client = value;
|
|
|
|
if (!value) return;
|
|
|
|
|
|
|
|
const filter = {where: {id: value.id}};
|
|
|
|
this.$http.get(`VnUsers/preview`, {filter})
|
|
|
|
.then(res => {
|
|
|
|
const [user] = res.data;
|
|
|
|
this.account = user;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
get client() {
|
|
|
|
return this._client;
|
|
|
|
}
|
|
|
|
|
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();
|
2018-03-07 11:24:47 +00:00
|
|
|
this.checkConditions();
|
2017-09-21 05:53:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
isCustomer() {
|
2018-03-07 14:05:09 +00:00
|
|
|
if (this.client.id) {
|
2019-10-24 22:53:53 +00:00
|
|
|
this.$http.get(`Clients/${this.client.id}/hasCustomerRole`).then(res => {
|
2021-09-29 10:15:42 +00:00
|
|
|
this.canChangePassword = res.data && res.data;
|
2017-09-21 05:53:23 +00:00
|
|
|
});
|
|
|
|
}
|
2017-05-31 07:46:05 +00:00
|
|
|
}
|
2017-09-21 06:48:25 +00:00
|
|
|
|
2018-03-07 11:24:47 +00:00
|
|
|
checkConditions() {
|
2018-03-07 14:05:09 +00:00
|
|
|
if (this.client.id) {
|
2019-10-24 22:53:53 +00:00
|
|
|
this.$http.get(`Clients/${this.client.id}/isValidClient`).then(res => {
|
2018-03-07 11:24:47 +00:00
|
|
|
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-11-13 21:15:44 +00:00
|
|
|
|
2020-07-29 08:47:48 +00:00
|
|
|
onPassChange() {
|
|
|
|
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`);
|
2022-06-16 09:32:42 +00:00
|
|
|
const data = {
|
|
|
|
newPassword: this.newPassword
|
2020-07-29 08:47:48 +00:00
|
|
|
};
|
2017-05-31 07:46:05 +00:00
|
|
|
|
2022-06-16 09:32:42 +00:00
|
|
|
this.$http.patch(`Clients/${this.client.id}/setPassword`, data).then(() => {
|
2020-07-29 08:47:48 +00:00
|
|
|
this.vnApp.showSuccess(this.$t('Data saved!'));
|
|
|
|
});
|
|
|
|
} catch (e) {
|
|
|
|
this.vnApp.showError(this.$t(e.message));
|
2019-07-11 05:06:53 +00:00
|
|
|
|
2020-07-29 08:47:48 +00:00
|
|
|
return false;
|
2019-05-29 11:06:42 +00:00
|
|
|
}
|
2017-05-31 07:46:05 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2022-06-16 09:32:42 +00:00
|
|
|
|
|
|
|
onSubmit() {
|
|
|
|
const data = {
|
|
|
|
name: this.account.name,
|
2022-06-20 05:31:10 +00:00
|
|
|
email: this.account.email,
|
2022-06-16 14:25:21 +00:00
|
|
|
active: this.account.active
|
2022-06-16 09:32:42 +00:00
|
|
|
};
|
|
|
|
this.$http.patch(`Clients/${this.client.id}/updateUser`, data).then(() => {
|
2022-06-16 14:25:21 +00:00
|
|
|
this.$.watcher.notifySaved();
|
|
|
|
this.$.watcher.updateOriginalData();
|
2022-06-16 09:32:42 +00:00
|
|
|
});
|
|
|
|
}
|
2017-05-31 07:46:05 +00:00
|
|
|
}
|
2020-03-17 10:17:50 +00:00
|
|
|
Controller.$inject = ['$element', '$scope'];
|
2017-05-31 07:46:05 +00:00
|
|
|
|
2020-07-24 12:22:30 +00:00
|
|
|
ngModule.vnComponent('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
|
|
|
});
|