#1558 ticket.sales mark/unmark as reserved

This commit is contained in:
Carlos Jimenez Ruiz 2019-06-26 13:56:40 +02:00
parent 2ce442a022
commit d27402d4e6
1 changed files with 16 additions and 5 deletions

View File

@ -1,5 +1,6 @@
import ngModule from '../module';
import './style.scss';
import {throws} from 'assert';
class Controller {
constructor($scope, $state, $http, vnApp, $translate) {
@ -9,7 +10,6 @@ class Controller {
this.$state = $state;
this.$stateParams = $state.params;
this.$http = $http;
this.deletable = false;
this.edit = {};
this.moreOptions = [
{callback: this.markAsReserved, name: 'Mark as reserved'},
@ -336,11 +336,22 @@ class Controller {
}
setReserved(reserved) {
let sales = this.getCheckedLines();
let params = {sales: sales, ticketFk: this.ticket.id, reserved: reserved};
let selectedSales = this.getCheckedLines();
let params = {sales: selectedSales, ticketFk: this.ticket.id, reserved: reserved};
this.$http.post(`/api/Sales/reserve`, params).then(() => {
this.$scope.model.refresh();
let reservedSales = new Map();
this.$http.post(`/api/Sales/reserve`, params).then(res => {
let isReserved = res.config.data.reserved;
res.config.data.sales.forEach(sale => {
reservedSales.set(sale.id, {reserved: isReserved});
});
this.sales.forEach(sale => {
const reservedSale = reservedSales.get(sale.id);
if (reservedSale)
sale.reserved = reservedSale.reserved;
});
});
}