From c439fce1f097987de9176885dc6535b0a1403346 Mon Sep 17 00:00:00 2001 From: ckonstanski Date: Fri, 25 Dec 2020 19:49:35 -0700 Subject: initial commit --- src/org_ckons_cljs/notifications/core.cljs | 36 ++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 src/org_ckons_cljs/notifications/core.cljs (limited to 'src/org_ckons_cljs/notifications') diff --git a/src/org_ckons_cljs/notifications/core.cljs b/src/org_ckons_cljs/notifications/core.cljs new file mode 100644 index 0000000..8fc7926 --- /dev/null +++ b/src/org_ckons_cljs/notifications/core.cljs @@ -0,0 +1,36 @@ +(ns org-ckons-cljs.notifications.core + (:require-macros [hiccups.core :as hiccups :refer [html]]) + (:require [dommy.core :as dommy])) + +(declare template-message) +(declare template-error) +(declare maybe-error) +(declare maybe-message) + +(hiccups/defhtml template-message [message] + [:div {:class "alert alert-success"} message]) + +(hiccups/defhtml template-error [errormsg] + [:div {:class "alert alert-danger"} errormsg]) + +(defn maybe-message [jsonobj] + (when (get jsonobj "locationP") + (let [message (get jsonobj "message")] + (cond (empty? message) + (dommy/set-style! (dommy/sel1 :#message) :display "none") + :else + (do + (dommy/set-style! (dommy/sel1 :#message) :display "block") + (dommy/set-html! (dommy/sel1 :#message) + (template-message message))))))) + +(defn maybe-error [jsonobj] + (when (get jsonobj "locationP") + (let [errormsg (get jsonobj "errormsg")] + (cond (empty? errormsg) + (dommy/set-style! (dommy/sel1 :#errormsg) :display "none") + :else + (do + (dommy/set-style! (dommy/sel1 :#errormsg) :display "block") + (dommy/set-html! (dommy/sel1 :#errormsg) + (template-error errormsg))))))) -- cgit v1.3