summaryrefslogtreecommitdiff
path: root/src/org_ckons_cljs
diff options
context:
space:
mode:
authorckonstanski <ckonstanski@pippiandcarlos.com>2020-12-25 19:49:35 -0700
committerckonstanski <ckonstanski@pippiandcarlos.com>2020-12-25 19:49:35 -0700
commitc439fce1f097987de9176885dc6535b0a1403346 (patch)
tree7a1f59f801cd696981520f2ecb5d39b019d3f459 /src/org_ckons_cljs
initial commit
Diffstat (limited to 'src/org_ckons_cljs')
-rw-r--r--src/org_ckons_cljs/notifications/core.cljs36
1 files changed, 36 insertions, 0 deletions
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)))))))