Permalink
Browse files

Created a reservation new page and linked to it

  • Loading branch information...
1 parent a0690c9 commit 852bee35f56fca0e63fc1987c4dc5893c6ca4383 David Davis committed Aug 12, 2012
Showing with 28 additions and 12 deletions.
  1. +26 −12 src/shared_resource/views/reservations.clj
  2. +2 −0 src/shared_resource/views/resource.clj
@@ -5,6 +5,7 @@
hiccup.element
hiccup.form)
(:require [shared-resource.models.reservation :as reservation]
+ [shared-resource.models.resource :as resource]
[shared-resource.views.common :as common]
[noir.response :as resp]
[noir.session :as session]))
@@ -19,19 +20,32 @@
(defpartial reservation-list [reservations]
[:div.reservations (map reservation-div reservations)])
-(defpartial new-reservation-page [start end resource]
- [:div.new-reservation])
+(defn resource-options []
+ (map #(conj [] (:name %) (:id %)) (resource/get-all)))
+
+(defpartial new-reservation-page [resource start end]
+ (common/layout
+ (form-to [:post "/reservations"]
+ (label "resource" "Resource: ")
+ (drop-down "resource" (resource-options) (Long/parseLong resource))
+ (label "start" "Start: ")
+ (text-field "start")
+ (label "end" "End: ")
+ (text-field "end")
+ (submit-button "Submit"))))
;; Routes
-(defpage "/reservations/new" []
- (new-reservation-page "" "" ""))
+(defpage "/reservations/new" {:keys [resource]}
+ (new-reservation-page resource "" ""))
-(defpage [:post "/reservations"] {:keys [start end resource]}
- (if (reservation/create-reservation resource (session/get :user) start end)
- (do
- (session/flash-put! :success "Successfully create reservation.")
- (resp/redirect (str "/resources/" resource)))
- (do
- (session/flash-put! :error "Failed to log in.")
- (new-reservation-page start end resource))))
+(defpage [:post "/reservations"] {:keys [resource start end]}
+ (let [resource-id (Long/parseLong resource)
+ user-id (session/get :user)]
+ (if (reservation/create-reservation resource-id user-id start end)
+ (do
+ (session/flash-put! :success "Successfully create reservation.")
+ (resp/redirect (str "/resources/" resource)))
+ (do
+ (session/flash-put! :error "Failed to save reservation.")
+ (new-reservation-page start end resource)))))
@@ -44,6 +44,8 @@
(rpage/reservation-list (reservation/get-by-resource-id (:id resource-item)))
[:span "No reservations have been made."])
)]
+ [:div.actions
+ (link-to (str "/reservations/new?resource=" (:id resource-item)) "Create a reservartion")]
)
(defpartial resources-page [resources]

0 comments on commit 852bee3

Please sign in to comment.