add js to make delete buttons more fool-proof

integration-tests
Josha von Gizycki 6 years ago
parent 02063e8405
commit b91c3888f9

1
.gitignore vendored

@ -11,3 +11,4 @@ pom.xml.asc
/resources/public/css
.idea
*.iml
figwheel_server.log

@ -2,23 +2,30 @@
:description "FIXME: write description"
:url "http://example.com/FIXME"
:min-lein-version "2.0.0"
:dependencies [[org.clojure/clojure "1.9.0"]
[org.clojure/clojurescript "1.9.521"]
[compojure "1.6.1"]
[ring/ring-defaults "0.3.2"]
[hiccup "1.0.5"]
[gorillalabs/neo4j-clj "1.1.0"
:exclusions [org.bouncycastle/bcprov-jdk15on
org.bouncycastle/bcpkix-jdk15on
com.github.ben-manes.caffeine/caffeine]]
[hiccup "1.0.5"]
[buddy/buddy-hashers "1.3.0"
:exclusions [commons-codec]]
[clj-time "0.14.4"]]
:plugins [[lein-ring "0.9.7"]]
:ring {:handler wanijo.handler/app}
:profiles {:dev {:dependencies [[javax.servlet/servlet-api "2.5"]
[ring/ring-mock "0.3.2"]]
:plugins [[lein-less "1.7.5"]
[joshavg/lein-neo4j "0.3.0"]]}}
:plugins [[joshavg/lein-neo4j "0.3.0"]
[lein-less "1.7.5"]
[lein-ring "0.9.7"]]}
:uberjar {:aot :all}}
:ring {:handler wanijo.handler/app}
:less {:source-paths ["resources/app/stylesheets"]
:target-path "resources/public/css"}
:hiera {:cluster-depth 2})

@ -176,6 +176,10 @@ form {
font-family: monospace;
}
}
.delete-btn.__on-countdown {
font-weight: bold;
}
}
form.inline {

@ -0,0 +1,44 @@
document.addEventListener('DOMContentLoaded', function() {
function label(element, value) {
if(element.hasAttribute('value')) {
if(value !== undefined) {
element.setAttribute('value', value)
} else {
return element.getAttribute('value')
}
} else {
if(value !== undefined) {
element.textContent = value
} else {
return element.textContent
}
}
}
function countdownDeleteButton(event) {
const btn = event.target
const countdown = btn.getAttribute('data-countdown')
if(countdown != 0) {
event.preventDefault()
btn.classList.add('__on-countdown')
const hasCountdown = countdown !== null
const newCountdown = hasCountdown ? countdown - 1 : 3
if(!hasCountdown) {
btn.setAttribute('data-label', label(btn))
}
label(btn, newCountdown)
btn.setAttribute('data-countdown', newCountdown)
setTimeout(countdownDeleteButton, 1000, event)
} else {
label(btn, btn.getAttribute('data-label'))
}
}
document.querySelectorAll('.delete-btn').forEach(function(btn) {
btn.addEventListener('click', countdownDeleteButton)
})
})

@ -1,6 +1,6 @@
(ns wanijo.framework.view
(:require [hiccup.page :refer
[html5 include-css]]
[html5 include-css include-js]]
[wanijo.framework.routing :refer [path]]))
(defn btnlink
@ -26,7 +26,8 @@
:content "width=device-width,initial-scale=1,shrink-to-fit=no"}]
[:title (str "wan ijo" (when title (str " - " title)))]
(include-css "/css/app.css")
(when devmode? (include-css "/css/devmode.css"))]
(when devmode? (include-css "/css/devmode.css"))
(include-js "/js/frontend.js")]
[:body
[:section.grid
[:header

@ -52,7 +52,7 @@
(prettify-dt (:created_at schema))]])]]
[:h1 "New schema"]
(hform/form-to [:post (path :schema-new)]
(form/render-form form {} req)
(form/render-widgets form {} req)
(hform/submit-button "Create"))])))
(defn show-schema! [schema attrs req]
@ -77,7 +77,7 @@
(hform/form-to [:delete (path :attribute-delete attr)]
(anti-forgery-field)
(hform/hidden-field "schema" (:uuid schema))
(hform/submit-button "Delete!")
(hform/submit-button {:class "delete-btn"} "Delete!")
[:label "Created at " [:em (prettify-dt (:created_at attr))]])])]
[:h3 "New attribute"]
(hform/form-to [:post (path :attribute-new)]
@ -88,4 +88,4 @@
(hform/form-to {:class "inline"}
[:delete (path :schema-delete schema)]
(anti-forgery-field)
(hform/submit-button "Delete!"))]))
(hform/submit-button {:class "delete-btn"} "Delete!"))]))

Loading…
Cancel
Save