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

64 lines
1.6 KiB
JavaScript
Raw Normal View History

2018-11-30 06:57:41 +00:00
import ngModule from '../module';
2020-03-18 07:35:59 +00:00
import Section from 'salix/components/section';
import UserError from 'core/lib/user-error';
2018-11-30 06:57:41 +00:00
2020-03-18 07:35:59 +00:00
class Controller extends Section {
$onInit() {
2020-03-18 07:35:59 +00:00
this.services = [];
this.getDefaultTaxClass();
}
getDefaultTaxClass() {
2019-11-11 15:32:03 +00:00
let filter = {
where: {code: 'G'}
};
this.$http.get('TaxClasses/findOne', {filter})
.then(res => this.defaultTaxClass = res.data);
2018-11-30 06:57:41 +00:00
}
add() {
2019-11-12 07:51:50 +00:00
if (this.defaultTaxClass) {
2020-03-18 07:35:59 +00:00
this.$.model.insert({
2019-11-12 07:51:50 +00:00
taxClassFk: this.defaultTaxClass.id,
quantity: 1,
2020-03-18 07:35:59 +00:00
ticketFk: this.$params.id
2019-11-12 07:51:50 +00:00
});
}
2018-11-30 06:57:41 +00:00
}
onNewServiceTypeOpen() {
2019-10-11 15:38:04 +00:00
this.newServiceType = {};
}
2019-10-18 19:36:30 +00:00
newServiceTypeDialog(elementIndex, event) {
event.preventDefault();
2020-03-18 07:35:59 +00:00
this.$.createServiceTypeDialog.show();
this.currentServiceIndex = elementIndex;
}
onNewServiceTypeResponse(response) {
2019-10-30 15:57:14 +00:00
if (response == 'accept') {
if (!this.newServiceType.name)
throw new UserError(`Name can't be empty`);
this.$http.post(`TicketServiceTypes`, this.newServiceType).then(response => {
this.services[this.currentServiceIndex].ticketServiceTypeFk = response.data.id;
});
}
}
2018-11-30 06:57:41 +00:00
onSubmit() {
2020-03-18 07:35:59 +00:00
this.$.watcher.check();
2020-03-18 07:35:59 +00:00
this.$.model.save().then(() => {
this.$.watcher.notifySaved();
this.$.model.refresh();
2018-11-30 06:57:41 +00:00
});
}
}
ngModule.component('vnTicketService', {
template: require('./index.html'),
controller: Controller
});