salix/client/item/src/tax/index.js

46 lines
1.2 KiB
JavaScript
Raw Normal View History

2018-02-23 12:04:44 +00:00
import ngModule from '../module';
export default class Controller {
constructor($stateParams, $http, $translate, vnApp) {
2018-02-23 12:04:44 +00:00
this.$http = $http;
this.$stateParams = $stateParams;
this._ = $translate;
this.vnApp = vnApp;
2018-02-23 12:04:44 +00:00
let filter = {
fields: ['id', 'countryFk', 'taxClassFk'],
include: [{
relation: 'country',
scope: {fields: ['country']}
}]
};
let urlFilter = encodeURIComponent(JSON.stringify(filter));
let url = `/item/api/Items/${$stateParams.id}/taxes?filter=${urlFilter}`;
$http.get(url).then(json => {
this.taxes = json.data;
});
}
2018-02-23 12:04:44 +00:00
submit() {
let data = [];
for (let tax of this.taxes)
data.push({id: tax.id, taxClassFk: tax.taxClassFk});
let url = `/item/api/Items/${this.$stateParams.id}/updateTaxes`;
this.$http.post(url, data).then(
() => this.vnApp.showMessage(this._.instant('Data saved!'))
);
2018-02-23 12:04:44 +00:00
}
}
Controller.$inject = ['$stateParams', '$http', '$translate', 'vnApp'];
2018-02-23 12:04:44 +00:00
ngModule.component('vnItemTax', {
template: require('./index.html'),
2018-02-23 12:04:44 +00:00
controller: Controller,
bindings: {
item: '<'
}
});