Tarea #284 Seccion ticket.lineas icono papelera para eliminar lineas
This commit is contained in:
parent
a9ade07aa0
commit
6544d0161c
|
@ -15,6 +15,13 @@
|
|||
url="/ticket/api/States/alertLevelIs0"
|
||||
on-change="$ctrl.onStateChange(value)">
|
||||
</vn-icon-menu>
|
||||
<vn-button
|
||||
disabled="!$ctrl.isChecked"
|
||||
ng-click="$ctrl.onRemoveLinesClick()"
|
||||
vn-tooltip="Remove lines"
|
||||
tooltip-position="right"
|
||||
icon="delete">
|
||||
</vn-button>
|
||||
</vn-tool-bar>
|
||||
<table class="vn-grid">
|
||||
<thead>
|
||||
|
|
|
@ -10,6 +10,16 @@ class Controller extends FilterTicketList {
|
|||
this.$http = $http;
|
||||
}
|
||||
|
||||
get isChecked() {
|
||||
let data = this.$.index.model.instances;
|
||||
if (data)
|
||||
for (let instance of data)
|
||||
if (instance.checked)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
onStateOkClick() {
|
||||
let filter = {where: {code: "OK"}, fields: ["id"]};
|
||||
let json = encodeURIComponent(JSON.stringify(filter));
|
||||
|
@ -25,6 +35,25 @@ class Controller extends FilterTicketList {
|
|||
});
|
||||
}
|
||||
|
||||
onRemoveLinesClick() {
|
||||
let lines = {
|
||||
delete: []
|
||||
};
|
||||
let data = this.$.index.model.instances;
|
||||
if (data)
|
||||
for (let i = 0; i < data.length;) {
|
||||
if (data[i].checked) {
|
||||
lines.delete.push(data[i].id);
|
||||
data.splice(i, 1);
|
||||
} else {
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
let query = `/ticket/api/Sales/crudSale`;
|
||||
this.$http.post(query, lines);
|
||||
}
|
||||
|
||||
showDescriptor(event, itemFk) {
|
||||
this.$.descriptor.itemFk = itemFk;
|
||||
this.$.descriptor.parent = event.target;
|
||||
|
|
|
@ -26,6 +26,18 @@ describe('Ticket', () => {
|
|||
controller = $componentController('vnTicketSale', {$scope: $scope}, {$state: $state});
|
||||
}));
|
||||
|
||||
describe('isChecked() setter/getter', () => {
|
||||
it('should set isChecked value to true when one of the instances has the value checked to true', () => {
|
||||
let lines = [
|
||||
{checked: false},
|
||||
{checked: true}
|
||||
];
|
||||
$scope.index.model.instances = lines;
|
||||
|
||||
expect(controller.isChecked).toBeTruthy();
|
||||
});
|
||||
});
|
||||
|
||||
describe('onStateOkClick()', () => {
|
||||
it('should perform a get and then call a function', () => {
|
||||
let filter = {where: {code: "OK"}, fields: ["id"]};
|
||||
|
@ -50,5 +62,21 @@ describe('Ticket', () => {
|
|||
$httpBackend.flush();
|
||||
});
|
||||
});
|
||||
|
||||
describe('onRemoveLinesClick()', () => {
|
||||
it('should remove an object of the model if has the attribute cheched true', () => {
|
||||
$scope.index.model.instances = [{id: 1, checked: true}, {id: 2, checked: false}];
|
||||
controller.onRemoveLinesClick();
|
||||
|
||||
expect($scope.index.model.instances).toEqual([{id: 2, checked: false}]);
|
||||
});
|
||||
|
||||
it('should make a post if an object the model has the attribute cheched true', () => {
|
||||
$scope.index.model.instances = [{id: 1, checked: false}, {id: 2, checked: false}];
|
||||
$httpBackend.expectPOST(`/ticket/api/Sales/crudSale`).respond();
|
||||
controller.onRemoveLinesClick();
|
||||
$httpBackend.flush();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue