2018-03-15 13:36:09 +00:00
|
|
|
import ngModule from '../../module';
|
|
|
|
|
|
|
|
class Controller {
|
|
|
|
|
2018-03-21 10:08:59 +00:00
|
|
|
constructor($http, $scope, $translate, vnApp) {
|
2018-03-15 13:36:09 +00:00
|
|
|
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;
|
|
|
|
});
|
2018-03-15 13:36:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Controller.$inject = ['$http', '$scope'];
|
|
|
|
|
|
|
|
ngModule.component('vnTicketPackageList', {
|
|
|
|
template: require('./package-list.html'),
|
|
|
|
controller: Controller,
|
|
|
|
bindings: {
|
|
|
|
ticket: '<'
|
|
|
|
}
|
|
|
|
});
|