angular.module('footyroom').component('tipEditor', { template: /* html */ `
`, bindings: { id: '@', dismiss: '&', }, controller: [ '$http', function ($http) { const vm = this; vm.$onInit = init; vm.save = save; vm.remove = remove; function init() { if (vm.id) { vm.isLoading = true; $http.get(`/tips/${this.id}.json`).then(function (response) { vm.tip = response.data; vm.isLoading = false; }); } else { vm.tip = { status: 'pending', }; } } function save() { vm.isSaving = true; const persist = vm.tip.id ? $http.put(`/tips/${vm.tip.id}`, vm.tip) : $http.post('/tips', vm.tip); persist .then(() => { window.location.reload(); }) .catch(() => { vm.isSaving = false; }); } function remove() { vm.isSaving = true; $http.delete(`/tips/${this.id}`) .then(() => { window.location.reload(); }) .catch(() => { vm.isSaving = false; }); } }, ], });