Skip to content

Instantly share code, notes, and snippets.

@futuro

futuro/timepicker.cljs Secret

Created Feb 14, 2016
Embed
What would you like to do?
Cached function in componenetDidMount
(defn set-timekey [comp dbkey timeval]
(println "dbkey is " dbkey)
(om/transact! comp
`[(newevent/set-attr
{:value ~timeval
:attrkey ~dbkey})
:newevent]))
(defn set-beginning [comp timeval]
(set-timekey comp :newevent/beginning timeval))
(defn set-ending [comp timeval]
(set-timekey comp :newevent/ending timeval))
(defui TimePicker
static om/IQuery
(query [this]
[:db/id :newevent/beginning :newevent/ending])
Object
(componentDidMount [this]
(util/upgrade-mdl-components)
(let [{:keys [dbkey id]} (om/props this)
elem (util/elem-by-id id)
options (clj->js {:timeFormat "military"})
time-selected (condp = dbkey
:newevent/beginning #(set-beginning this %)
:newevent/ending #(set-ending this %)
#(.log js/console "No dbkey specified."))
tpicker (new js/TimePicker. time-selected)]
(.log js/console "key:%o:picker:%o:" (str dbkey) tpicker)
(.bindInput tpicker elem options)))
(render [this]
(let [{:keys [id desc dbkey] :as props} (om/props this)
time (get props dbkey)]
#_(println props)
(html
[:div {:class "time-picker" :position "relative"}
(create-time-input this time "text" id desc)]))))
(def timepicker (om/factory TimePicker {:keyfn :id}))
(defui CreateEvent
static om/IQuery
(query [this]
[{:newevent (om/get-query TimePicker)}])
Object
(render [this]
(let [props (om/props this)
active-button (om/get-state this :active-button)]
(html
[:div {:id "create-event"}
[:h2 "Create Event"]
[:div
[:div
(timepicker (merge {:id "ce-end" :desc "Choose an end time."
:dbkey :newevent/ending}
(get props :newevent)))
(timepicker (merge {:id "ce-beginning" :desc "Choose a start time."
:dbkey :newevent/beginning}
(get props :newevent)))]]])))
(componentDidMount [this]
(util/upgrade-mdl-components)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.