salix/client/ticket/src/package/list/package-list.js

74 lines
1.8 KiB
JavaScript
Raw Normal View History

import ngModule from '../../module';
class Controller {
2018-03-21 10:08:59 +00:00
constructor($http, $scope, $translate, vnApp) {
this.$http = $http;
this.$ = $scope;
2018-03-21 10:08:59 +00:00
this.$translate = $translate;
this.vnApp = vnApp;
this.removedPackages = [];
this.updatedPackages = [];
}
submit() {
let query = `/ticket/api/TicketPackagings/crudTicketPackaging`;
let packagesObj = {
delete: this.removedPackages,
create: [],
update: []
};
this.packages.forEach(item => {
if (typeof item.id === 'undefined')
packagesObj.create.push(item);
if (typeof item.id !== 'undefined' && angular.equals(item, this.oldPackages[item.id]))
packagesObj.update.push(item);
});
this.$http.post(query, packagesObj).then(res => {
this.$.index.accept();
});
}
removePackage(index) {
if (this.packages[index] && this.packages[index].id)
this.removedPackages.push(this.packages[index].id);
this.packages.splice(index, 1);
}
addPackage() {
let data = {
packagingFk: null,
quantity: null,
created: Date.now(),
ticketFk: this.ticket.id
};
this.packages.push(data);
}
getPackages() {
this.packages = this.$.index.model;
this.setOldPackages();
}
setOldPackages() {
this.oldPackages = [];
this.packages.forEach(item => {
this.oldPackages[item.id] = item;
});
}
}
Controller.$inject = ['$http', '$scope'];
ngModule.component('vnTicketPackageList', {
template: require('./package-list.html'),
controller: Controller,
bindings: {
ticket: '<'
}
});