diff --git a/modules/entry/front/latest-buys/index.html b/modules/entry/front/latest-buys/index.html index adeda5e56..768c8c7ee 100644 --- a/modules/entry/front/latest-buys/index.html +++ b/modules/entry/front/latest-buys/index.html @@ -4,6 +4,7 @@ order="itemFk DESC" limit="20" data="$ctrl.buys" + on-data-change="$ctrl.reCheck()" auto-load="true"> @@ -21,7 +22,7 @@ @@ -123,17 +124,18 @@ @@ -186,7 +188,7 @@ - + @@ -231,7 +233,7 @@ - diff --git a/modules/entry/front/latest-buys/index.js b/modules/entry/front/latest-buys/index.js index ec1109b81..198d38eff 100644 --- a/modules/entry/front/latest-buys/index.js +++ b/modules/entry/front/latest-buys/index.js @@ -7,6 +7,7 @@ export default class Controller extends Section { super($element, $); this.editedColumn; this.checkAll = false; + this.checkedBuys = []; this.smartTableOptions = { activeButtons: { @@ -139,6 +140,7 @@ export default class Controller extends Section { uncheck() { this.checkAll = false; + this.checkedBuys = []; } get totalChecked() { @@ -148,6 +150,23 @@ export default class Controller extends Section { return this.checked.length; } + saveChecked(buyId) { + const index = this.checkedBuys.indexOf(buyId); + if (index !== -1) + return this.checkedBuys.splice(index, 1); + return this.checkedBuys.push(buyId); + } + + reCheck() { + if (!this.$.model.data) return; + if (!this.checkedBuys.length) return; + + this.$.model.data.forEach(buy => { + if (this.checkedBuys.includes(buy.id)) + buy.checked = true; + }); + } + onEditAccept() { const rowsToEdit = []; for (let row of this.checked) diff --git a/modules/entry/front/latest-buys/index.spec.js b/modules/entry/front/latest-buys/index.spec.js index 76e122d80..6574303fc 100644 --- a/modules/entry/front/latest-buys/index.spec.js +++ b/modules/entry/front/latest-buys/index.spec.js @@ -57,5 +57,44 @@ describe('Entry', () => { expect(result.length).toEqual(0); }); }); + + describe('reCheck()', () => { + it(`should recheck buys`, () => { + controller.$.model.data = [ + {checked: false, id: 1}, + {checked: false, id: 2}, + {checked: false, id: 3}, + {checked: false, id: 4}, + ]; + controller.checkedBuys = [1, 2]; + + controller.reCheck(); + + expect(controller.$.model.data[0].checked).toEqual(true); + expect(controller.$.model.data[1].checked).toEqual(true); + expect(controller.$.model.data[2].checked).toEqual(false); + expect(controller.$.model.data[3].checked).toEqual(false); + }); + }); + + describe('saveChecked()', () => { + it(`should check buy`, () => { + const buyCheck = 3; + controller.checkedBuys = [1, 2]; + + controller.saveChecked(buyCheck); + + expect(controller.checkedBuys[2]).toEqual(buyCheck); + }); + + it(`should uncheck buy`, () => { + const buyUncheck = 3; + controller.checkedBuys = [1, 2, 3]; + + controller.saveChecked(buyUncheck); + + expect(controller.checkedBuys[2]).toEqual(undefined); + }); + }); }); });
- - - + {{::buy.packing | dashIfEmpty}} - + {{::buy.grouping | dashIfEmpty}} {{::buy.family}} @@ -204,7 +206,7 @@ - + {{::buy.price2 | currency: 'EUR':2}} {{::buy.price3 | currency: 'EUR':2}}