2018-07-31 09:08:22 +00:00
|
|
|
import ngModule from '../../module';
|
|
|
|
import './style.scss';
|
|
|
|
|
|
|
|
class Controller {
|
2019-11-06 07:20:45 +00:00
|
|
|
constructor($scope, $state, $http, vnApp, $translate, $httpParamSerializer, $window) {
|
2018-07-31 09:08:22 +00:00
|
|
|
this.$scope = $scope;
|
|
|
|
this.$state = $state;
|
|
|
|
this.$stateParams = $state.params;
|
|
|
|
this.$http = $http;
|
|
|
|
this.vnApp = vnApp;
|
|
|
|
this.$translate = $translate;
|
2019-11-06 07:20:45 +00:00
|
|
|
this.$window = $window;
|
2019-11-04 12:55:20 +00:00
|
|
|
this.$httpParamSerializer = $httpParamSerializer;
|
2018-07-31 09:08:22 +00:00
|
|
|
this.clientSample = {
|
|
|
|
clientFk: this.$stateParams.id
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2018-10-17 07:28:38 +00:00
|
|
|
showPreview() {
|
2018-07-31 09:08:22 +00:00
|
|
|
let sampleType = this.$scope.sampleType.selection;
|
|
|
|
|
|
|
|
if (!sampleType)
|
|
|
|
return this.vnApp.showError(this.$translate.instant('Choose a sample'));
|
|
|
|
|
|
|
|
if (sampleType.hasCompany && !this.clientSample.companyFk)
|
|
|
|
return this.vnApp.showError(this.$translate.instant('Choose a company'));
|
|
|
|
|
2019-11-04 12:55:20 +00:00
|
|
|
const params = {
|
|
|
|
clientId: this.$stateParams.id,
|
|
|
|
recipient: this.clientSample.recipient,
|
|
|
|
isPreview: true
|
|
|
|
};
|
|
|
|
|
2019-01-30 07:09:21 +00:00
|
|
|
if (sampleType.hasCompany)
|
2019-11-04 12:55:20 +00:00
|
|
|
params.companyId = this.clientSample.companyFk;
|
2018-07-31 09:08:22 +00:00
|
|
|
|
2019-11-04 12:55:20 +00:00
|
|
|
const serializedParams = this.$httpParamSerializer(params);
|
2019-11-05 08:16:16 +00:00
|
|
|
const query = `email/${sampleType.code}?${serializedParams}`;
|
2018-07-31 09:08:22 +00:00
|
|
|
this.$http.get(query).then(res => {
|
2019-11-06 07:20:45 +00:00
|
|
|
this.$scope.showPreview.show();
|
|
|
|
let dialog = document.body.querySelector('div.vn-dialog');
|
2019-11-04 12:55:20 +00:00
|
|
|
let body = dialog.querySelector('tpl-body');
|
|
|
|
let 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
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
onSubmit() {
|
|
|
|
this.$scope.watcher.check();
|
|
|
|
this.$scope.watcher.realSubmit().then(() =>
|
|
|
|
this.sendSample()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
sendSample() {
|
|
|
|
let sampleType = this.$scope.sampleType.selection;
|
2019-11-04 12:55:20 +00:00
|
|
|
let params = {
|
|
|
|
clientId: this.$stateParams.id,
|
|
|
|
recipient: this.clientSample.recipient
|
|
|
|
};
|
2018-07-31 09:08:22 +00:00
|
|
|
|
2019-11-04 12:55:20 +00:00
|
|
|
if (!sampleType)
|
|
|
|
return this.vnApp.showError(this.$translate.instant('Choose a sample'));
|
|
|
|
|
|
|
|
if (sampleType.hasCompany && !this.clientSample.companyFk)
|
|
|
|
return this.vnApp.showError(this.$translate.instant('Choose a company'));
|
2018-07-31 09:08:22 +00:00
|
|
|
|
2019-11-04 12:55:20 +00:00
|
|
|
if (sampleType.hasCompany)
|
|
|
|
params.companyId = this.clientSample.companyFk;
|
2019-01-30 07:09:21 +00:00
|
|
|
|
2019-11-04 12:55:20 +00:00
|
|
|
const serializedParams = this.$httpParamSerializer(params);
|
2019-11-05 08:16:16 +00:00
|
|
|
const query = `email/${sampleType.code}?${serializedParams}`;
|
2019-11-04 12:55:20 +00:00
|
|
|
this.$http.get(query).then(res => {
|
|
|
|
this.vnApp.showSuccess(this.$translate.instant('Notification sent!'));
|
|
|
|
this.$state.go('client.card.sample.index');
|
2018-07-31 09:08:22 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2019-11-06 07:20:45 +00:00
|
|
|
Controller.$inject = ['$scope', '$state', '$http', 'vnApp', '$translate', '$httpParamSerializer', '$window'];
|
2018-07-31 09:08:22 +00:00
|
|
|
|
|
|
|
ngModule.component('vnClientSampleCreate', {
|
|
|
|
template: require('./index.html'),
|
2019-11-04 12:55:20 +00:00
|
|
|
controller: Controller,
|
|
|
|
bindings: {
|
|
|
|
client: '<'
|
|
|
|
}
|
2018-07-31 09:08:22 +00:00
|
|
|
});
|