;;;; user.lisp (in-package :vampire) ;;; CLIENT UI (defun create-new-playlist-form (parent) (with-clog-create parent (form () (section (:h2 :content "Create New Playlist")) (label (:content "Playlist Title:")) (form-element (:text :bind pl-title)) (button (:content "Create" :bind btn))) (set-on-click btn (thunk* (new-playlist (session-user parent) :title (value pl-title)) (reload (location (connection-body parent))))))) (defun url-to-playlist (pl) (format nil "/playlist/~a" (key pl))) (defun create-playlist-listing (parent) (dolist (pl (user-playlists (session-user parent))) (let ((url (url-to-playlist pl))) (with-clog-create parent (div (:bind pl-item) (p () (a (:link url :content (playlist-title pl))) (button (:content "X" :bind btn)))) (set-on-click btn (thunk* (destroy-playlist pl) (destroy pl-item))))))) (defun create-invite-list-item (invite-list invite) (with-clog-create invite-list (list-item (:bind item) (button (:bind delbtn :content "delete")) (p () (span (:content "Code: ")) (span (:content (key invite)))) (p () (span (:content "Uses Remaining: ")) (span (:content (format nil "~a" (or (uses-remaining invite) "unlimited")))))) (set-on-click delbtn (thunk* (destroy-invite invite) (destroy item)))) ) (defun create-invite-control (parent) (let* ((user (session-user parent)) (container (create-div parent)) (invite-list (create-unordered-list parent))) (place-after (create-section container :h3 :content "Your Invites") invite-list) ;; list invites (dolist (invite (invites-by-maker user)) (create-invite-list-item invite-list invite)) (with-clog-create container (form () (button (:bind createbtn :content "Create Invite")) (form-element (:number :bind count)) (p (:content "Uses are optional. Blank or Zero means unlimited use."))) (setf (minimum count) 0 (place-holder count) "Uses" (width count) 70) (set-on-click createbtn (thunk* (let ((invite (make-invite user (parse-integer (value count) :junk-allowed t)))) (create-invite-list-item invite-list invite))))))) (defun user-home-page (body) (include-style body) (with-clog-create body (div () (navigation-header ()) (p (:content (format nil "Welcome ~a" (user-name (session-user body))))) (new-playlist-form ()) (playlist-listing ()) (invite-control ()))))