salix/modules/ticket/front/services/index.js

54 lines
1.4 KiB
JavaScript

import ngModule from '../module';
import Section from 'salix/components/section';
import UserError from 'core/lib/user-error';
class Controller extends Section {
$onInit() {
this.services = [];
this.getDefaultTaxClass();
}
getDefaultTaxClass() {
let filter = {
where: {code: 'G'}
};
this.$http.get('TaxClasses/findOne', {filter})
.then(res => this.defaultTaxClass = res.data);
}
add() {
this.$.model.insert({
taxClassFk: this.defaultTaxClass.id,
quantity: 1,
ticketFk: this.$params.id
});
}
onNewServiceTypeClick(service, event) {
event.preventDefault();
this.$.newServiceType = {};
this.$.newServiceTypeDialog.show(service);
}
onNewServiceTypeAccept(service) {
if (!this.$.newServiceType.name)
throw new UserError(`Name can't be empty`);
return this.$http.post(`TicketServiceTypes`, this.$.newServiceType)
.then(res => service.ticketServiceTypeFk = res.data.id);
}
onSubmit() {
this.$.watcher.check();
this.$.model.save()
.then(() => this.$.model.refresh())
.then(() => this.$.watcher.notifySaved());
}
}
ngModule.vnComponent('vnTicketService', {
template: require('./index.html'),
controller: Controller
});