Skip to content

Instantly share code, notes, and snippets.

@swannodette
Last active December 10, 2015 08:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save swannodette/65ee1280c5c725ae9214 to your computer and use it in GitHub Desktop.
Save swannodette/65ee1280c5c725ae9214 to your computer and use it in GitHub Desktop.
(ns store.admin.forms
(:require [domina :as d]
[domina.events :as e]
[store.helpers :as sh]))
(defn add-model-name []
(e/listen! (d/by-id "add-model") :click
(fn [evt]
(e/prevent-default evt)
(sh/ajax-response (d/attr (d/by-id "add-model") :href)
(fn [content]
(sh/create-dialog
{:title "Create Model"
:body content}))))))
(defn ^:export main []
(add-model-name))
;;Helper functions called from store.admin.forms
(ns store.helpers
(:require [goog.ui.Dialog :as dlg]
[simple-xhr :as sxhr]
[goog.Uri :as uri]))
(defn create-dialog [{dtitle :title dbody :body }]
(doto (new goog.ui.Dialog)
(.setContent dbody)
(.setTitle dtitle)
(.setVisible true)
(.setModal true)))
(defn ajax-response [url callback]
(sxhr/request
:url (goog.Uri. url)
:method "GET"
:complete
(fn [xhrio]
(let [content (.getResponseXml xhrio)]
(callback content)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment