Skip to content

Instantly share code, notes, and snippets.

@aarkerio
Last active December 20, 2019 22:14
Show Gist options
  • Save aarkerio/2a672154842c68063e713ccbb6b67c87 to your computer and use it in GitHub Desktop.
Save aarkerio/2a672154842c68063e713ccbb6b67c87 to your computer and use it in GitHub Desktop.
;; Clojure hiccup file
[:button {:class "btn btn-success" :onClick (str "zentaur.core.deletetest("id")")} "Löschen"]
;; file: src/cljs/zentaur/core.cljs
(ns zentaur.core
(:require [ajax.core :refer [GET POST DELETE]]))
(defn delete-test [test-id]
(let [csrf-field (.-value (gdom/getElement "__anti-forgery-token"))]
(DELETE "/admin/tests/deletetest"
{:params {:test-id test-id}
:headers {"x-csrf-token" csrf-field}
:handler (fn [] (set! js/window.location.href "/admin/tests"))
:error-handler error-handler})))
(defn ^:export deletetest [test-id]
(when (js/confirm "Delete test?")
(delete-test test-id)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment