61 lines
1.4 KiB
JavaScript
61 lines
1.4 KiB
JavaScript
|
import ngModule from '../module';
|
||
|
|
||
|
class Controller {
|
||
|
constructor($, _, $http, $stateParams) {
|
||
|
Object.assign(this, {
|
||
|
$,
|
||
|
$http
|
||
|
});
|
||
|
|
||
|
this.path = `/api/Zones/${$stateParams.id}/warehouses`;
|
||
|
this.refresh();
|
||
|
}
|
||
|
|
||
|
refresh() {
|
||
|
let filter = {include: 'warehouse'};
|
||
|
this.$http.get(this.path, {params: {filter}})
|
||
|
.then(res => this.$.data = res.data);
|
||
|
}
|
||
|
|
||
|
onCreate() {
|
||
|
this.selected = {};
|
||
|
this.$.dialog.show();
|
||
|
}
|
||
|
|
||
|
onSave(response) {
|
||
|
if (response != 'ACCEPT') return;
|
||
|
|
||
|
this.$http.post(this.path, this.selected)
|
||
|
.then(() => {
|
||
|
this.selected = null;
|
||
|
this.isNew = null;
|
||
|
this.$.dialog.hide();
|
||
|
this.refresh();
|
||
|
});
|
||
|
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
onDelete(index) {
|
||
|
this.$.confirm.show();
|
||
|
this.deleteIndex = index;
|
||
|
}
|
||
|
|
||
|
delete(response) {
|
||
|
if (response != 'ACCEPT') return;
|
||
|
let id = this.$.data[this.deleteIndex].id;
|
||
|
if (!id) return;
|
||
|
this.$http.delete(`${this.path}/${id}`)
|
||
|
.then(() => {
|
||
|
this.$.data.splice(this.deleteIndex, 1);
|
||
|
this.deleteIndex = null;
|
||
|
});
|
||
|
}
|
||
|
}
|
||
|
Controller.$inject = ['$scope', '$translate', '$http', '$stateParams'];
|
||
|
|
||
|
ngModule.component('vnZoneWarehouses', {
|
||
|
template: require('./index.html'),
|
||
|
controller: Controller
|
||
|
});
|