salix/modules/client/front/credit-insurance/create/index.js

44 lines
1.2 KiB
JavaScript

import ngModule from '../../module';
class Controller {
constructor($http, $filter, $state, $scope, $translate, vnApp) {
this.$http = $http;
this.$state = $state;
this.$scope = $scope;
this.$translate = $translate;
this.vnApp = vnApp;
this.creditClassification = {
started: $filter('date')(new Date(), 'yyyy-MM-dd HH:mm')
};
}
onSubmit() {
if (this.$scope.form.$invalid)
return this.vnApp.showError(this.$translate.instant('Some fields are invalid'));
let query = `creditClassifications/createWithInsurance`;
let data = this.creditClassification;
data.clientFk = this.client.id;
this.$http.post(query, data).then(res => {
if (res.data) {
this.card.reload();
this.$state.go('client.card.creditInsurance.index');
}
});
}
}
Controller.$inject = ['$http', '$filter', '$state', '$scope', '$translate', 'vnApp'];
ngModule.component('vnClientCreditInsuranceCreate', {
template: require('./index.html'),
controller: Controller,
require: {
card: '^vnClientCard'
},
bindings: {
client: '<'
}
});