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 {
|
|
|
|
constructor($element, $) {
|
2019-11-07 10:19:05 +00:00
|
|
|
super($element, $);
|
2018-07-31 09:08:22 +00:00
|
|
|
this.clientSample = {
|
2019-11-07 10:19:05 +00:00
|
|
|
clientFk: this.$params.id,
|
2020-03-17 10:17:50 +00:00
|
|
|
companyId: this.vnConfig.companyFk
|
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;
|
|
|
|
|
|
|
|
if (value)
|
|
|
|
this.clientSample.recipient = value.email;
|
|
|
|
}
|
|
|
|
|
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();
|
|
|
|
this.$.watcher.realSubmit().then(() =>
|
|
|
|
this.sendSample()
|
|
|
|
);
|
|
|
|
}
|
2018-07-31 09:08:22 +00:00
|
|
|
|
2020-02-18 10:14:02 +00:00
|
|
|
showPreview() {
|
|
|
|
this.send(true, res => {
|
2019-11-07 10:19:05 +00:00
|
|
|
this.$.showPreview.show();
|
2020-02-18 10:14:02 +00:00
|
|
|
const dialog = document.body.querySelector('div.vn-dialog');
|
|
|
|
const body = dialog.querySelector('tpl-body');
|
|
|
|
const scroll = dialog.querySelector('div:first-child');
|
2019-01-30 07:09:21 +00:00
|
|
|
|
2019-11-04 12:55:20 +00:00
|
|
|
body.innerHTML = res.data;
|
|
|
|
scroll.scrollTop = 0;
|
2018-07-31 09:08:22 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-02-18 10:14:02 +00:00
|
|
|
sendSample() {
|
|
|
|
this.send(false, () => {
|
2020-07-23 14:07:08 +00:00
|
|
|
this.vnApp.showSuccess(this.$t('Notification sent!'));
|
2020-02-18 10:14:02 +00:00
|
|
|
this.$state.go('client.card.sample.index');
|
|
|
|
});
|
2018-07-31 09:08:22 +00:00
|
|
|
}
|
|
|
|
|
2020-02-18 10:14:02 +00:00
|
|
|
send(isPreview, cb) {
|
|
|
|
const sampleType = this.$.sampleType.selection;
|
|
|
|
const params = {
|
2020-05-22 13:20:55 +00:00
|
|
|
recipientId: this.$params.id,
|
2019-11-04 12:55:20 +00:00
|
|
|
recipient: this.clientSample.recipient
|
|
|
|
};
|
2018-07-31 09:08:22 +00:00
|
|
|
|
2020-02-18 10:14:02 +00:00
|
|
|
if (!params.recipient)
|
2020-07-23 14:07:08 +00:00
|
|
|
return this.vnApp.showError(this.$t('Email cannot be blank'));
|
2020-02-18 10:14:02 +00:00
|
|
|
|
2019-11-04 12:55:20 +00:00
|
|
|
if (!sampleType)
|
2020-07-23 14:07:08 +00:00
|
|
|
return this.vnApp.showError(this.$t('Choose a sample'));
|
2019-11-04 12:55:20 +00:00
|
|
|
|
2020-02-26 13:30:30 +00:00
|
|
|
if (sampleType.hasCompany && !this.clientSample.companyFk)
|
2020-07-23 14:07:08 +00:00
|
|
|
return this.vnApp.showError(this.$t('Choose a company'));
|
2018-07-31 09:08:22 +00:00
|
|
|
|
2019-11-04 12:55:20 +00:00
|
|
|
if (sampleType.hasCompany)
|
2020-02-26 13:30:30 +00:00
|
|
|
params.companyId = this.clientSample.companyFk;
|
2020-02-18 10:14:02 +00:00
|
|
|
|
2021-04-06 11:46:38 +00:00
|
|
|
let query = `email/${sampleType.code}`;
|
|
|
|
if (isPreview)
|
|
|
|
query = `email/${sampleType.code}/preview`;
|
2019-01-30 07:09:21 +00:00
|
|
|
|
2020-03-17 10:17:50 +00:00
|
|
|
this.$http.get(query, {params}).then(cb);
|
2018-07-31 09:08:22 +00:00
|
|
|
}
|
|
|
|
}
|
2020-03-17 10:17:50 +00:00
|
|
|
Controller.$inject = ['$element', '$scope'];
|
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
|
|
|
});
|