diff options
Diffstat (limited to 'lisp/webapps/resume/clojurescript')
| -rw-r--r-- | lisp/webapps/resume/clojurescript/resume/src/resume/core.cljs | 174 |
1 files changed, 93 insertions, 81 deletions
diff --git a/lisp/webapps/resume/clojurescript/resume/src/resume/core.cljs b/lisp/webapps/resume/clojurescript/resume/src/resume/core.cljs index b0a2244..33d03c5 100644 --- a/lisp/webapps/resume/clojurescript/resume/src/resume/core.cljs +++ b/lisp/webapps/resume/clojurescript/resume/src/resume/core.cljs @@ -190,7 +190,7 @@ (def resume-state (r/atom {})) (defn reset-location [url] - (reset! location-state url)) + (reset! location-state (first (str/split url "?")))) (defn reset-login-state [jsonobj] (reset! login-state jsonobj)) @@ -271,23 +271,24 @@ separating the throwaway prefix and the remaining useful bit. `selector' will likely be something like: [id^='chk_']" (reduce (fn [x y] - (cond (and x y) (str x "|" y) - (and x (not y)) x - (and (not x) y) y + (cond (and (not (empty? x)) (not (empty? y))) (str x "|" y) + (and (not (empty? x)) (empty? y)) x + (and (empty? x) (not (empty? y))) y :else "")) (map (fn [elem] (let [this (jquery (str "#" (dommy/attr elem :id)))] (when (-> this (.prop "checked")) - (second (str/split (-> this (.prop "id")) "_"))))) + (last (str/split (-> this (.prop "id")) "_"))))) (.toArray (jquery selector))))) (defn form-fields-to-map [selector] - (apply merge (for [x (jquery selector) - :when (not (empty? (.-name x)))] - {(.-name x) (.-value x)}))) + (let [form-name (str/replace (str/replace-first (first (str/split selector " ")) "#" "") "-" "_")] + (apply merge (for [x (jquery selector) + :when (not (empty? (.-name x)))] + {(str/replace (.-name x) (str form-name "-") "") (.-value x)})))) (hiccups/defhtml generic-component-add-modify [jsonobj] - (ck-form/template-generic-form (get jsonobj "form") (namespace ::x))) + [:div {:dangerouslySetInnerHTML (r/unsafe-html (ck-form/template-generic-form (get jsonobj "form") (namespace ::x)))}]) (defn component-results-table [component jsonobj & [reverse-p]] (let [results (get jsonobj "components") @@ -482,8 +483,7 @@ (defn render-login-authenticate [] (POST "/login/authenticate" {:format :raw - :params {:username (dommy/value (dommy/sel1 :#username)) - :pwd (dommy/value (dommy/sel1 :#pwd))} + :params (form-fields-to-map "#login-form :input") :handler handler-login-authenticate})) ;; logout @@ -746,7 +746,7 @@ (defn render-about-us-modify-submit [] (POST (str "/" @about-us-category-state "/modify/submit") {:format :raw - :params {:content (dommy/value (dommy/sel1 :#txt-content))} + :params (form-fields-to-map "#about-us-modify-form :input") :handler handler-about-us-modify-submit})) ;; contact-us @@ -756,20 +756,21 @@ [:h3 {:style {:text-align "center"}} "Reach out to me by filling out the form."] [comp-contact-us-view] [:table {:width "100%"} - [:tr - [:td {:style {:width "100%" - :text-align "center"}} - [:h3 "Located on the edge of the ISU campus!"]]] - [:tr - [:td {:style {:width "100%" - :text-align "center"}} - [:iframe {:src "https://www.google.com/maps/embed?pb=!1m18!1m12!1m3!1d3225.263770603599!2d-112.4266916!3d42.8635091!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x53554f343c440407%3A0xf13bf897ecb4f7e0!2sBogenherr%20Violin%20and%20Viola%20Studio!5e1!3m2!1sen!2sus!4v1783097048097!5m2!1sen!2sus" - :style {:width "600px" - :height "450px" - :border "0px"} - :allowfullscreen "" - :loading "lazy" - :referrerpolicy "strict-origin-when-cross-origin"}]]]]]) + [:tbody + [:tr + [:td {:style {:width "100%" + :text-align "center"}} + [:h3 "Located on the edge of the ISU campus!"]]] + [:tr + [:td {:style {:width "100%" + :text-align "center"}} + [:iframe {:src "https://www.google.com/maps/embed?pb=!1m18!1m12!1m3!1d3225.263770603599!2d-112.4266916!3d42.8635091!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x53554f343c440407%3A0xf13bf897ecb4f7e0!2sBogenherr%20Violin%20and%20Viola%20Studio!5e1!3m2!1sen!2sus!4v1783097048097!5m2!1sen!2sus" + :style {:width "600px" + :height "450px" + :border "0px"} + :allowfullscreen "" + :loading "lazy" + :referrerpolicy "strict-origin-when-cross-origin"}]]]]]]) (defn handler-contact-us [response] (let [jsonobj (js->clj (js/JSON.parse response))] @@ -829,7 +830,7 @@ ;; messages-results (defn on-messages-mode-clicked [read] - (dommy/set-value! (dommy/sel1 :#read) read) + (dommy/set-value! (dommy/sel1 :#messages_select_mode_form-read) read) (render-messages-results)) (defn comp-messages-results [] @@ -847,7 +848,7 @@ (for [key keys] [:th key]) [:th - (str "Mark " (cond (= (dommy/value (dommy/sel1 :#read)) "read") + (str "Mark " (cond (= (dommy/value (dommy/sel1 :#messages_select_mode_form-read)) "read") "unread" :else "read"))]]] @@ -858,15 +859,15 @@ (for [key keys] [:td {:onclick onclick} (get rec key)]) [:td [:img {:src (str "/static/images/" - (cond (= (dommy/value (dommy/sel1 :#read)) "read") + (cond (= (dommy/value (dommy/sel1 :#messages_select_mode_form-read)) "read") "edit-undo.png" :else "edit-redo.png")) - :on-click #(on-messages-mark((cond (= (dommy/value (dommy/sel1 :#read)) "read") + :on-click #(on-messages-mark (cond (= (dommy/value (dommy/sel1 :#messages_select_mode_form-read)) "read") "'unread'" :else "'read'") - (get rec "id")))}]]]))]])])) + (get rec "id"))}]]]))]])])) (defn handler-messages-results [response] (let [jsonobj (js->clj (js/JSON.parse response))] @@ -892,7 +893,7 @@ (defn render-messages-mark [read id] (POST "/messages/mark" {:format :raw - :params (form-fields-to-map "#messages-select-mode-form :input") + :params (merge (form-fields-to-map "#messages-select-mode-form :input") {"id" (str id)}) :handler handler-messages-mark})) ;; users @@ -901,22 +902,42 @@ [:div {:style {:display (cond (or (= @location-state "/users")) "block" :else "none")}} [:h3 {:style {:text-align "center"}} (get @users-state "title")] [comp-users-view] - [:div {:id "modify-users" + [:div {:id "modal-users-add" + :class "modal fade" + :role "dialog" + :tab-index "-1"} + [:div {:class "modal-dialog modal-lg"} + [:div {:class "modal-content"} + [:div {:class "modal-header"} + [:h5 (get @users-state "title")] + [:button {:type "button" + :class "close" + :data-dismiss "modal"} + "×"]] + [:div {:class "modal-body" + :style {:height "460px"}} + [comp-users-add]] + [:div {:class "modal-footer"} + [:button {:type "submit" + :class "btn btn-danger btn-default" + :data-dismiss "modal"} + [:span {:class "glyphicon glyphicon-remove"}] + "Cancel"]]]]] + [:div {:id "modal-users-modify" :class "modal fade" :role "dialog" :tab-index "-1"} [:div {:class "modal-dialog modal-lg"} [:div {:class "modal-content"} [:div {:class "modal-header"} - [:h5 "Users - Modify"] + [:h5 (get @users-state "title")] [:button {:type "button" :class "close" :data-dismiss "modal"} "×"]] [:div {:class "modal-body" :style {:height "460px"}} - ;;[comp-users-modify] - ] + [comp-users-modify]] [:div {:class "modal-footer"} [:button {:type "submit" :class "btn btn-danger btn-default" @@ -991,7 +1012,7 @@ (let [jsonobj (js->clj (js/JSON.parse response))] (auth-notifications jsonobj) (reset-users-add-state jsonobj) - (.modal (jquery "#modify-users")))) + (.modal (jquery "#modal-users-add")))) (defn render-users-add [] (POST "/users/add" {:handler handler-users-add})) @@ -1002,33 +1023,31 @@ (when (-> (jquery "#users-add-form") (.get "0") (.checkValidity)) - (.modal (jquery "#modify-users") "hide") + (.modal (jquery "#modal-users-add") "hide") (render-users-add-submit))) (defn handler-users-add-submit [response] (let [jsonobj (js->clj (js/JSON.parse response))] (auth-notifications jsonobj) - (on-menu-clicked "/users"))) + (render-users-view))) (defn render-users-add-submit [] (POST "/users/add/submit" {:format :raw - :params {:role_groups (reduce-checkboxes "[id^='chk_']") - :first_name (dommy/value (dommy/sel1 :#first_name)) - :last_name (dommy/value (dommy/sel1 :#last_name)) - :email (dommy/value (dommy/sel1 :#email))} + :params (merge (form-fields-to-map "#users-add-form :input") + {:role_groups (reduce-checkboxes "[id^='users_add_form-chk_users_add_']")}) :handler handler-users-add-submit})) ;; users-register -(hiccups/defhtml template-users-register [jsonobj] - [:h3 {:style {:style "text-align: center"}} (get jsonobj "title")] - [:div {:id "content"}]) +(defn comp-users-register [] + [:div {:style {:display (cond (or (= @location-state "/register")) "block" :else "none")}} + [:h3 {:style {:style "text-align: center"}} (get @users-register-state "title")] + [comp-users-register-form]]) (defn handler-users-register [response] (let [jsonobj (js->clj (js/JSON.parse response))] - (dommy/set-html! (dommy/sel1 :#body) (template-users-register jsonobj)) - (render-users-register-form (get jsonobj "hash")))) + (reset-users-register-state jsonobj))) (defn render-users-register [hash] (POST "/users/register" @@ -1038,22 +1057,23 @@ ;; users-register-form -(hiccups/defhtml template-users-register-form [jsonobj] - (cond (get jsonobj "errormsg") - [:a {:href (str "javascript:" (namespace ::x) ".reset_app()")} - "Click here to return to the home page."] - :else - (do - [:p (str "Welcome " (get jsonobj "firstName") " " (get jsonobj "lastName") " to the new user registration page. Please fill out the form below to complete your registration.")] - [:p "Create a new username and password for your login to the website. Phone number is optional."] - [:p (str "Your email address is recorded as " (get jsonobj "email") ". This is where notifications will be sent. If this is not the desired email address, you can change it later by visiting the Edit Profile page.")] - [:p (str "This registration will expire in " (get jsonobj "validFor") ". Please submit this form before that time.")] - (ck-form/template-generic-form (get jsonobj "form") (namespace ::x))))) +(defn comp-users-register-form [] + [:div + (cond (get @users-register-form-state "errormsg") + [:a {:href (str "javascript:" (namespace ::x) ".reset_app()")} + "Click here to return to the home page."] + :else + (do + [:p (str "Welcome " (get @users-register-form-state "firstName") " " (get @users-register-form-state "lastName") " to the new user registration page. Please fill out the form below to complete your registration.")] + [:p "Create a new username and password for your login to the website. Phone number is optional."] + [:p (str "Your email address is recorded as " (get @users-register-form-state "email") ". This is where notifications will be sent. If this is not the desired email address, you can change it later by visiting the Edit Profile page.")] + [:p (str "This registration will expire in " (get @users-register-form-state "validFor") ". Please submit this form before that time.")] + [:div {:dangerouslySetInnerHTML (r/unsafe-html (ck-form/template-generic-form (get @users-register-form-state "form") (namespace ::x)))}]))]) (defn handler-users-register-form [response] (let [jsonobj (js->clj (js/JSON.parse response))] (notifications jsonobj) - (dommy/set-html! (dommy/sel1 :#content) (template-users-register-form jsonobj)))) + (reset-users-register-form-state jsonobj))) (defn render-users-register-form [hash] (POST "/users/register/form" @@ -1069,28 +1089,20 @@ (.checkValidity)) (render-users-register-submit))) -(hiccups/defhtml template-users-register-submit [jsonobj] - [:a {:href (str "javascript:" (namespace ::x) ".reset_app()")} - "Click here to start using the website!"]) +(defn comp-users-register-submit [] + [:div + [:a {:href (str "javascript:" (namespace ::x) ".reset_app()")} + "Click here to start using the website!"]]) (defn handler-users-register-submit [response] (let [jsonobj (js->clj (js/JSON.parse response))] (notifications jsonobj) - (cond (get jsonobj "errormsg") - (do - (dommy/set-value! (dommy/sel1 :#pwd) "") - (dommy/set-value! (dommy/sel1 :#pwd2) "")) - :else - (dommy/set-html! (dommy/sel1 :#content) (template-users-register-submit jsonobj))))) + (reset-users-register-submit-state jsonobj))) (defn render-users-register-submit [] (POST "/users/register/submit" {:format :raw - :params {:hash (dommy/value (dommy/sel1 :#hash)) - :username (dommy/value (dommy/sel1 :#username)) - :pwd (dommy/value (dommy/sel1 :#pwd)) - :pwd2 (dommy/value (dommy/sel1 :#pwd2)) - :phone (dommy/value (dommy/sel1 :#phone))} + :params (form-fields-to-map "#users-register-form :input") :handler handler-users-register-submit})) ;; users-modify @@ -1098,15 +1110,14 @@ (defn on-users-modify-clicked [id] (render-users-modify id)) -(hiccups/defhtml template-users-modify [jsonobj] - (ck-form/template-generic-form (get jsonobj "form") (namespace ::x))) +(defn comp-users-modify [] + [:div {:dangerouslySetInnerHTML (r/unsafe-html (ck-form/template-generic-form (get @users-modify-state "form") (namespace ::x)))}]) (defn handler-users-modify [response] (let [jsonobj (js->clj (js/JSON.parse response))] (auth-notifications jsonobj) - (dommy/set-html! (dommy/sel1 :#modify-title) (get jsonobj "title")) - (dommy/set-html! (dommy/sel1 :#modify-body) (template-users-modify jsonobj)) - (.modal (jquery "#modify-users")))) + (reset-users-modify-state jsonobj) + (.modal (jquery "#modal-users-modify")))) (defn render-users-modify [id] (POST "/users/modify" @@ -1120,7 +1131,7 @@ (when (-> (jquery "#users-modify-form") (.get "0") (.checkValidity)) - (.modal (jquery "#modify-users") "hide") + (.modal (jquery "#modal-users-modify") "hide") (render-users-modify-submit))) (defn handler-users-modify-submit [response] @@ -1131,7 +1142,8 @@ (defn render-users-modify-submit [] (POST "/users/modify/submit" {:format :raw - :params (form-fields-to-map "#users-modify-form :input") + :params (merge (form-fields-to-map "#users-modify-form :input") + {:role_groups (reduce-checkboxes "[id^='users_modify_form-chk_users_modify_']")}) :handler handler-users-modify-submit})) ;; users-toggle-active |
