2018-07-31 09:08:22 +00:00
|
|
|
import ngModule from '../../module';
|
2020-03-17 10:17:50 +00:00
|
|
|
import Section from 'salix/components/section';
|
2018-07-31 09:08:22 +00:00
|
|
|
import './style.scss';
|
|
|
|
|
2020-03-17 10:17:50 +00:00
|
|
|
class Controller extends Section {
|
2022-09-26 06:07:45 +00:00
|
|
|
constructor($element, $, vnEmail) {
|
2019-11-07 10:19:05 +00:00
|
|
|
super($element, $);
|
2022-09-26 06:07:45 +00:00
|
|
|
this.vnEmail = vnEmail;
|
2018-07-31 09:08:22 +00:00
|
|
|
}
|
|
|
|
|
2019-11-04 12:55:20 +00:00
|
|
|
get client() {
|
|
|
|
return this._client;
|
|
|
|
}
|
|
|
|
|
|
|
|
set client(value) {
|
|
|
|
this._client = value;
|
|
|
|
|
2023-02-22 12:04:27 +00:00
|
|
|
if (value)
|
|
|
|
this.setClientSample(value);
|
2019-11-04 12:55:20 +00:00
|
|
|
}
|
|
|
|
|
2019-11-07 10:19:05 +00:00
|
|
|
get companyId() {
|
2020-02-26 13:30:30 +00:00
|
|
|
if (!this.clientSample.companyFk)
|
|
|
|
this.clientSample.companyFk = this.vnConfig.companyFk;
|
|
|
|
return this.clientSample.companyFk;
|
2019-11-07 10:19:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
set companyId(value) {
|
2020-02-26 13:30:30 +00:00
|
|
|
this.clientSample.companyFk = value;
|
2019-11-07 10:19:05 +00:00
|
|
|
}
|
|
|
|
|
2020-02-18 10:14:02 +00:00
|
|
|
onSubmit() {
|
|
|
|
this.$.watcher.check();
|
2022-10-04 07:21:24 +00:00
|
|
|
|
|
|
|
const validationMessage = this.validate();
|
|
|
|
if (validationMessage)
|
|
|
|
return this.vnApp.showError(this.$t(validationMessage));
|
|
|
|
|
2022-09-26 06:07:45 +00:00
|
|
|
this.$.watcher.realSubmit().then(() => this.send());
|
2020-02-18 10:14:02 +00:00
|
|
|
}
|
2018-07-31 09:08:22 +00:00
|
|
|
|
2022-10-04 07:21:24 +00:00
|
|
|
validate() {
|
2022-09-26 06:07:45 +00:00
|
|
|
const sampleType = this.$.sampleType.selection;
|
|
|
|
|
2022-10-04 07:21:24 +00:00
|
|
|
if (!this.clientSample.recipient)
|
|
|
|
return 'Email cannot be blank';
|
2022-09-26 06:07:45 +00:00
|
|
|
|
|
|
|
if (!sampleType)
|
2022-10-04 07:21:24 +00:00
|
|
|
return 'Choose a sample';
|
2022-09-26 06:07:45 +00:00
|
|
|
|
|
|
|
if (sampleType.hasCompany && !this.clientSample.companyFk)
|
2022-10-04 07:21:24 +00:00
|
|
|
return 'Choose a company';
|
|
|
|
|
|
|
|
if (sampleType.datepickerEnabled && !this.clientSample.from)
|
|
|
|
return 'Choose a date';
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
setParams(params) {
|
|
|
|
const sampleType = this.$.sampleType.selection;
|
2022-09-26 06:07:45 +00:00
|
|
|
|
|
|
|
if (sampleType.hasCompany)
|
|
|
|
params.companyId = this.clientSample.companyFk;
|
|
|
|
|
|
|
|
if (sampleType.datepickerEnabled)
|
|
|
|
params.from = this.clientSample.from;
|
|
|
|
}
|
|
|
|
|
2022-09-22 13:44:35 +00:00
|
|
|
preview() {
|
2020-02-18 10:14:02 +00:00
|
|
|
const sampleType = this.$.sampleType.selection;
|
2022-09-22 13:44:35 +00:00
|
|
|
|
2020-02-18 10:14:02 +00:00
|
|
|
const params = {
|
2022-10-04 07:21:24 +00:00
|
|
|
recipientId: this.$params.id
|
2019-11-04 12:55:20 +00:00
|
|
|
};
|
2018-07-31 09:08:22 +00:00
|
|
|
|
2022-10-04 07:21:24 +00:00
|
|
|
const validationMessage = this.validate();
|
|
|
|
if (validationMessage)
|
|
|
|
return this.vnApp.showError(this.$t(validationMessage));
|
|
|
|
|
|
|
|
this.setParams(params);
|
2022-09-26 06:07:45 +00:00
|
|
|
|
|
|
|
const path = `${sampleType.model}/${this.$params.id}/${sampleType.code}-html`;
|
2022-09-22 13:44:35 +00:00
|
|
|
this.$http.get(path, {params})
|
|
|
|
.then(response => {
|
|
|
|
this.$.showPreview.show();
|
|
|
|
const dialog = document.body.querySelector('div.vn-dialog');
|
|
|
|
const body = dialog.querySelector('tpl-body');
|
|
|
|
const scroll = dialog.querySelector('div:first-child');
|
|
|
|
|
|
|
|
body.innerHTML = response.data;
|
|
|
|
scroll.scrollTop = 0;
|
|
|
|
});
|
|
|
|
}
|
2019-01-30 07:09:21 +00:00
|
|
|
|
2022-09-22 13:44:35 +00:00
|
|
|
send() {
|
2022-09-26 06:07:45 +00:00
|
|
|
const sampleType = this.$.sampleType.selection;
|
|
|
|
|
|
|
|
const params = {
|
|
|
|
recipientId: this.client.id,
|
|
|
|
recipient: this.clientSample.recipient,
|
|
|
|
replyTo: this.clientSample.replyTo
|
|
|
|
};
|
|
|
|
|
2022-10-04 07:21:24 +00:00
|
|
|
const validationMessage = this.validate();
|
|
|
|
if (validationMessage)
|
|
|
|
return this.vnApp.showError(this.$t(validationMessage));
|
|
|
|
|
|
|
|
this.setParams(params);
|
2022-09-26 06:07:45 +00:00
|
|
|
|
|
|
|
const path = `${sampleType.model}/${this.$params.id}/${sampleType.code}-email`;
|
|
|
|
this.vnEmail.send(path, params)
|
|
|
|
.then(() => this.$state.go('client.card.sample.index'));
|
2018-07-31 09:08:22 +00:00
|
|
|
}
|
2021-04-07 11:09:53 +00:00
|
|
|
|
2023-02-22 12:04:27 +00:00
|
|
|
setClientSample(client) {
|
2021-04-07 11:09:53 +00:00
|
|
|
const userId = window.localStorage.currentUserWorkerId;
|
|
|
|
const params = {filter: {where: {userFk: userId}}};
|
|
|
|
this.$http.get('EmailUsers', params).then(res => {
|
|
|
|
const [worker] = res && res.data;
|
2023-02-22 12:04:27 +00:00
|
|
|
this.clientSample = {
|
|
|
|
clientFk: this.$params.id,
|
|
|
|
companyId: this.vnConfig.companyFk,
|
|
|
|
recipient: client.email,
|
|
|
|
replyTo: worker.email
|
|
|
|
};
|
2021-04-07 11:09:53 +00:00
|
|
|
});
|
|
|
|
}
|
2018-07-31 09:08:22 +00:00
|
|
|
}
|
2021-04-07 11:09:53 +00:00
|
|
|
|
2022-09-26 06:07:45 +00:00
|
|
|
Controller.$inject = ['$element', '$scope', 'vnEmail'];
|
2018-07-31 09:08:22 +00:00
|
|
|
|
2020-07-24 12:22:30 +00:00
|
|
|
ngModule.vnComponent('vnClientSampleCreate', {
|
2018-07-31 09:08:22 +00:00
|
|
|
template: require('./index.html'),
|
2019-11-04 12:55:20 +00:00
|
|
|
controller: Controller,
|
|
|
|
bindings: {
|
|
|
|
client: '<'
|
|
|
|
}
|
2018-07-31 09:08:22 +00:00
|
|
|
});
|