2019-09-25 18:06:42 +00:00
|
|
|
import ngModule from '../module';
|
2020-03-18 11:55:22 +00:00
|
|
|
import Section from 'salix/components/section';
|
2019-09-25 18:06:42 +00:00
|
|
|
|
2020-03-18 11:55:22 +00:00
|
|
|
class Controller extends Section {
|
2020-06-17 09:51:57 +00:00
|
|
|
$onInit() {
|
2019-09-25 18:06:42 +00:00
|
|
|
this.refresh();
|
|
|
|
}
|
|
|
|
|
2020-06-17 09:51:57 +00:00
|
|
|
get path() {
|
|
|
|
return `Zones/${this.$params.id}/warehouses`;
|
|
|
|
}
|
|
|
|
|
2019-09-25 18:06:42 +00:00
|
|
|
refresh() {
|
|
|
|
let filter = {include: 'warehouse'};
|
|
|
|
this.$http.get(this.path, {params: {filter}})
|
|
|
|
.then(res => this.$.data = res.data);
|
|
|
|
}
|
|
|
|
|
|
|
|
onCreate() {
|
|
|
|
this.selected = {};
|
|
|
|
this.$.dialog.show();
|
|
|
|
}
|
|
|
|
|
2020-07-29 08:47:48 +00:00
|
|
|
onSave() {
|
2019-09-25 18:06:42 +00:00
|
|
|
this.$http.post(this.path, this.selected)
|
|
|
|
.then(() => {
|
|
|
|
this.selected = null;
|
|
|
|
this.isNew = null;
|
|
|
|
this.$.dialog.hide();
|
|
|
|
this.refresh();
|
|
|
|
});
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-01-22 15:32:01 +00:00
|
|
|
onDelete(row) {
|
2019-09-25 18:06:42 +00:00
|
|
|
this.$.confirm.show();
|
2020-01-22 15:32:01 +00:00
|
|
|
this.deleteRow = row;
|
2019-09-25 18:06:42 +00:00
|
|
|
}
|
|
|
|
|
2020-01-22 15:32:01 +00:00
|
|
|
delete() {
|
|
|
|
let row = this.deleteRow;
|
|
|
|
if (!row) return;
|
|
|
|
return this.$http.delete(`${this.path}/${row.id}`)
|
2019-09-25 18:06:42 +00:00
|
|
|
.then(() => {
|
2020-01-22 15:32:01 +00:00
|
|
|
let index = this.$.data.indexOf(row);
|
|
|
|
if (index !== -1) this.$.data.splice(index, 1);
|
|
|
|
this.deleteRow = null;
|
2019-09-25 18:06:42 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-24 12:22:30 +00:00
|
|
|
ngModule.vnComponent('vnZoneWarehouses', {
|
2019-09-25 18:06:42 +00:00
|
|
|
template: require('./index.html'),
|
|
|
|
controller: Controller
|
|
|
|
});
|