34 lines
991 B
TypeScript
Raw Normal View History

2018-04-02 05:34:16 +00:00
import AnimeNotifier from "../AnimeNotifier"
2017-10-17 09:43:07 +00:00
2017-10-17 21:17:04 +00:00
// New
export function newObject(arn: AnimeNotifier, button: HTMLButtonElement) {
let dataType = button.dataset.type
2018-04-25 16:59:23 +00:00
arn.post(`/api/new/${dataType}`)
2017-10-17 21:17:04 +00:00
.then(response => response.json())
.then(obj => arn.app.load(`/${dataType}/${obj.id}/edit`))
.catch(err => arn.statusMessage.showError(err))
}
2017-10-17 09:43:07 +00:00
// Delete
export function deleteObject(arn: AnimeNotifier, button: HTMLButtonElement) {
let confirmType = button.dataset.confirmType
let returnPath = button.dataset.returnPath
if(!confirm(`Are you sure you want to delete this ${confirmType}?`)) {
return
}
2018-03-26 19:54:53 +00:00
// Double confirmation on anime
if(confirmType === "anime") {
if(!confirm(`Just making sure because this is not reversible. Are you absolutely sure you want to delete this ${confirmType}?`)) {
return
}
}
2017-10-17 09:43:07 +00:00
let endpoint = arn.findAPIEndpoint(button)
2018-04-25 16:59:23 +00:00
arn.post(endpoint + "/delete")
2017-10-17 09:43:07 +00:00
.then(() => arn.app.load(returnPath))
.catch(err => arn.statusMessage.showError(err))
}