salix/modules/ticket/front/sale/editDiscount.js

83 lines
2.1 KiB
JavaScript
Raw Normal View History

import ngModule from '../module';
class Controller {
constructor($scope, $http, $state, vnApp, $translate) {
this.$scope = $scope;
this.$http = $http;
this.$state = $state;
this.vnApp = vnApp;
this.$translate = $translate;
}
set edit(value) {
this._edit = value;
2019-06-06 07:34:36 +00:00
this.clearDiscount();
this.setNewDiscount();
}
get edit() {
return this._edit;
}
set bulk(value) {
this._bulk = value;
this.setNewDiscount();
}
get bulk() {
return this._bulk;
}
setNewDiscount() {
if (!this.newDiscount && this.edit[0])
this.newDiscount = this.edit[0].discount;
}
updateDiscount() {
2019-06-05 11:39:15 +00:00
let salesIds = [];
let modified = false;
for (let i = 0; i < this.edit.length; i++) {
if (this.newDiscount != this.edit[0].discount || this.bulk || !this.newDiscount) {
2019-06-05 11:39:15 +00:00
salesIds.push(this.edit[i].id);
modified = true;
}
}
2019-05-29 09:11:54 +00:00
if (modified) {
2019-06-05 11:39:15 +00:00
const params = {salesIds: salesIds, newDiscount: this.newDiscount};
const query = `/api/Tickets/${this.$state.params.id}/updateDiscount`;
this.$http.post(query, params).then(() => {
this.vnApp.showSuccess(this.$translate.instant('Data saved!'));
2019-06-06 07:34:36 +00:00
this.clearDiscount();
modified = false;
2019-06-06 07:34:36 +00:00
this.vnTicketSale.$scope.model.refresh();
}).catch(e => {
this.vnApp.showError(e.data.error.message);
});
2019-05-06 05:40:59 +00:00
this.onHide();
2019-02-14 11:06:14 +00:00
} else
2019-05-29 09:11:54 +00:00
this.vnApp.showError(this.$translate.instant('There are no changes to save'));
}
2019-06-06 07:34:36 +00:00
clearDiscount() {
this.newDiscount = null;
}
}
Controller.$inject = ['$scope', '$http', '$state', 'vnApp', '$translate'];
ngModule.component('vnTicketSaleEditDiscount', {
template: require('./editDiscount.html'),
controller: Controller,
bindings: {
edit: '<?',
mana: '<?',
bulk: '<?',
2019-02-14 19:18:10 +00:00
onHide: '&'
2019-06-06 07:34:36 +00:00
},
require: {
vnTicketSale: '^vnTicketSale'
}
});