From b56b50cd732d9f0dd0bd21d952587e1e530dde8a Mon Sep 17 00:00:00 2001 From: Nicholas Kariniemi Date: Fri, 26 Jul 2013 23:47:32 +0300 Subject: [PATCH] Display todo list client side with button, onclick event --- project.clj | 4 +++- src-clj/grub/core.clj | 19 ----------------- src-cljs/grub_client/core.cljs | 39 ++++++++++++++++++++++++++++++++-- 3 files changed, 40 insertions(+), 22 deletions(-) diff --git a/project.clj b/project.clj index 0d123c4..a666870 100644 --- a/project.clj +++ b/project.clj @@ -9,7 +9,9 @@ [compojure "1.1.5"] [ring/ring-devel "1.2.0"] [ring/ring-core "1.2.0"] - [hiccup "1.0.4"]] + [hiccup "1.0.4"] + [prismatic/dommy "0.1.1"] + [core.async "0.1.0-SNAPSHOT"]] :plugins [[lein-cljsbuild "0.3.2"] [lein-ring "0.8.6"]] :cljsbuild { diff --git a/src-clj/grub/core.clj b/src-clj/grub/core.clj index 54df867..2ad4a38 100644 --- a/src-clj/grub/core.clj +++ b/src-clj/grub/core.clj @@ -20,17 +20,6 @@ (send! channel {:status 200 :headers {"Content-Type" "text/plain"} :body "Long polling?"})))) -(def test-grubs - ["8 dl water" - "8 whole peppercorns" - "2 bay leaves" - "1 - 2 (150 g) onions" - "750 g potato" - "600 g salmon" - "1 t. salt" - "2 dl cream" - "1 dl dill"]) - (defn index-page [] (html5 [:head @@ -39,14 +28,6 @@ (include-css "/css/bootstrap.css") (include-css "/css/bootstrap-responsive.css")] [:body - [:div.container - [:div.row-fluid - [:div.span8.offset2 - [:h2 "Grub"] - [:table.table - [:tbody - (for [grub test-grubs] - [:tr [:td [:label.checkbox [:input {:type :checkbox} grub]]]])]]]]] (include-js "http://code.jquery.com/jquery.js") (include-js "/js/bootstrap.js") (include-js "/js/main.js")])) diff --git a/src-cljs/grub_client/core.cljs b/src-cljs/grub_client/core.cljs index e38c048..3b9a649 100644 --- a/src-cljs/grub_client/core.cljs +++ b/src-cljs/grub_client/core.cljs @@ -1,3 +1,38 @@ -(ns grub-client.core) +(ns grub-client.core + (:use-macros [dommy.macros :only [deftemplate sel1 node]]) + (:require [dommy.core :as dommy])) -(.log js/console "ClojureScript running") +(defn log [& args] + (apply #(.log js/console %) args)) + +(def test-grubs + ["8 dl water" + "8 whole peppercorns" + "2 bay leaves" + "1 - 2 (150 g) onions" + "2 dl cream" + "1 dl dill"]) + +(deftemplate grub-template [grub] + [:tr + [:td + [:label.checkbox [:input {:type "checkbox"}] grub]]]) + +(deftemplate main-template [grubs] + [:div.container + [:div.row-fluid + [:div.span8.offset2 + [:h2 "Grub List"] + [:table.table + [:tbody + (for [grub grubs] (grub-template grub))]] + [:div.input-append + [:input.span2#addGrubText {:type "text"}] + [:button.btn#addGrubButton {:type "button"} "Add"]]]]]) + +(defn onClicked [] + (log "onClicked")) + +(dommy/prepend! (sel1 :body) (main-template test-grubs)) + +(dommy/listen! (sel1 :#addGrubButton) :click onClicked)