From 96c0d221928b785b4dfcb41df62968944cf498d9 Mon Sep 17 00:00:00 2001 From: Eduard Urbach Date: Tue, 17 Oct 2017 11:43:07 +0200 Subject: [PATCH] Implemented soundtrack deletion --- pages/soundtrack/edit.go | 15 ++++++++++++--- scripts/Actions.ts | 1 + scripts/Actions/Delete.ts | 17 +++++++++++++++++ 3 files changed, 30 insertions(+), 3 deletions(-) create mode 100644 scripts/Actions/Delete.ts diff --git a/pages/soundtrack/edit.go b/pages/soundtrack/edit.go index 94569065..59c06a23 100644 --- a/pages/soundtrack/edit.go +++ b/pages/soundtrack/edit.go @@ -19,6 +19,7 @@ import ( func Edit(ctx *aero.Context) string { id := ctx.Get("id") track, err := arn.GetSoundTrack(id) + user := utils.GetUser(ctx) if err != nil { return ctx.Error(http.StatusNotFound, "Track not found", err) @@ -37,11 +38,11 @@ func Edit(ctx *aero.Context) string { ctx.Data.(*arn.OpenGraph).Tags["og:image"] = track.MainAnime().Image.Large } - return ctx.HTML(components.SoundTrackTabs(track) + EditForm(track, "Edit soundtrack")) + return ctx.HTML(components.SoundTrackTabs(track) + EditForm(track, "Edit soundtrack", user)) } // EditForm ... -func EditForm(obj interface{}, title string) string { +func EditForm(obj interface{}, title string, user *arn.User) string { t := reflect.TypeOf(obj).Elem() v := reflect.ValueOf(obj).Elem() id := reflect.Indirect(v.FieldByName("ID")) @@ -59,6 +60,12 @@ func EditForm(obj interface{}, title string) string { RenderObject(&b, obj, "") + if user != nil && (user.Role == "editor" || user.Role == "admin") { + b.WriteString(`
`) + b.WriteString(``) + b.WriteString(`
`) + } + b.WriteString("") b.WriteString("") @@ -119,7 +126,9 @@ func RenderField(b *bytes.Buffer, v *reflect.Value, field reflect.StructField, i b.WriteString(``) } - b.WriteString(`
`) + b.WriteString(`
`) + b.WriteString(``) + b.WriteString(`
`) default: panic("No edit form implementation for " + idPrefix + field.Name + " with type " + field.Type.String()) } diff --git a/scripts/Actions.ts b/scripts/Actions.ts index 60d4a79e..71138565 100644 --- a/scripts/Actions.ts +++ b/scripts/Actions.ts @@ -1,4 +1,5 @@ export * from "./Actions/AnimeList" +export * from "./Actions/Delete" export * from "./Actions/Diff" export * from "./Actions/FollowUser" export * from "./Actions/Forum" diff --git a/scripts/Actions/Delete.ts b/scripts/Actions/Delete.ts new file mode 100644 index 00000000..23559b91 --- /dev/null +++ b/scripts/Actions/Delete.ts @@ -0,0 +1,17 @@ +import { AnimeNotifier } from "../AnimeNotifier" + +// 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 + } + + let endpoint = arn.findAPIEndpoint(button) + + arn.post(endpoint + "/delete", "") + .then(() => arn.app.load(returnPath)) + .catch(err => arn.statusMessage.showError(err)) +} \ No newline at end of file