Permalink
Browse files

pop up a dialog for user input

  • Loading branch information...
1 parent f7279f3 commit 4e76c94e5d932bd31c0044eec84cd3da9b90546e @netguy204 committed Jul 7, 2012
Showing with 103 additions and 4 deletions.
  1. +1 −0 index-dev.html
  2. +72 −0 resources/dialog.css
  3. +2 −2 runtests.watchr
  4. +8 −0 src-cljs/move/events.cljs
  5. +3 −1 src-cljs/move/interactors.cljs
  6. +16 −0 src-cljs/move/views.cljs
  7. +1 −1 test-cljs/move/test.cljs
View
@@ -3,6 +3,7 @@
<script src="closure/goog/base.js"></script>
<script src="javascripts/main.js"></script>
<link rel="stylesheet" href="resources/tree.css" type="text/css" media="screen" />
+ <link rel="stylesheet" href="resources/dialog.css" type="text/css" media="screen" />
</head>
<body>
View
@@ -0,0 +1,72 @@
+/*
+ * Copyright 2009 The Closure Library Authors. All Rights Reserved.
+ *
+ * Use of this source code is governed by the Apache License, Version 2.0.
+ * See the COPYING file for details.
+ */
+
+/*
+ * Standard styling for goog.ui.Dialog.
+ *
+ * @author ssaviano@google.com (Steven Saviano)
+ * @author attila@google.com (Attila Bodis)
+ */
+
+
+.modal-dialog {
+ background: #c1d9ff;
+ border: 1px solid #3a5774;
+ color: #000;
+ padding: 4px;
+ position: absolute;
+}
+
+.modal-dialog a,
+.modal-dialog a:link,
+.modal-dialog a:visited {
+ color: #06c;
+ cursor: pointer;
+}
+
+.modal-dialog-bg {
+ background: #666;
+ left: 0;
+ position: absolute;
+ top: 0;
+}
+
+.modal-dialog-title {
+ background: #e0edfe;
+ color: #000;
+ cursor: pointer;
+ font-size: 120%;
+ font-weight: bold;
+
+ /* Add padding on the right to ensure the close button has room. */
+ padding: 8px 31px 8px 8px;
+
+ position: relative;
+ _zoom: 1; /* Ensures proper width in IE6 RTL. */
+}
+
+.modal-dialog-title-close {
+ /* Client apps may override the URL at which they serve the sprite. */
+ background: #e0edfe url(//ssl.gstatic.com/editor/editortoolbar.png) no-repeat -528px 0;
+ cursor: default;
+ height: 15px;
+ position: absolute;
+ right: 10px;
+ top: 8px;
+ width: 15px;
+ vertical-align: middle;
+}
+
+.modal-dialog-buttons,
+.modal-dialog-content {
+ background-color: #fff;
+ padding: 8px;
+}
+
+.goog-buttonset-default {
+ font-weight: bold;
+}
View
@@ -1,3 +1,3 @@
-watch( '(.*)cljs/move/(.*)\.cljs' ) { system("rm -rf resources/private/js"); system("lein cljsbuild test"); }
+watch( '(.*)cljs/move/(.*)\.cljs' ) { system("rm -rf resources/private/js"); system("lein cljsbuild test unit"); }
-watch( 'src/move/(.*)\.clj' ) { system("rm -rf resources/private/js"); system("lein cljsbuild test"); }
+watch( 'src/move/(.*)\.clj' ) { system("rm -rf resources/private/js"); system("lein cljsbuild test unit"); }
@@ -18,6 +18,14 @@
(fn [bindings]
(remove #(identical? binding %) bindings))))
+(defn register-once [event callback & curried]
+ (let [binding (atom nil)
+ new-callback (fn [& args]
+ (unregister event @binding)
+ (apply callback args))]
+ (reset! binding (apply register event new-callback curried))
+ @binding))
+
(defn fire [event & args]
"event is either a single value or a sequence."
(binding [*current-event* event]
@@ -35,7 +35,9 @@
(defasync create-new-todo [state view]
"[async] create a new item in the current list"
[list (models/current-list state)
- item (models/add-todo state list "EMPTY")]
+ input-dialog (views/make-input-dialog "Todo name?")
+ input [events/register-once [:ok-clicked input-dialog]]
+ item (models/add-todo state list input)]
item)
View
@@ -1,6 +1,8 @@
(ns move.views
(:require [goog.ui.tree.TreeControl :as TreeControl]
[goog.ui.Button :as Button]
+ [goog.ui.Dialog :as Dialog]
+ [goog.ui.LabelInput :as LabelInput]
[goog.dom :as dom]
[goog.events :as ge]
[move.events :as events]))
@@ -92,3 +94,17 @@
(append-item [view item] true)
(clear-items [view] true)
(set-name [view name] true)))
+
+
+(defn make-input-dialog [message]
+ (let [dialog (goog/ui.Dialog.)
+ input (goog/ui.LabelInput. "type here")]
+ (.setTitle dialog message)
+ (.addChild dialog input true)
+ (.setVisible dialog true)
+ (.focusAndSelect input)
+
+ (ge/listen dialog (.-SELECT goog/ui.Dialog.EventType)
+ #(events/fire [:ok-clicked dialog] (.getValue input)))
+
+ dialog))
View
@@ -23,7 +23,7 @@
[content (dom/getElement "content")
view (views/make-web-view content)
_ (views/set-items view ["one" "two" "three"])
- _ (views/set-list-name view "sizzle")]
+ _ (views/set-name view "sizzle")]
(assert-true (= 3 (count (.getChildren (:list view)))))
(assert-true (= "sizzle" (.getText (:list view))))))

0 comments on commit 4e76c94

Please sign in to comment.