salix/client/order/src/line/index.js

96 lines
2.5 KiB
JavaScript
Raw Normal View History

2018-08-07 14:04:42 +00:00
import ngModule from '../module';
import './style.scss';
class Controller {
constructor($scope, $state, $http, vnApp, $translate) {
this.$scope = $scope;
this.vnApp = vnApp;
this.$translate = $translate;
this.$state = $state;
this.$http = $http;
this.idsToRemove = [];
}
$onInit() {
this.getRows();
this.getVAT();
}
getRows() {
let filter = {
where: {orderFk: this.$state.params.id},
include: [{
relation: 'item',
scope: {
include: {
relation: 'tags',
scope: {
fields: ['tagFk', 'value'],
include: {
relation: 'tag',
scope: {
fields: ['name']
}
}
}
},
fields: ['itemFk', 'name', 'image']
}
},
{relation: 'warehouse'}]
};
filter = encodeURIComponent(JSON.stringify(filter));
let query = `/order/api/OrderRows?filter=${filter}`;
this.$http.get(query).then(res => {
this.rows = res.data;
});
}
getVAT() {
let query = `/order/api/Orders/${this.$state.params.id}/getVAT`;
2018-08-07 14:04:42 +00:00
this.$http.get(query).then(res => {
this.VAT = res.data;
2018-08-07 14:04:42 +00:00
});
}
removeRow(index) {
let [lineRemoved] = this.rows.splice(index, 1);
this.idsToRemove.push(lineRemoved.id);
}
// Item Descriptor
showDescriptor(event, itemFk) {
this.$scope.descriptor.itemFk = itemFk;
this.$scope.descriptor.parent = event.target;
this.$scope.descriptor.show();
}
onDescriptorLoad() {
this.$scope.popover.relocate();
}
save() {
let params = {
rows: this.idsToRemove,
actualOrderId: this.$state.params.id
};
let query = `/order/api/OrderRows/removes`;
this.$http.post(query, params).then(() => {
this.vnApp.showSuccess(this.$translate.instant('Data saved!'));
});
}
}
Controller.$inject = ['$scope', '$state', '$http', 'vnApp', '$translate'];
ngModule.component('vnOrderLine', {
template: require('./index.html'),
controller: Controller,
bindings: {
order: '<'
}
});