salix/modules/client/front/sample/create/index.js

76 lines
2.4 KiB
JavaScript
Raw Normal View History

2018-07-31 09:08:22 +00:00
import ngModule from '../../module';
import './style.scss';
class Controller {
constructor($scope, $state, $http, vnApp, $translate) {
this.$scope = $scope;
this.$state = $state;
this.$stateParams = $state.params;
this.$http = $http;
this.vnApp = vnApp;
this.$translate = $translate;
this.clientSample = {
clientFk: this.$stateParams.id
};
}
showPreview() {
2018-07-31 09:08:22 +00:00
let sampleType = this.$scope.sampleType.selection;
let queryParams;
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'));
if (sampleType.hasCompany) {
queryParams = `${sampleType.code}/${this.clientSample.companyFk}/${this.$stateParams.id}/preview`;
} else {
queryParams = `${sampleType.code}/${this.$stateParams.id}/preview`;
}
let query = `/mailer/notification/${queryParams}`;
this.$http.get(query).then(res => {
if (res.data) {
let dialog = this.$scope.showPreview.element;
let body = dialog.querySelector('tpl-body');
body.innerHTML = res.data;
this.$scope.showPreview.show();
}
});
}
onSubmit() {
this.$scope.watcher.check();
this.$scope.watcher.realSubmit().then(() =>
this.sendSample()
);
}
sendSample() {
let sampleType = this.$scope.sampleType.selection;
let queryParams;
if (sampleType.hasCompany) {
queryParams = `${sampleType.code}/${this.clientSample.companyFk}/${this.$stateParams.id}`;
} else {
queryParams = `${sampleType.code}/${this.$stateParams.id}`;
}
let query = `/mailer/notification/${queryParams}`;
this.$http.get(query).then(res => {
if (res) {
this.vnApp.showSuccess(this.$translate.instant('Notification sent!'));
this.$state.go('client.card.sample.index');
}
});
}
}
Controller.$inject = ['$scope', '$state', '$http', 'vnApp', '$translate'];
ngModule.component('vnClientSampleCreate', {
template: require('./index.html'),
controller: Controller
});