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

80 lines
2.0 KiB
JavaScript

import ngModule from '../module';
import UserError from 'core/lib/user-error';
class Controller {
constructor($http, $scope, $stateParams, vnApp, $translate, $element) {
this.$http = $http;
this.$scope = $scope;
this.$stateParams = $stateParams;
this.vnApp = vnApp;
this.$translate = $translate;
this.$element = $element;
this.services = [];
}
$onInit() {
this.getDefaultTaxClass();
}
getDefaultTaxClass() {
let config = {params: {
filter: {
where: {
code: 'G'
}
}
}};
let query = 'TaxClasses/findOne';
this.$http.get(query, config).then(res => {
if (res.data)
this.defaultTaxClass = res.data;
});
}
add() {
this.$scope.model.insert({
taxClassFk: this.defaultTaxClass.id,
quantity: 1,
ticketFk: this.$stateParams.id
});
}
onNewServiceTypeOpen() {
this.newServiceType = {};
}
newServiceTypeDialog(elementIndex, event) {
event.preventDefault();
this.$scope.createServiceTypeDialog.show();
this.currentServiceIndex = elementIndex;
}
onNewServiceTypeResponse(response) {
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].description = response.data.name;
});
}
}
onSubmit() {
this.$scope.watcher.check();
this.$scope.model.save().then(() => {
this.$scope.watcher.notifySaved();
this.$scope.model.refresh();
});
}
}
Controller.$inject = ['$http', '$scope', '$stateParams', 'vnApp', '$translate', '$element'];
ngModule.component('vnTicketService', {
template: require('./index.html'),
controller: Controller
});