From be4663059d4395fec8aa1807e202fb466a0ed282 Mon Sep 17 00:00:00 2001 From: ckonstanski Date: Wed, 29 Jul 2026 21:59:34 -0600 Subject: clojurescript macro --- lisp/service/menu-service.lisp | 2 +- .../resume/clojurescript/resume/src/core.cljs | 2042 ------------------- .../clojurescript/resume/src/resume/core.cljs | 2076 ++++++++++++++++++++ .../clojurescript/resume/src/resume/util.clj | 92 + .../clojurescript/resume/src/resume/util.cljs | 2 + lisp/webapps/resume/site.lisp | 14 +- 6 files changed, 2178 insertions(+), 2050 deletions(-) delete mode 100644 lisp/webapps/resume/clojurescript/resume/src/core.cljs create mode 100644 lisp/webapps/resume/clojurescript/resume/src/resume/core.cljs create mode 100644 lisp/webapps/resume/clojurescript/resume/src/resume/util.clj create mode 100644 lisp/webapps/resume/clojurescript/resume/src/resume/util.cljs diff --git a/lisp/service/menu-service.lisp b/lisp/service/menu-service.lisp index 608f23a..e213069 100644 --- a/lisp/service/menu-service.lisp +++ b/lisp/service/menu-service.lisp @@ -4,7 +4,7 @@ (in-package :resume) (defparameter *menu-config* '((:id "a_menu_home" :label "Home" :handler "/home" :permissions "_Public") - (:id "a_menu_resume" :label "Resumes" :handler "/resume" :permissions "resume-view") + (:id "a_menu_resume" :label "Resumes" :handler "/resume/resume" :permissions "resume-view") (:id "a_menu_resume_contactinfo" :label "Contact Info" :handler "/resume/contactinfo" :permissions "resume-view") (:id "a_menu_resume_education" :label "Education" :handler "/resume/education" :permissions "resume-view") (:id "a_menu_resume_language" :label "Language" :handler "/resume/language" :permissions "resume-view") diff --git a/lisp/webapps/resume/clojurescript/resume/src/core.cljs b/lisp/webapps/resume/clojurescript/resume/src/core.cljs deleted file mode 100644 index 0a3e6c2..0000000 --- a/lisp/webapps/resume/clojurescript/resume/src/core.cljs +++ /dev/null @@ -1,2042 +0,0 @@ -(ns resume.core - (:require-macros [hiccups.core :as hiccups :refer [html]]) - (:require [ajax.core :refer [GET POST PUT DELETE raw-response-format]] - [dommy.core :as dommy] - [hiccups.runtime :as hiccupsrt] - [cljsjs.showdown :as showdown] - [clojure.string :as str] - [cljs-time.format :as time-format] - [reagent.core :as r] - [reagent.dom :as rd] - [reagent.dom.client :as rdc] - [org-ckons-cljs.notifications.react :as ck-notifications] - [org-ckons-cljs.form.core :as ck-form])) - -;; declarations - -(declare date-sql-to-pretty) -(declare markdown-to-html) -(declare reduce-checkboxes) -(declare comp-app) -(declare start-render) -(declare start-location) -(declare reset-location) -(declare start) -(declare notifications) -(declare auth-notifications) -(declare comp-menu-main) -(declare comp-menu-user) -(declare handler-menu) -(declare handler-menu-user) -(declare render-menu) -(declare render-home) -(declare template-login) -(declare handler-login) -(declare render-login) -(declare on-login-submit-clicked) -(declare handler-login-authenticate) -(declare render-login-authenticate) -(declare handler-logout) -(declare render-logout) -(declare template-profile) -(declare handler-profile) -(declare render-profile) -(declare template-profile-view) -(declare handler-profile-view) -(declare render-profile-view) -(declare on-profile-modify-clicked) -(declare template-profile-modify) -(declare handler-profile-modify) -(declare render-profile-modify) -(declare on-profile-modify-submit-clicked) -(declare handler-profile-modify-submit) -(declare render-profile-modify-submit) -(declare template-password) -(declare handler-password) -(declare render-password) -(declare on-password-submit-clicked) -(declare handler-password-submit) -(declare render-password-submit) -(declare template-about-us) -(declare handler-about-us) -(declare render-lessons) -(declare template-about-us-view) -(declare handler-about-us-view) -(declare render-about-us-view) -(declare on-about-us-modify-clicked) -(declare template-about-us-modify) -(declare handler-about-us-modify) -(declare render-about-us-modify) -(declare on-about-us-modify-submit-clicked) -(declare handler-about-us-modify-submit) -(declare render-about-us-modify-submit) -(declare template-contact-us) -(declare handler-contact-us) -(declare render-contact-us) -(declare template-contact-us-view) -(declare handler-contact-us-view) -(declare render-contact-us-view) -(declare on-contact-us-email-submit-clicked) -(declare handler-contact-us-email-submit) -(declare render-contact-us-email-submit) -(declare template-messages) -(declare handler-messages) -(declare render-messages) -(declare on-messages-mode-clicked) -(declare template-messages-results) -(declare handler-messages-results) -(declare render-messages-results) -(declare on-messages-mark) -(declare handler-messages-mark) -(declare render-messages-mark) -(declare template-users) -(declare handler-users) -(declare render-users) -(declare template-users-view) -(declare handler-users-view) -(declare render-users-view) -(declare on-users-add-clicked) -(declare template-users-add) -(declare handler-users-add) -(declare render-users-add) -(declare on-users-add-submit-clicked) -(declare handler-users-add-submit) -(declare render-users-add-submit) -(declare template-users-register) -(declare handler-users-register) -(declare render-users-register) -(declare template-users-register-form) -(declare handler-users-register-form) -(declare handler-users-register-form-impl) -(declare render-users-register-form) -(declare on-users-register-submit-clicked) -(declare template-users-register-submit) -(declare handler-users-register-submit) -(declare render-users-register-submit) -(declare on-users-modify-clicked) -(declare template-users-modify) -(declare handler-users-modify) -(declare render-users-modify) -(declare on-users-modify-submit-clicked) -(declare handler-users-modify-submit) -(declare render-users-modify-submit) -(declare on-users-toggle-active-clicked) -(declare handler-users-toggle-active) -(declare render-users-toggle-active) -(declare on-users-delete-clicked) -(declare handler-users-delete) -(declare render-users-delete) -(declare template-resume) -(declare handler-resume) -(declare render-resume) -(declare template-resume-view) -(declare handler-resume-view) -(declare render-resume-view) -(declare on-resume-add-clicked) -(declare template-resume-add) -(declare handler-resume-add) -(declare render-resume-add) -(declare on-resume-add-submit-clicked) -(declare handler-resume-add-submit) -(declare render-resume-add-submit) -(declare on-resume-modify-clicked) -(declare template-resume-modify) -(declare handler-resume-modify) -(declare render-resume-modify) -(declare on-resume-modify-submit-clicked) -(declare handler-resume-modify-submit) -(declare render-resume-modify-submit) -(declare on-resume-delete-clicked) -(declare handler-resume-delete) -(declare render-resume-delete) -(declare template-contactinfo) -(declare handler-contactinfo) -(declare render-contactinfo) -(declare template-contactinfo-view) -(declare handler-contactinfo-view) -(declare render-contactinfo-view) -(declare on-contactinfo-add-clicked) -(declare template-contactinfo-add) -(declare handler-contactinfo-add) -(declare render-contactinfo-add) -(declare on-contactinfo-add-submit-clicked) -(declare handler-contactinfo-add-submit) -(declare render-contactinfo-add-submit) -(declare on-contactinfo-modify-clicked) -(declare template-contactinfo-modify) -(declare handler-contactinfo-modify) -(declare render-contactinfo-modify) -(declare on-contactinfo-modify-submit-clicked) -(declare handler-contactinfo-modify-submit) -(declare render-contactinfo-modify-submit) -(declare on-contactinfo-delete-clicked) -(declare handler-contactinfo-delete) -(declare render-contactinfo-delete) -(declare template-education) -(declare handler-education) -(declare render-education) -(declare template-education-view) -(declare handler-education-view) -(declare render-education-view) -(declare on-education-add-clicked) -(declare template-education-add) -(declare handler-education-add) -(declare render-education-add) -(declare on-education-add-submit-clicked) -(declare handler-education-add-submit) -(declare render-education-add-submit) -(declare on-education-modify-clicked) -(declare template-education-modify) -(declare handler-education-modify) -(declare render-education-modify) -(declare on-education-modify-submit-clicked) -(declare handler-education-modify-submit) -(declare render-education-modify-submit) -(declare on-education-delete-clicked) -(declare handler-education-delete) -(declare render-education-delete) -(declare template-language) -(declare handler-language) -(declare render-language) -(declare template-language-view) -(declare handler-language-view) -(declare render-language-view) -(declare on-language-add-clicked) -(declare template-language-add) -(declare handler-language-add) -(declare render-language-add) -(declare on-language-add-submit-clicked) -(declare handler-language-add-submit) -(declare render-language-add-submit) -(declare on-language-modify-clicked) -(declare template-language-modify) -(declare handler-language-modify) -(declare render-language-modify) -(declare on-language-modify-submit-clicked) -(declare handler-language-modify-submit) -(declare render-language-modify-submit) -(declare on-language-delete-clicked) -(declare handler-language-delete) -(declare render-language-delete) -(declare template-skill) -(declare handler-skill) -(declare render-skill) -(declare template-skill-view) -(declare handler-skill-view) -(declare render-skill-view) -(declare on-skill-add-clicked) -(declare template-skill-add) -(declare handler-skill-add) -(declare render-skill-add) -(declare on-skill-add-submit-clicked) -(declare handler-skill-add-submit) -(declare render-skill-add-submit) -(declare on-skill-modify-clicked) -(declare template-skill-modify) -(declare handler-skill-modify) -(declare render-skill-modify) -(declare on-skill-modify-submit-clicked) -(declare handler-skill-modify-submit) -(declare render-skill-modify-submit) -(declare on-skill-delete-clicked) -(declare handler-skill-delete) -(declare render-skill-delete) -(declare on-menu-clicked) -(declare handler-location) -(declare goto-location) -(declare goto-register) -(declare reset-app) -(declare reset-about-us-category) - -(enable-console-print!) - -(def jquery (js* "$")) -(def sql-formatter (time-format/formatter "yyyy-MM-dd HH:mm:ss")) -(def pretty-formatter (time-format/formatters :rfc822)) -(def location-state (r/atom "/home")) -(def about-us-category-state (r/atom "home")) -(def menu-main-state (r/atom [])) -(def menu-user-state (r/atom [])) -(def menu-user-label (r/atom "Guest User")) - -;; helper functions - -(defn date-sql-to-pretty [sql-date] - (first (str/split (time-format/unparse pretty-formatter (time-format/parse sql-formatter (first (str/split sql-date ".")))) " Z"))) - -(defn markdown-to-html [markdown] - (let [converter (js/showdown.Converter.)] - (.makeHtml converter markdown))) - -(defn reduce-checkboxes [selector] - "Reduces the names of all checked checkboxes to a pipe-separated - list. Assumes that the checkboxes are named via the convention - `chk_something-more'. The important thing is the underscore - 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 - :else "")) - (map (fn [elem] - (let [this (jquery (str "#" (dommy/attr elem :id)))] - (when (-> this (.prop "checked")) - (second (str/split (-> this (.prop "id")) "_"))))) - (.toArray (jquery selector))))) - -;; body - -(defn comp-app [] - [:div {:class "container-fluid"} - [:div {:class "banner"} - [:table {:width "100%" :height "100%"} - [:tbody - [:tr - [:td {:class "banner-menu"} - [comp-menu-user]] - [:td {:class "banner-title"} "Resume Builder"] - [:td {:class "banner-menu"} " "]]]]] - [comp-menu-main] - [ck-notifications/comp-errormsg] - [ck-notifications/comp-message] - [:div {:id "body"}] - [:div {:id "footer"} - [:hr] - "Carlos Konstanski (970) 294-9708" - [:br] - [:a {:href "https://github.com/ckonstanski/resume/tree/master" - :target "_blank"} - "Source code on GitHub"]]]) - -;; start the react app - -(defn start-render [] - (let [app-root (rdc/create-root (js/document.getElementById "app"))] - (rdc/render app-root [comp-app]))) - -(defn start-location [] - (cond (str/starts-with? @location-state "/register/") - (goto-register (str/replace-first @location-state "/register/" "")) - :else - (goto-location @location-state))) - -(defn reset-location [url] - (reset! location-state url)) - -(defn reset-about-us-category [category] - (reset! about-us-category-state category)) - -(defn ^:dev/after-load start - ([] - (start-render) - (start-location)) - ([url] - (reset-location url) - (start-render) - (start-location))) - -;; notifications - -(defn notifications [jsonobj] - (ck-notifications/reset-message (get jsonobj "message")) - (ck-notifications/reset-errormsg (get jsonobj "errormsg"))) - -(defn auth-notifications [jsonobj] - (cond (empty? (get jsonobj "errormsg")) - (notifications jsonobj) - :else - (do - (render-home "" (get jsonobj "errormsg")) - (render-menu)))) - -;; menu - -(defn comp-menu-main [] - [:div {:class "well"} - [:ul {:class "nav nav-pills"} - (for [menuitem (doall @menu-main-state)] - [:li {:key (str "li_" (get menuitem "id")) - :class "nav-item"} - [:a {:class (cond (= (str/upper-case (get menuitem "handler")) - (str/upper-case @location-state)) - "nav-link active" - :else - "nav-link") - :key (get menuitem "id") - :on-click #(on-menu-clicked (get menuitem "handler"))} - (get menuitem "label")]])]]) - -(defn comp-menu-user [] - [:div {:class "dropdown"} - [:button {:class "btn btn-primary dropdown-toggle" - :type "button" - :id "button-menu-user" - :data-toggle "dropdown" - :aria-haspopup "true" - :aria-expanded "false"} - @menu-user-label] - [:div {:class "dropdown-menu" :aria-labelledby "button-menu-user"} - (for [menuitem (doall @menu-user-state)] - [:a {:key (get menuitem "id") - :class "dropdown-item" - :on-click #(on-menu-clicked (get menuitem "handler"))} - (get menuitem "label")])]]) - -(defn handler-menu [response] - (let [jsonobj (js->clj (js/JSON.parse response))] - (reset! menu-main-state (get jsonobj "menuitems")))) - -(defn handler-menu-user [response] - (let [jsonobj (js->clj (js/JSON.parse response))] - (reset! menu-user-state (get jsonobj "menuitems")) - (reset! menu-user-label (get jsonobj "label")))) - -(defn render-menu [] - (GET "/menu" {:handler handler-menu}) - (GET "/menu/user" {:handler handler-menu-user})) - -;; login - -(hiccups/defhtml template-login [jsonobj] - [:h3 {:style "text-align: center"} (get jsonobj "title")] - (ck-form/template-generic-form (get jsonobj "form") (namespace ::x)) - [:div {:style "text-align: center"} - [:a {:href ""} "Forgot password?"]]) - -(defn handler-login [response] - (let [jsonobj (js->clj (js/JSON.parse response))] - (notifications jsonobj) - (dommy/set-html! (dommy/sel1 :#body) (template-login jsonobj)))) - -(defn render-login [] - (GET "/login" {:handler handler-login})) - -;; login-authenticate - -(defn on-login-submit-clicked [] - (when (-> (jquery "#login-form") - (.get "0") - (.checkValidity)) - (render-login-authenticate))) - -(defn handler-login-authenticate [response] - (let [jsonobj (js->clj (js/JSON.parse response))] - (cond (get jsonobj "errormsg") - (goto-location "/login") - (get jsonobj "message") - (do - (reset-location "/home") - (render-home) - (render-menu))))) - -(defn render-login-authenticate [] - (POST "/login/authenticate" - {:format :raw - :params {:username (dommy/value (dommy/sel1 :#username)) - :pwd (dommy/value (dommy/sel1 :#pwd))} - :handler handler-login-authenticate})) - -;; logout - -(defn handler-logout [response] - (let [jsonobj (js->clj (js/JSON.parse response))] - (render-home "You are now logged out" "") - (reset-location "/home") - (render-menu))) - -(defn render-logout [] - (GET "/logout" {:handler handler-logout})) - -;; profile - -(hiccups/defhtml template-profile [jsonobj] - [:h3 {:style "text-align: center"} (get jsonobj "title")] - [:div {:id "content"}] - [:div {:id "modify" - :class "modal fade" - :role "dialog" - :tabindex "-1"} - [:div {:class "modal-dialog modal-lg"} - [:div {:class "modal-content"} - [:div {:class "modal-header"} - [:h5 {:class "modal-title"} "Profile - Modify"] - [:button {:type "button" - :class "close" - :data-dismiss "modal"} - "×"]] - [:div {:id "modify-body" - :class "modal-body" - :style "height: 460px;"}] - [:div {:class "modal-footer"} - [:button {:type "submit" - :class "btn btn-danger btn-default" - :data-dismiss "modal"} - [:span {:class "glyphicon glyphicon-remove"}] - "Cancel"]]]]]) - -(defn handler-profile [response] - (let [jsonobj (js->clj (js/JSON.parse response))] - (notifications jsonobj) - (dommy/set-html! (dommy/sel1 :#body) (template-profile jsonobj)) - (render-profile-view))) - -(defn render-profile [] - (GET "/profile" {:handler handler-profile})) - -;; profile-view - -(hiccups/defhtml template-profile-view [jsonobj] - [:div {:style "text-align: right"} - [:img {:src "/static/images/edit.png" - :style "cursor:pointer; cursor:hand" - :onclick (str (namespace ::x) ".on_profile_modify_clicked()")}]] - [:div {:class "container"} - [:div {:class "row"} - [:div {:class "col" :style "text-align: right"} "Username:"] - [:div {:class "col-10"} (get jsonobj "username")]] - [:div {:class "row"} - [:div {:class "col" :style "text-align: right"} "First Name:"] - [:div {:class "col-10"} (get jsonobj "first_name")]] - [:div {:class "row"} - [:div {:class "col" :style "text-align: right"} "Last Name:"] - [:div {:class "col-10"} (get jsonobj "last_name")]] - [:div {:class "row"} - [:div {:class "col" :style "text-align: right"} "Email:"] - [:div {:class "col-10"} (get jsonobj "email")]] - [:div {:class "row"} - [:div {:class "col" :style "text-align: right"} "Phone:"] - [:div {:class "col-10"} (get jsonobj "phone")]]]) - -(defn handler-profile-view [response] - (let [jsonobj (js->clj (js/JSON.parse response))] - (dommy/set-html! (dommy/sel1 :#content) (template-profile-view jsonobj)))) - -(defn render-profile-view [] - (GET "/profile/view" {:handler handler-profile-view})) - -;; profile-modify - -(defn on-profile-modify-clicked [] - (render-profile-modify)) - -(hiccups/defhtml template-profile-modify [jsonobj] - (ck-form/template-generic-form (get jsonobj "form") (namespace ::x))) - -(defn handler-profile-modify [response] - (let [jsonobj (js->clj (js/JSON.parse response))] - (auth-notifications jsonobj) - (dommy/set-html! (dommy/sel1 :#modify-body) (template-profile-modify jsonobj)) - (.modal (jquery "#modify")))) - -(defn render-profile-modify [] - (POST "/profile/modify" {:handler handler-profile-modify})) - -;; profile-modify-submit - -(defn on-profile-modify-submit-clicked [] - (when (-> (jquery "#profile-modify-form") - (.get "0") - (.checkValidity)) - (.modal (jquery "#modify") "hide") - (render-profile-modify-submit))) - -(defn handler-profile-modify-submit [response] - (let [jsonobj (js->clj (js/JSON.parse response))] - (auth-notifications jsonobj) - (on-menu-clicked "/profile"))) - -(defn render-profile-modify-submit [] - (POST "/profile/modify/submit" - {:format :raw - :params {:id (dommy/value (dommy/sel1 :#id)) - :username (dommy/value (dommy/sel1 :#username)) - :first_name (dommy/value (dommy/sel1 :#first_name)) - :last_name (dommy/value (dommy/sel1 :#last_name)) - :email (dommy/value (dommy/sel1 :#email)) - :phone (dommy/value (dommy/sel1 :#phone))} - :handler handler-profile-modify-submit})) - -;; password - -(hiccups/defhtml template-password [jsonobj] - [:h3 {:style "text-align: center"} (get jsonobj "title")] - (ck-form/template-generic-form (get jsonobj "form") (namespace ::x))) - -(defn handler-password [response] - (let [jsonobj (js->clj (js/JSON.parse response))] - (notifications jsonobj) - (dommy/set-html! (dommy/sel1 :#body) (template-password jsonobj)))) - -(defn render-password [] - (GET "/password" {:handler handler-password})) - -;; password-submit - -(defn on-password-submit-clicked [] - (when (-> (jquery "#password-form") - (.get "0") - (.checkValidity)) - (render-password-submit))) - -(defn handler-password-submit [response] - (let [jsonobj (js->clj (js/JSON.parse response))] - (auth-notifications jsonobj) - (on-menu-clicked "/password"))) - -(defn render-password-submit [] - (POST "/password/submit" - {:format :raw - :params {:id (dommy/value (dommy/sel1 :#id)) - :pwd (dommy/value (dommy/sel1 :#pwd)) - :pwd2 (dommy/value (dommy/sel1 :#pwd2))} - :handler handler-password-submit})) - -;; about-us (home) - -(hiccups/defhtml template-about-us [jsonobj] - [:h1 {:style "text-align: center"} - (cond (= @about-us-category-state "home") "Home")] - [:div {:id "content"}] - [:div {:id "modify" - :class "modal fade" - :role "dialog" - :tabindex "-1"} - [:div {:class "modal-dialog modal-lg"} - [:div {:class "modal-content"} - [:div {:class "modal-header"} - [:h5 [:span {:id "modify-title"}]] - [:button {:type "button" - :class "close" - :data-dismiss "modal"} - "×"]] - [:div {:id "modify-body" - :class "modal-body" - :style "height: 460px;"}] - [:div {:class "modal-footer"} - [:button {:type "submit" - :class "btn btn-danger btn-default" - :data-dismiss "modal"} - [:span {:class "glyphicon glyphicon-remove"}] - "Cancel"]]]]]) - -(defn handler-about-us [response] - (let [jsonobj (js->clj (js/JSON.parse response))] - (reset-about-us-category (get jsonobj "category")) - (notifications jsonobj) - (dommy/set-html! (dommy/sel1 :#body) (template-about-us jsonobj)) - (render-about-us-view))) - -(defn render-home - ([] - (GET "/home" {:handler handler-about-us})) - ([message errormsg] - (POST "/home" - {:format :raw - :params {:message message - :errormsg errormsg} - :handler handler-about-us}))) - -;; about-us-view - -(hiccups/defhtml template-about-us-view [jsonobj] - (when (get jsonobj "adminP") - [:div {:style "text-align: right;"} - [:img {:src "/static/images/edit.png" - :style "cursor:pointer; cursor:hand" - :onclick (str (namespace ::x) ".on_about_us_modify_clicked()")}]]) - [:div {:id "markdown"}]) - -(defn handler-about-us-view [response] - (let [jsonobj (js->clj (js/JSON.parse response))] - (dommy/set-html! (dommy/sel1 :#content) (template-about-us-view jsonobj)) - (dommy/set-html! (dommy/sel1 :#markdown) (markdown-to-html (get jsonobj "content"))))) - -(defn render-about-us-view [] - (GET (str "/" @about-us-category-state "/view") - {:handler handler-about-us-view})) - -;; about-us-modify - -(defn on-about-us-modify-clicked [] - (render-about-us-modify)) - -(hiccups/defhtml template-about-us-modify [jsonobj] - (ck-form/template-generic-form (get jsonobj "form") (namespace ::x))) - -(defn handler-about-us-modify [response] - (let [jsonobj (js->clj (js/JSON.parse response))] - (auth-notifications jsonobj) - (dommy/set-html! (dommy/sel1 :#modify-title) - (str (cond (= @about-us-category-state "home") "Home") - " - Modify")) - (dommy/set-html! (dommy/sel1 :#modify-body) (template-about-us-modify jsonobj)) - (.modal (jquery "#modify")))) - -(defn render-about-us-modify [] - (POST (str "/" @about-us-category-state "/modify") - {:handler handler-about-us-modify})) - -;; about-us-modify-submit - -(defn on-about-us-modify-submit-clicked [] - (when (-> (jquery "#about-us-modify-form") - (.get "0") - (.checkValidity)) - (.modal (jquery "#modify") "hide") - (render-about-us-modify-submit))) - -(defn handler-about-us-modify-submit [response] - (let [jsonobj (js->clj (js/JSON.parse response))] - (auth-notifications jsonobj) - (dommy/set-html! (dommy/sel1 :#content) (template-about-us-view jsonobj)) - (dommy/set-html! (dommy/sel1 :#markdown) (markdown-to-html (get jsonobj "content"))))) - -(defn render-about-us-modify-submit [] - (POST (str "/" @about-us-category-state "/modify/submit") - {:format :raw - :params {:content (dommy/value (dommy/sel1 :#txt-content))} - :handler handler-about-us-modify-submit})) - -;; contact-us - -(hiccups/defhtml template-contact-us [jsonobj] - [:h1 {:style "text-align: center"} "Reach out to me by filling out the form."] - [:div {:id "content"}] - [: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"}]]]]) - -(defn handler-contact-us [response] - (let [jsonobj (js->clj (js/JSON.parse response))] - (notifications jsonobj) - (dommy/set-html! (dommy/sel1 :#body) (template-contact-us jsonobj)) - (render-contact-us-view))) - -(defn render-contact-us [] - (GET "/contact-us" {:handler handler-contact-us})) - -;; contact-us-view - -(hiccups/defhtml template-contact-us-view [jsonobj] - (ck-form/template-generic-form (get jsonobj "form") (namespace ::x))) - -(defn handler-contact-us-view [response] - (let [jsonobj (js->clj (js/JSON.parse response))] - (notifications jsonobj) - (dommy/set-html! (dommy/sel1 :#content) (template-contact-us-view jsonobj)))) - -(defn render-contact-us-view [] - (GET "/contact-us/view" {:handler handler-contact-us-view})) - -;; contact-us-submit - -(defn on-contact-us-email-submit-clicked [] - (when (-> (jquery "#contact-us-form") - (.get "0") - (.checkValidity)) - (render-contact-us-email-submit))) - -(defn handler-contact-us-email-submit [response] - (on-menu-clicked "/contact-us")) - -(defn render-contact-us-email-submit [] - (POST "/contact-us/email" - {:format :raw - :params {:first_name (dommy/value (dommy/sel1 :#first_name)) - :last_name (dommy/value (dommy/sel1 :#last_name)) - :email (dommy/value (dommy/sel1 :#email)) - :phone (dommy/value (dommy/sel1 :#phone)) - :comments (dommy/value (dommy/sel1 :#comments))} - :handler handler-contact-us-email-submit})) - -;; messages - -(hiccups/defhtml template-messages [jsonobj] - [:h3 {:style "text-align: center"} (get jsonobj "title")] - (ck-form/template-generic-form (get jsonobj "form") (namespace ::x)) - [:div {:id "results"}]) - -(defn handler-messages [response] - (let [jsonobj (js->clj (js/JSON.parse response))] - (notifications jsonobj) - (dommy/set-html! (dommy/sel1 :#body) (template-messages jsonobj)) - (when (not (empty? (dommy/value (dommy/sel1 :#read)))) - (render-messages-results)))) - -(defn render-messages [] - (GET "/messages" {:handler handler-messages})) - -;; messages-results - -(defn on-messages-mode-clicked [read] - (dommy/set-value! (dommy/sel1 :#read) read) - (render-messages-results)) - -(hiccups/defhtml template-messages-results [jsonobj] - (let [results (get jsonobj "results") - keys (remove (fn [x] - (not (get (first results) x))) - (keys (first results)))] - (cond (empty? results) - [:h5 {:style "text-align: center"} "No results found."] - :else - [:table {:class "table table-hover"} - [:thead - [:tr - (for [key keys] - [:th key]) - [:th - (str "Mark " (cond (= (dommy/value (dommy/sel1 :#read)) "read") - "unread" - :else - "read"))]]] - [:tbody - (for [rec results] - (let [onclick "void()"] - [:tr - (for [key keys] - [:td {:onclick onclick} (get rec key)]) - [:td [:img {:src (str "/static/images/" - (cond (= (dommy/value (dommy/sel1 :#read)) "read") - "edit-undo.png" - :else - "edit-redo.png")) - :style "cursor: pointer; cursor: hand" - :onclick (str (namespace ::x) - ".on_messages_mark(" - (cond (= (dommy/value (dommy/sel1 :#read)) "read") - "'unread'" - :else - "'read'") - "," (get rec "id") ")")}]]]))]]))) - -(defn handler-messages-results [response] - (let [jsonobj (js->clj (js/JSON.parse response))] - (auth-notifications jsonobj) - (dommy/set-html! (dommy/sel1 :#results) (template-messages-results jsonobj)))) - -(defn render-messages-results [] - (POST "/messages/results" - {:format :raw - :params {:read (dommy/value (dommy/sel1 :#read))} - :handler handler-messages-results})) - -;; messages-mark - -(defn on-messages-mark [read id] - (render-messages-mark read id)) - -(defn handler-messages-mark [response] - (let [jsonobj (js->clj (js/JSON.parse response))] - (auth-notifications jsonobj) - (on-menu-clicked "/messages"))) - -(defn render-messages-mark [read id] - (POST "/messages/mark" - {:format :raw - :params {:read read - :id id} - :handler handler-messages-mark})) - -;; users - -(hiccups/defhtml template-users [jsonobj] - [:h3 {:style "text-align: center"} (get jsonobj "title")] - [:div {:id "content"}] - [:div {:id "modify" - :class "modal fade" - :role "dialog" - :tabindex "-1"} - [:div {:class "modal-dialog modal-lg"} - [:div {:class "modal-content"} - [:div {:class "modal-header"} - [:h5 [:span {:id "modify-title"}]] - [:button {:type "button" - :class "close" - :data-dismiss "modal"} - "×"]] - [:div {:id "modify-body" - :class "modal-body" - :style "height: 450px;"}] - [:div {:class "modal-footer"} - [:button {:type "submit" - :class "btn btn-danger btn-default" - :data-dismiss "modal"} - [:span {:class "glyphicon glyphicon-remove"}] - "Cancel"]]]]]) - -(defn handler-users [response] - (let [jsonobj (js->clj (js/JSON.parse response))] - (notifications jsonobj) - (dommy/set-html! (dommy/sel1 :#body) (template-users jsonobj)) - (render-users-view))) - -(defn render-users [] - (GET "/users" {:handler handler-users})) - -;; users-view - -(hiccups/defhtml template-users-view [jsonobj] - [:div {:style "text-align: right"} - [:img {:src "/static/images/add.png" - :style "cursor:pointer; cursor:hand" - :onclick (str (namespace ::x) ".on_users_add_clicked()")}]] - [:table {:class "table table-striped table-hover table-sm"} - [:thead - [:tr - [:th {:scope "col"} "Active?"] - [:th {:scope "col"} "Last Name"] - [:th {:scope "col"} "First Name"] - [:th {:scope "col"} "Username"] - [:th {:scope "col"} "Email"] - [:th {:scope "col"} "Phone"] - [:th {:scope "col"} "Del"]]] - [:tbody - (for [user (get jsonobj "users")] - (let [onclick (str (namespace ::x) ".on_users_modify_clicked(" (get user "id") ")") - toggle-active (str (namespace ::x) ".on_users_toggle_active_clicked(" (get user "id") ")")] - [:tr - [:td [:img {:src (cond (get user "active") - "/static/images/yes.png" - :else - "/static/images/no.png") - :onclick toggle-active}]] - [:td {:onclick onclick} (get user "last_name")] - [:td {:onclick onclick} (get user "first_name")] - [:td {:onclick onclick} (get user "username")] - [:td {:onclick onclick} (get user "email")] - [:td {:onclick onclick} (get user "phone")] - [:td [:img {:src "/static/images/delete.png" - :onclick (str (namespace ::x) ".on_users_delete_clicked(" (get user "id") ", '" (get user "first_name") "', '" (get user "last_name") "')")}]]]))]]) - -(defn handler-users-view [response] - (let [jsonobj (js->clj (js/JSON.parse response))] - (dommy/set-html! (dommy/sel1 :#content) (template-users-view jsonobj)))) - -(defn render-users-view [] - (GET "/users/view" {:handler handler-users-view})) - -;; users-add - -(defn on-users-add-clicked [] - (render-users-add)) - -(hiccups/defhtml template-users-add [jsonobj] - (ck-form/template-generic-form (get jsonobj "form") (namespace ::x))) - -(defn handler-users-add [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-add jsonobj)) - (.modal (jquery "#modify")))) - -(defn render-users-add [] - (POST "/users/add" {:handler handler-users-add})) - -;; users-add-submit - -(defn on-users-add-submit-clicked [] - (when (-> (jquery "#users-add-form") - (.get "0") - (.checkValidity)) - (.modal (jquery "#modify") "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"))) - -(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))} - :handler handler-users-add-submit})) - -;; users-register - -(hiccups/defhtml template-users-register [jsonobj] - [:h3 {:style "text-align: center"} (get jsonobj "title")] - [:div {:id "content"}]) - -(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")))) - -(defn render-users-register [hash] - (POST "/users/register" - {:format :raw - :params {:hash hash} - :handler handler-users-register})) - -;; 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 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)))) - -(defn render-users-register-form [hash] - (POST "/users/register/form" - {:format :raw - :params {:hash hash} - :handler handler-users-register-form})) - -;; users-register-submit - -(defn on-users-register-submit-clicked [] - (when (-> (jquery "#users-register-form") - (.get "0") - (.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 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))))) - -(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))} - :handler handler-users-register-submit})) - -;; users-modify - -(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 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")))) - -(defn render-users-modify [id] - (POST "/users/modify" - {:format :raw - :params {:id id} - :handler handler-users-modify})) - -;; users-modify-submit - -(defn on-users-modify-submit-clicked [] - (when (-> (jquery "#users-modify-form") - (.get "0") - (.checkValidity)) - (.modal (jquery "#modify") "hide") - (render-users-modify-submit))) - -(defn handler-users-modify-submit [response] - (let [jsonobj (js->clj (js/JSON.parse response))] - (auth-notifications jsonobj) - (on-menu-clicked "/users"))) - -(defn render-users-modify-submit [] - (POST "/users/modify/submit" - {:format :raw - :params {:id (dommy/value (dommy/sel1 :#id)) - :role_groups (reduce-checkboxes "[id^='chk_']") - :username (dommy/value (dommy/sel1 :#username)) - :first_name (dommy/value (dommy/sel1 :#first_name)) - :last_name (dommy/value (dommy/sel1 :#last_name)) - :email (dommy/value (dommy/sel1 :#email)) - :phone (dommy/value (dommy/sel1 :#phone))} - :handler handler-users-modify-submit})) - -;; users-toggle-active - -(defn on-users-toggle-active-clicked [id] - (render-users-toggle-active id)) - -(defn handler-users-toggle-active [response] - (let [jsonobj (js->clj (js/JSON.parse response))] - (auth-notifications jsonobj) - (on-menu-clicked "/users"))) - -(defn render-users-toggle-active [id] - (POST "/users/toggle-active" - {:format :raw - :params {:id id} - :handler handler-users-toggle-active})) - -;; users-delete - -(defn on-users-delete-clicked [id first-name last-name] - (when (js/confirm (str "Are you sure you want to delete " first-name " " last-name "? This action cannot be undone.")) - (render-users-delete id))) - -(defn handler-users-delete [response] - (let [jsonobj (js->clj (js/JSON.parse response))] - (auth-notifications jsonobj) - (on-menu-clicked "/users"))) - -(defn render-users-delete [id] - (DELETE (str "/users/delete/" id) - {:format :raw - :handler handler-users-delete})) - -;; resume - -(hiccups/defhtml template-resume [jsonobj] - [:h3 {:style "text-align: center"} (get jsonobj "title")] - [:div {:id "content"}] - [:div {:id "modify" - :class "modal fade" - :role "dialog" - :tabindex "-1"} - [:div {:class "modal-dialog modal-lg"} - [:div {:class "modal-content"} - [:div {:class "modal-header"} - [:h5 [:span {:id "modify-title"}]] - [:button {:type "button" - :class "close" - :data-dismiss "modal"} - "×"]] - [:div {:id "modify-body" - :class "modal-body" - :style "height: 450px;"}] - [:div {:class "modal-footer"} - [:button {:type "submit" - :class "btn btn-danger btn-default" - :data-dismiss "modal"} - [:span {:class "glyphicon glyphicon-remove"}] - "Cancel"]]]]]) - -(defn handler-resume [response] - (let [jsonobj (js->clj (js/JSON.parse response))] - (notifications jsonobj) - (dommy/set-html! (dommy/sel1 :#body) (template-resume jsonobj)) - (render-resume-view))) - -(defn render-resume [] - (GET "/resume" {:handler handler-resume})) - -;; resume-view - -(hiccups/defhtml template-resume-view [jsonobj] - [:div {:style "text-align: right"} - [:img {:src "/static/images/add.png" - :style "cursor:pointer; cursor:hand" - :onclick (str (namespace ::x) ".on_resume_add_clicked()")}]] - [:table {:class "table table-striped table-hover table-sm"} - [:thead - [:tr - [:th {:scope "col"} "Name"] - [:th {:scope "col"} "Mod"] - [:th {:scope "col"} "Del"]]] - [:tbody - (for [resume (get jsonobj "resumes")] - [:tr - [:td (get resume "name")] - [:td {:width "30"} - [:img {:src "/static/images/modify.png" - :onclick (str (namespace ::x) ".on_resume_modify_clicked(" (get resume "id") ")")}]] - [:td {:width "30"} - [:img {:src "/static/images/delete.png" - :onclick (str (namespace ::x) ".on_resume_delete_clicked(" (get resume "id") ", '" (get resume "name") "')")}]]])]]) - -(defn handler-resume-view [response] - (let [jsonobj (js->clj (js/JSON.parse response))] - (dommy/set-html! (dommy/sel1 :#content) (template-resume-view jsonobj)))) - -(defn render-resume-view [] - (GET "/resume/view" {:handler handler-resume-view})) - -;; resume-add - -(defn on-resume-add-clicked [] - (render-resume-add)) - -(hiccups/defhtml template-resume-add [jsonobj] - (ck-form/template-generic-form (get jsonobj "form") (namespace ::x))) - -(defn handler-resume-add [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-resume-add jsonobj)) - (.modal (jquery "#modify")))) - -(defn render-resume-add [] - (POST "/resume/add" {:handler handler-resume-add})) - -;; resume-add-submit - -(defn on-resume-add-submit-clicked [] - (when (-> (jquery "#resume-add-form") - (.get "0") - (.checkValidity)) - (.modal (jquery "#modify") "hide") - (render-resume-add-submit))) - -(defn handler-resume-add-submit [response] - (let [jsonobj (js->clj (js/JSON.parse response))] - (auth-notifications jsonobj) - (on-menu-clicked "/resume"))) - -(defn render-resume-add-submit [] - (POST "/resume/add/submit" - {:format :raw - :params {:name (dommy/value (dommy/sel1 :#name))} - :handler handler-resume-add-submit})) - -;; resume-modify - -(defn on-resume-modify-clicked [id] - (render-resume-modify id)) - -(hiccups/defhtml template-resume-modify [jsonobj] - (ck-form/template-generic-form (get jsonobj "form") (namespace ::x))) - -(defn handler-resume-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-resume-modify jsonobj)) - (.modal (jquery "#modify")))) - -(defn render-resume-modify [id] - (POST "/resume/modify" - {:format :raw - :params {:id id} - :handler handler-resume-modify})) - -;; resume-modify-submit - -(defn on-resume-modify-submit-clicked [] - (when (-> (jquery "#resume-modify-form") - (.get "0") - (.checkValidity)) - (.modal (jquery "#modify") "hide") - (render-resume-modify-submit))) - -(defn handler-resume-modify-submit [response] - (let [jsonobj (js->clj (js/JSON.parse response))] - (auth-notifications jsonobj) - (on-menu-clicked "/resume"))) - -(defn render-resume-modify-submit [] - (POST "/resume/modify/submit" - {:format :raw - :params {:id (dommy/value (dommy/sel1 :#id)) - :name (dommy/value (dommy/sel1 :#name))} - :handler handler-resume-modify-submit})) - -;; resume-delete - -(defn on-resume-delete-clicked [id name] - (when (js/confirm (str "Are you sure you want to delete " name "? This action cannot be undone.")) - (render-resume-delete id))) - -(defn handler-resume-delete [response] - (let [jsonobj (js->clj (js/JSON.parse response))] - (auth-notifications jsonobj) - (on-menu-clicked "/resume"))) - -(defn render-resume-delete [id] - (DELETE (str "/resume/delete/" id) - {:format :raw - :handler handler-resume-delete})) - -;; contactinfo - -(hiccups/defhtml template-contactinfo [jsonobj] - [:h3 {:style "text-align: center"} (get jsonobj "title")] - [:div {:id "content"}] - [:div {:id "modify" - :class "modal fade" - :role "dialog" - :tabindex "-1"} - [:div {:class "modal-dialog modal-lg"} - [:div {:class "modal-content"} - [:div {:class "modal-header"} - [:h5 [:span {:id "modify-title"}]] - [:button {:type "button" - :class "close" - :data-dismiss "modal"} - "×"]] - [:div {:id "modify-body" - :class "modal-body" - :style "height: 450px;"}] - [:div {:class "modal-footer"} - [:button {:type "submit" - :class "btn btn-danger btn-default" - :data-dismiss "modal"} - [:span {:class "glyphicon glyphicon-remove"}] - "Cancel"]]]]]) - -(defn handler-contactinfo [response] - (let [jsonobj (js->clj (js/JSON.parse response))] - (notifications jsonobj) - (dommy/set-html! (dommy/sel1 :#body) (template-contactinfo jsonobj)) - (render-contactinfo-view))) - -(defn render-contactinfo [] - (GET "/resume/contactinfo" {:handler handler-contactinfo})) - -;; contactinfo-view - -(hiccups/defhtml template-contactinfo-view [jsonobj] - [:div {:style "text-align: right"} - [:img {:src "/static/images/add.png" - :style "cursor:pointer; cursor:hand" - :onclick (str (namespace ::x) ".on_contactinfo_add_clicked()")}]] - [:table {:class "table table-striped table-hover table-sm"} - [:thead - [:tr - [:th {:scope "col"} "Address"] - [:th {:scope "col"} "City"] - [:th {:scope "col"} "State"] - [:th {:scope "col"} "Phone"] - [:th {:scope "col"} "Email"] - [:th {:scope "col"} "URL"] - [:th {:scope "col"} "VISA Status"] - [:th {:scope "col"} "Mod"] - [:th {:scope "col"} "Del"]]] - [:tbody - (for [contactinfo (get jsonobj "components")] - [:tr - [:td (get contactinfo "address")] - [:td (get contactinfo "city")] - [:td (get contactinfo "state_abbr")] - [:td (get contactinfo "phone")] - [:td (get contactinfo "email")] - [:td (get contactinfo "url")] - [:td (get contactinfo "visastatus")] - [:td {:width "30"} - [:img {:src "/static/images/modify.png" - :onclick (str (namespace ::x) ".on_contactinfo_modify_clicked(" (get contactinfo "id") ")")}]] - [:td {:width "30"} - [:img {:src "/static/images/delete.png" - :onclick (str (namespace ::x) ".on_contactinfo_delete_clicked(" (get contactinfo "id") ", '" (str (get contactinfo "address") ", " (get contactinfo "city") " " (get contactinfo "state_abbr")) "')")}]]])]]) - -(defn handler-contactinfo-view [response] - (let [jsonobj (js->clj (js/JSON.parse response))] - (dommy/set-html! (dommy/sel1 :#content) (template-contactinfo-view jsonobj)))) - -(defn render-contactinfo-view [] - (GET "/resume/contactinfo/view" {:handler handler-contactinfo-view})) - -;; contactinfo-add - -(defn on-contactinfo-add-clicked [] - (render-contactinfo-add)) - -(hiccups/defhtml template-contactinfo-add [jsonobj] - (ck-form/template-generic-form (get jsonobj "form") (namespace ::x))) - -(defn handler-contactinfo-add [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-contactinfo-add jsonobj)) - (.modal (jquery "#modify")))) - -(defn render-contactinfo-add [] - (POST "/resume/contactinfo/add" {:handler handler-contactinfo-add})) - -;; contactinfo-add-submit - -(defn on-contactinfo-add-submit-clicked [] - (when (-> (jquery "#contactinfo-add-form") - (.get "0") - (.checkValidity)) - (.modal (jquery "#modify") "hide") - (render-contactinfo-add-submit))) - -(defn handler-contactinfo-add-submit [response] - (let [jsonobj (js->clj (js/JSON.parse response))] - (auth-notifications jsonobj) - (on-menu-clicked "/resume/contactinfo"))) - -(defn render-contactinfo-add-submit [] - (POST "/resume/contactinfo/add/submit" - {:format :raw - :params {:address (dommy/value (dommy/sel1 :#address)) - :city (dommy/value (dommy/sel1 :#city)) - :state_id (dommy/value (dommy/sel1 :#state_id)) - :phone (dommy/value (dommy/sel1 :#phone)) - :email (dommy/value (dommy/sel1 :#email)) - :url (dommy/value (dommy/sel1 :#url)) - :visastatus_id (dommy/value (dommy/sel1 :#visastatus_id))} - :handler handler-contactinfo-add-submit})) - -;; contactinfo-modify - -(defn on-contactinfo-modify-clicked [id] - (render-contactinfo-modify id)) - -(hiccups/defhtml template-contactinfo-modify [jsonobj] - (ck-form/template-generic-form (get jsonobj "form") (namespace ::x))) - -(defn handler-contactinfo-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-contactinfo-modify jsonobj)) - (.modal (jquery "#modify")))) - -(defn render-contactinfo-modify [id] - (POST "/resume/contactinfo/modify" - {:format :raw - :params {:id id} - :handler handler-contactinfo-modify})) - -;; contactinfo-modify-submit - -(defn on-contactinfo-modify-submit-clicked [id] - (when (-> (jquery "#contactinfo-modify-form") - (.get "0") - (.checkValidity)) - (.modal (jquery "#modify") "hide") - (render-contactinfo-modify-submit id))) - -(defn handler-contactinfo-modify-submit [response] - (let [jsonobj (js->clj (js/JSON.parse response))] - (auth-notifications jsonobj) - (on-menu-clicked "/resume/contactinfo"))) - -(defn render-contactinfo-modify-submit [id] - (POST "/resume/contactinfo/modify/submit" - {:format :raw - :params {:id id - :address (dommy/value (dommy/sel1 :#address)) - :city (dommy/value (dommy/sel1 :#city)) - :state_id (dommy/value (dommy/sel1 :#state_id)) - :phone (dommy/value (dommy/sel1 :#phone)) - :email (dommy/value (dommy/sel1 :#email)) - :url (dommy/value (dommy/sel1 :#url)) - :visastatus_id (dommy/value (dommy/sel1 :#visastatus_id))} - :handler handler-contactinfo-modify-submit})) - -;; contactinfo-delete - -(defn on-contactinfo-delete-clicked [id name] - (when (js/confirm (str "Are you sure you want to delete " name "? This action cannot be undone.")) - (render-contactinfo-delete id))) - -(defn handler-contactinfo-delete [response] - (let [jsonobj (js->clj (js/JSON.parse response))] - (auth-notifications jsonobj) - (on-menu-clicked "/resume/contactinfo"))) - -(defn render-contactinfo-delete [id] - (DELETE (str "/resume/contactinfo/delete/" id) - {:format :raw - :handler handler-contactinfo-delete})) - -;; education - -(hiccups/defhtml template-education [jsonobj] - [:h3 {:style "text-align: center"} (get jsonobj "title")] - [:div {:id "content"}] - [:div {:id "modify" - :class "modal fade" - :role "dialog" - :tabindex "-1"} - [:div {:class "modal-dialog modal-lg"} - [:div {:class "modal-content"} - [:div {:class "modal-header"} - [:h5 [:span {:id "modify-title"}]] - [:button {:type "button" - :class "close" - :data-dismiss "modal"} - "×"]] - [:div {:id "modify-body" - :class "modal-body" - :style "height: 450px;"}] - [:div {:class "modal-footer"} - [:button {:type "submit" - :class "btn btn-danger btn-default" - :data-dismiss "modal"} - [:span {:class "glyphicon glyphicon-remove"}] - "Cancel"]]]]]) - -(defn handler-education [response] - (let [jsonobj (js->clj (js/JSON.parse response))] - (notifications jsonobj) - (dommy/set-html! (dommy/sel1 :#body) (template-education jsonobj)) - (render-education-view))) - -(defn render-education [] - (GET "/resume/education" {:handler handler-education})) - -;; education-view - -(hiccups/defhtml template-education-view [jsonobj] - [:div {:style "text-align: right"} - [:img {:src "/static/images/add.png" - :style "cursor:pointer; cursor:hand" - :onclick (str (namespace ::x) ".on_education_add_clicked()")}]] - [:table {:class "table table-striped table-hover table-sm"} - [:thead - [:tr - [:th {:scope "col"} "School"] - [:th {:scope "col"} "Start Date"] - [:th {:scope "col"} "End Date"] - [:th {:scope "col"} "Major"] - [:th {:scope "col"} "Minor"] - [:th {:scope "col"} "Degree"] - [:th {:scope "col"} "Progress"] - [:th {:scope "col"} "Mod"] - [:th {:scope "col"} "Del"]]] - [:tbody - (for [education (get jsonobj "components")] - [:tr - [:td (get education "school")] - [:td (get education "start_date")] - [:td (get education "end_date")] - [:td (get education "major")] - [:td (get education "minor")] - [:td (get education "degree")] - [:td (get education "progress")] - [:td {:width "30"} - [:img {:src "/static/images/modify.png" - :onclick (str (namespace ::x) ".on_education_modify_clicked(" (get education "id") ")")}]] - [:td {:width "30"} - [:img {:src "/static/images/delete.png" - :onclick (str (namespace ::x) ".on_education_delete_clicked(" (get education "id") ", '" (str (get education "school") ", " (get education "major")) "')")}]]])]]) - -(defn handler-education-view [response] - (let [jsonobj (js->clj (js/JSON.parse response))] - (dommy/set-html! (dommy/sel1 :#content) (template-education-view jsonobj)))) - -(defn render-education-view [] - (GET "/resume/education/view" {:handler handler-education-view})) - -;; education-add - -(defn on-education-add-clicked [] - (render-education-add)) - -(hiccups/defhtml template-education-add [jsonobj] - (ck-form/template-generic-form (get jsonobj "form") (namespace ::x))) - -(defn handler-education-add [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-education-add jsonobj)) - (.modal (jquery "#modify")))) - -(defn render-education-add [] - (POST "/resume/education/add" {:handler handler-education-add})) - -;; education-add-submit - -(defn on-education-add-submit-clicked [] - (when (-> (jquery "#education-add-form") - (.get "0") - (.checkValidity)) - (.modal (jquery "#modify") "hide") - (render-education-add-submit))) - -(defn handler-education-add-submit [response] - (let [jsonobj (js->clj (js/JSON.parse response))] - (auth-notifications jsonobj) - (on-menu-clicked "/resume/education"))) - -(defn render-education-add-submit [] - (POST "/resume/education/add/submit" - {:format :raw - :params {:school (dommy/value (dommy/sel1 :#school)) - :major (dommy/value (dommy/sel1 :#major)) - :minor (dommy/value (dommy/sel1 :#minor)) - :degree (dommy/value (dommy/sel1 :#degree)) - :progress (dommy/value (dommy/sel1 :#progress)) - :start_date (dommy/value (dommy/sel1 :#start_date)) - :end_date (dommy/value (dommy/sel1 :#end_date))} - :handler handler-education-add-submit})) - -;; education-modify - -(defn on-education-modify-clicked [id] - (render-education-modify id)) - -(hiccups/defhtml template-education-modify [jsonobj] - (ck-form/template-generic-form (get jsonobj "form") (namespace ::x))) - -(defn handler-education-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-education-modify jsonobj)) - (.modal (jquery "#modify")))) - -(defn render-education-modify [id] - (POST "/resume/education/modify" - {:format :raw - :params {:id id} - :handler handler-education-modify})) - -;; education-modify-submit - -(defn on-education-modify-submit-clicked [id] - (when (-> (jquery "#education-modify-form") - (.get "0") - (.checkValidity)) - (.modal (jquery "#modify") "hide") - (render-education-modify-submit id))) - -(defn handler-education-modify-submit [response] - (let [jsonobj (js->clj (js/JSON.parse response))] - (auth-notifications jsonobj) - (on-menu-clicked "/resume/education"))) - -(defn render-education-modify-submit [id] - (POST "/resume/education/modify/submit" - {:format :raw - :params {:id id - :school (dommy/value (dommy/sel1 :#school)) - :major (dommy/value (dommy/sel1 :#major)) - :minor (dommy/value (dommy/sel1 :#minor)) - :degree (dommy/value (dommy/sel1 :#degree)) - :progress (dommy/value (dommy/sel1 :#progress)) - :start_date (dommy/value (dommy/sel1 :#start_date)) - :end_date (dommy/value (dommy/sel1 :#end_date))} - :handler handler-education-modify-submit})) - -;; education-delete - -(defn on-education-delete-clicked [id name] - (when (js/confirm (str "Are you sure you want to delete " name "? This action cannot be undone.")) - (render-education-delete id))) - -(defn handler-education-delete [response] - (let [jsonobj (js->clj (js/JSON.parse response))] - (auth-notifications jsonobj) - (on-menu-clicked "/resume/education"))) - -(defn render-education-delete [id] - (DELETE (str "/resume/education/delete/" id) - {:format :raw - :handler handler-education-delete})) - -;; language - -(hiccups/defhtml template-language [jsonobj] - [:h3 {:style "text-align: center"} (get jsonobj "title")] - [:div {:id "content"}] - [:div {:id "modify" - :class "modal fade" - :role "dialog" - :tabindex "-1"} - [:div {:class "modal-dialog modal-lg"} - [:div {:class "modal-content"} - [:div {:class "modal-header"} - [:h5 [:span {:id "modify-title"}]] - [:button {:type "button" - :class "close" - :data-dismiss "modal"} - "×"]] - [:div {:id "modify-body" - :class "modal-body" - :style "height: 450px;"}] - [:div {:class "modal-footer"} - [:button {:type "submit" - :class "btn btn-danger btn-default" - :data-dismiss "modal"} - [:span {:class "glyphicon glyphicon-remove"}] - "Cancel"]]]]]) - -(defn handler-language [response] - (let [jsonobj (js->clj (js/JSON.parse response))] - (notifications jsonobj) - (dommy/set-html! (dommy/sel1 :#body) (template-language jsonobj)) - (render-language-view))) - -(defn render-language [] - (GET "/resume/language" {:handler handler-language})) - -;; language-view - -(hiccups/defhtml template-language-view [jsonobj] - [:div {:style "text-align: right"} - [:img {:src "/static/images/add.png" - :style "cursor:pointer; cursor:hand" - :onclick (str (namespace ::x) ".on_language_add_clicked()")}]] - [:table {:class "table table-striped table-hover table-sm"} - [:thead - [:tr - [:th {:scope "col"} "Name"] - [:th {:scope "col"} "Understanding Listening"] - [:th {:scope "col"} "Understanding Reading"] - [:th {:scope "col"} "Speaking Interaction"] - [:th {:scope "col"} "Speaking Production"] - [:th {:scope "col"} "Writing"] - [:th {:scope "col"} "Mod"] - [:th {:scope "col"} "Del"]]] - [:tbody - (for [language (get jsonobj "components")] - [:tr - [:td (get language "name")] - [:td (get language "understanding_listening")] - [:td (get language "understanding_reading")] - [:td (get language "speaking_interaction")] - [:td (get language "speaking_production")] - [:td (get language "writing")] - [:td {:width "30"} - [:img {:src "/static/images/modify.png" - :onclick (str (namespace ::x) ".on_language_modify_clicked(" (get language "id") ")")}]] - [:td {:width "30"} - [:img {:src "/static/images/delete.png" - :onclick (str (namespace ::x) ".on_language_delete_clicked(" (get language "id") ", '" (get language "name") "')")}]]])]]) - -(defn handler-language-view [response] - (let [jsonobj (js->clj (js/JSON.parse response))] - (dommy/set-html! (dommy/sel1 :#content) (template-language-view jsonobj)))) - -(defn render-language-view [] - (GET "/resume/language/view" {:handler handler-language-view})) - -;; language-add - -(defn on-language-add-clicked [] - (render-language-add)) - -(hiccups/defhtml template-language-add [jsonobj] - (ck-form/template-generic-form (get jsonobj "form") (namespace ::x))) - -(defn handler-language-add [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-language-add jsonobj)) - (.modal (jquery "#modify")))) - -(defn render-language-add [] - (POST "/resume/language/add" {:handler handler-language-add})) - -;; language-add-submit - -(defn on-language-add-submit-clicked [] - (when (-> (jquery "#language-add-form") - (.get "0") - (.checkValidity)) - (.modal (jquery "#modify") "hide") - (render-language-add-submit))) - -(defn handler-language-add-submit [response] - (let [jsonobj (js->clj (js/JSON.parse response))] - (auth-notifications jsonobj) - (on-menu-clicked "/resume/language"))) - -(defn render-language-add-submit [] - (POST "/resume/language/add/submit" - {:format :raw - :params {:name (dommy/value (dommy/sel1 :#name)) - :understanding_listening (dommy/value (dommy/sel1 :#understanding_listening)) - :understanding_reading (dommy/value (dommy/sel1 :#understanding_reading)) - :speaking_interaction (dommy/value (dommy/sel1 :#speaking_interaction)) - :speaking_production (dommy/value (dommy/sel1 :#speaking_production)) - :writing (dommy/value (dommy/sel1 :#writing))} - :handler handler-language-add-submit})) - -;; language-modify - -(defn on-language-modify-clicked [id] - (render-language-modify id)) - -(hiccups/defhtml template-language-modify [jsonobj] - (ck-form/template-generic-form (get jsonobj "form") (namespace ::x))) - -(defn handler-language-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-language-modify jsonobj)) - (.modal (jquery "#modify")))) - -(defn render-language-modify [id] - (POST "/resume/language/modify" - {:format :raw - :params {:id id} - :handler handler-language-modify})) - -;; language-modify-submit - -(defn on-language-modify-submit-clicked [id] - (when (-> (jquery "#language-modify-form") - (.get "0") - (.checkValidity)) - (.modal (jquery "#modify") "hide") - (render-language-modify-submit id))) - -(defn handler-language-modify-submit [response] - (let [jsonobj (js->clj (js/JSON.parse response))] - (auth-notifications jsonobj) - (on-menu-clicked "/resume/language"))) - -(defn render-language-modify-submit [id] - (POST "/resume/language/modify/submit" - {:format :raw - :params {:id id - :name (dommy/value (dommy/sel1 :#name)) - :understanding_listening (dommy/value (dommy/sel1 :#understanding_listening)) - :understanding_reading (dommy/value (dommy/sel1 :#understanding_reading)) - :speaking_interaction (dommy/value (dommy/sel1 :#speaking_interaction)) - :speaking_production (dommy/value (dommy/sel1 :#speaking_production)) - :writing (dommy/value (dommy/sel1 :#writing))} - :handler handler-language-modify-submit})) - -;; language-delete - -(defn on-language-delete-clicked [id name] - (when (js/confirm (str "Are you sure you want to delete " name "? This action cannot be undone.")) - (render-language-delete id))) - -(defn handler-language-delete [response] - (let [jsonobj (js->clj (js/JSON.parse response))] - (auth-notifications jsonobj) - (on-menu-clicked "/resume/language"))) - -(defn render-language-delete [id] - (DELETE (str "/resume/language/delete/" id) - {:format :raw - :handler handler-language-delete})) - -;; skill - -(hiccups/defhtml template-skill [jsonobj] - [:h3 {:style "text-align: center"} (get jsonobj "title")] - [:div {:id "content"}] - [:div {:id "modify" - :class "modal fade" - :role "dialog" - :tabindex "-1"} - [:div {:class "modal-dialog modal-lg"} - [:div {:class "modal-content"} - [:div {:class "modal-header"} - [:h5 [:span {:id "modify-title"}]] - [:button {:type "button" - :class "close" - :data-dismiss "modal"} - "×"]] - [:div {:id "modify-body" - :class "modal-body" - :style "height: 450px;"}] - [:div {:class "modal-footer"} - [:button {:type "submit" - :class "btn btn-danger btn-default" - :data-dismiss "modal"} - [:span {:class "glyphicon glyphicon-remove"}] - "Cancel"]]]]]) - -(defn handler-skill [response] - (let [jsonobj (js->clj (js/JSON.parse response))] - (notifications jsonobj) - (dommy/set-html! (dommy/sel1 :#body) (template-skill jsonobj)) - (render-skill-view))) - -(defn render-skill [] - (GET "/resume/skill" {:handler handler-skill})) - -;; skill-view - -(hiccups/defhtml template-skill-view [jsonobj] - [:div {:style "text-align: right"} - [:img {:src "/static/images/add.png" - :style "cursor:pointer; cursor:hand" - :onclick (str (namespace ::x) ".on_skill_add_clicked()")}]] - [:table {:class "table table-striped table-hover table-sm"} - [:thead - [:tr - [:th {:scope "col"} "Skill"] - [:th {:scope "col"} "Mod"] - [:th {:scope "col"} "Del"]]] - [:tbody - (for [skill (get jsonobj "components")] - [:tr - [:td (get skill "skill")] - [:td {:width "30"} - [:img {:src "/static/images/modify.png" - :onclick (str (namespace ::x) ".on_skill_modify_clicked(" (get skill "id") ")")}]] - [:td {:width "30"} - [:img {:src "/static/images/delete.png" - :onclick (str (namespace ::x) ".on_skill_delete_clicked(" (get skill "id") ", '" (get skill "skill") "')")}]]])]]) - -(defn handler-skill-view [response] - (let [jsonobj (js->clj (js/JSON.parse response))] - (dommy/set-html! (dommy/sel1 :#content) (template-skill-view jsonobj)))) - -(defn render-skill-view [] - (GET "/resume/skill/view" {:handler handler-skill-view})) - -;; skill-add - -(defn on-skill-add-clicked [] - (render-skill-add)) - -(hiccups/defhtml template-skill-add [jsonobj] - (ck-form/template-generic-form (get jsonobj "form") (namespace ::x))) - -(defn handler-skill-add [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-skill-add jsonobj)) - (.modal (jquery "#modify")))) - -(defn render-skill-add [] - (POST "/resume/skill/add" {:handler handler-skill-add})) - -;; skill-add-submit - -(defn on-skill-add-submit-clicked [] - (when (-> (jquery "#skill-add-form") - (.get "0") - (.checkValidity)) - (.modal (jquery "#modify") "hide") - (render-skill-add-submit))) - -(defn handler-skill-add-submit [response] - (let [jsonobj (js->clj (js/JSON.parse response))] - (auth-notifications jsonobj) - (on-menu-clicked "/resume/skill"))) - -(defn render-skill-add-submit [] - (POST "/resume/skill/add/submit" - {:format :raw - :params {:skill (dommy/value (dommy/sel1 :#skill))} - :handler handler-skill-add-submit})) - -;; skill-modify - -(defn on-skill-modify-clicked [id] - (render-skill-modify id)) - -(hiccups/defhtml template-skill-modify [jsonobj] - (ck-form/template-generic-form (get jsonobj "form") (namespace ::x))) - -(defn handler-skill-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-skill-modify jsonobj)) - (.modal (jquery "#modify")))) - -(defn render-skill-modify [id] - (POST "/resume/skill/modify" - {:format :raw - :params {:id id} - :handler handler-skill-modify})) - -;; skill-modify-submit - -(defn on-skill-modify-submit-clicked [id] - (when (-> (jquery "#skill-modify-form") - (.get "0") - (.checkValidity)) - (.modal (jquery "#modify") "hide") - (render-skill-modify-submit id))) - -(defn handler-skill-modify-submit [response] - (let [jsonobj (js->clj (js/JSON.parse response))] - (auth-notifications jsonobj) - (on-menu-clicked "/resume/skill"))) - -(defn render-skill-modify-submit [id] - (POST "/resume/skill/modify/submit" - {:format :raw - :params {:id id - :skill (dommy/value (dommy/sel1 :#skill))} - :handler handler-skill-modify-submit})) - -;; skill-delete - -(defn on-skill-delete-clicked [id name] - (when (js/confirm (str "Are you sure you want to delete " name "? This action cannot be undone.")) - (render-skill-delete id))) - -(defn handler-skill-delete [response] - (let [jsonobj (js->clj (js/JSON.parse response))] - (auth-notifications jsonobj) - (on-menu-clicked "/resume/skill"))) - -(defn render-skill-delete [id] - (DELETE (str "/resume/skill/delete/" id) - {:format :raw - :handler handler-skill-delete})) - -;; location - -(defn on-menu-clicked [handler] - (reset-location handler) - (render-menu) - (cond (= handler "/home") (render-home) - (= handler "/login") (render-login) - (= handler "/logout") (render-logout) - (= handler "/profile") (render-profile) - (= handler "/password") (render-password) - (= handler "/contact-us") (render-contact-us) - (= handler "/messages") (render-messages) - (= handler "/users") (render-users) - (= handler "/resume") (render-resume) - (= handler "/resume/contactinfo") (render-contactinfo) - (= handler "/resume/education") (render-education) - (= handler "/resume/language") (render-language) - (= handler "/resume/skill") (render-skill) - (= handler "/resume/job") (render-job))) - -(defn handler-location [response] - (let [jsonobj (js->clj (js/JSON.parse response))] - (on-menu-clicked (get jsonobj "location")) - (notifications jsonobj))) - -(defn goto-location [location] - (POST "/location" - {:format :raw - :params {:location location} - :handler handler-location})) - -(defn reset-app [] - (set! (.-location js/document) "/")) - -(defn goto-register [hash] - (reset-location "/users/register") - (render-menu) - (render-users-register hash)) diff --git a/lisp/webapps/resume/clojurescript/resume/src/resume/core.cljs b/lisp/webapps/resume/clojurescript/resume/src/resume/core.cljs new file mode 100644 index 0000000..7b5747d --- /dev/null +++ b/lisp/webapps/resume/clojurescript/resume/src/resume/core.cljs @@ -0,0 +1,2076 @@ +(ns resume.core + (:require-macros [hiccups.core :as hiccups :refer [html]]) + (:require [ajax.core :refer [GET POST PUT DELETE raw-response-format]] + [dommy.core :as dommy] + [hiccups.runtime :as hiccupsrt] + [cljsjs.showdown :as showdown] + [clojure.string :as str] + [cljs-time.format :as time-format] + [reagent.core :as r] + [reagent.dom :as rd] + [reagent.dom.client :as rdc] + [org-ckons-cljs.notifications.react :as ck-notifications] + [org-ckons-cljs.form.core :as ck-form] + [resume.util :as util])) + +;; declarations + +(declare date-sql-to-pretty) +(declare markdown-to-html) +(declare reduce-checkboxes) +(declare comp-app) +(declare start-render) +(declare start-location) +(declare reset-location) +(declare start) +(declare notifications) +(declare auth-notifications) +(declare comp-menu-main) +(declare comp-menu-user) +(declare handler-menu) +(declare handler-menu-user) +(declare render-menu) +(declare render-home) +(declare template-login) +(declare handler-login) +(declare render-login) +(declare on-login-submit-clicked) +(declare handler-login-authenticate) +(declare render-login-authenticate) +(declare handler-logout) +(declare render-logout) +(declare template-profile) +(declare handler-profile) +(declare render-profile) +(declare template-profile-view) +(declare handler-profile-view) +(declare render-profile-view) +(declare on-profile-modify-clicked) +(declare template-profile-modify) +(declare handler-profile-modify) +(declare render-profile-modify) +(declare on-profile-modify-submit-clicked) +(declare handler-profile-modify-submit) +(declare render-profile-modify-submit) +(declare template-password) +(declare handler-password) +(declare render-password) +(declare on-password-submit-clicked) +(declare handler-password-submit) +(declare render-password-submit) +(declare template-about-us) +(declare handler-about-us) +(declare render-lessons) +(declare template-about-us-view) +(declare handler-about-us-view) +(declare render-about-us-view) +(declare on-about-us-modify-clicked) +(declare template-about-us-modify) +(declare handler-about-us-modify) +(declare render-about-us-modify) +(declare on-about-us-modify-submit-clicked) +(declare handler-about-us-modify-submit) +(declare render-about-us-modify-submit) +(declare template-contact-us) +(declare handler-contact-us) +(declare render-contact-us) +(declare template-contact-us-view) +(declare handler-contact-us-view) +(declare render-contact-us-view) +(declare on-contact-us-email-submit-clicked) +(declare handler-contact-us-email-submit) +(declare render-contact-us-email-submit) +(declare template-messages) +(declare handler-messages) +(declare render-messages) +(declare on-messages-mode-clicked) +(declare template-messages-results) +(declare handler-messages-results) +(declare render-messages-results) +(declare on-messages-mark) +(declare handler-messages-mark) +(declare render-messages-mark) +(declare template-users) +(declare handler-users) +(declare render-users) +(declare template-users-view) +(declare handler-users-view) +(declare render-users-view) +(declare on-users-add-clicked) +(declare template-users-add) +(declare handler-users-add) +(declare render-users-add) +(declare on-users-add-submit-clicked) +(declare handler-users-add-submit) +(declare render-users-add-submit) +(declare template-users-register) +(declare handler-users-register) +(declare render-users-register) +(declare template-users-register-form) +(declare handler-users-register-form) +(declare handler-users-register-form-impl) +(declare render-users-register-form) +(declare on-users-register-submit-clicked) +(declare template-users-register-submit) +(declare handler-users-register-submit) +(declare render-users-register-submit) +(declare on-users-modify-clicked) +(declare template-users-modify) +(declare handler-users-modify) +(declare render-users-modify) +(declare on-users-modify-submit-clicked) +(declare handler-users-modify-submit) +(declare render-users-modify-submit) +(declare on-users-toggle-active-clicked) +(declare handler-users-toggle-active) +(declare render-users-toggle-active) +(declare on-users-delete-clicked) +(declare handler-users-delete) +(declare render-users-delete) +(declare template-resume) +(declare handler-resume) +(declare render-resume) +(declare template-resume-view) +(declare handler-resume-view) +(declare render-resume-view) +(declare on-resume-add-clicked) +(declare template-resume-add) +(declare handler-resume-add) +(declare render-resume-add) +(declare on-resume-add-submit-clicked) +(declare handler-resume-add-submit) +(declare render-resume-add-submit) +(declare on-resume-modify-clicked) +(declare template-resume-modify) +(declare handler-resume-modify) +(declare render-resume-modify) +(declare on-resume-modify-submit-clicked) +(declare handler-resume-modify-submit) +(declare render-resume-modify-submit) +(declare on-resume-delete-clicked) +(declare handler-resume-delete) +(declare render-resume-delete) + +(declare template-contactinfo) +(declare handler-contactinfo) +(declare render-contactinfo) +(declare template-contactinfo-view) +(declare handler-contactinfo-view) +(declare render-contactinfo-view) +(declare on-contactinfo-add-clicked) +(declare template-contactinfo-add) +(declare handler-contactinfo-add) +(declare render-contactinfo-add) +(declare on-contactinfo-add-submit-clicked) +(declare handler-contactinfo-add-submit) +(declare render-contactinfo-add-submit) +(declare on-contactinfo-modify-clicked) +(declare template-contactinfo-modify) +(declare handler-contactinfo-modify) +(declare render-contactinfo-modify) +(declare on-contactinfo-modify-submit-clicked) +(declare handler-contactinfo-modify-submit) +(declare render-contactinfo-modify-submit) +(declare on-contactinfo-delete-clicked) +(declare handler-contactinfo-delete) +(declare render-contactinfo-delete) + +(declare template-education) +(declare handler-education) +(declare render-education) +(declare template-education-view) +(declare handler-education-view) +(declare render-education-view) +(declare on-education-add-clicked) +(declare template-education-add) +(declare handler-education-add) +(declare render-education-add) +(declare on-education-add-submit-clicked) +(declare handler-education-add-submit) +(declare render-education-add-submit) +(declare on-education-modify-clicked) +(declare template-education-modify) +(declare handler-education-modify) +(declare render-education-modify) +(declare on-education-modify-submit-clicked) +(declare handler-education-modify-submit) +(declare render-education-modify-submit) +(declare on-education-delete-clicked) +(declare handler-education-delete) +(declare render-education-delete) +(declare template-language) +(declare handler-language) +(declare render-language) +(declare template-language-view) +(declare handler-language-view) +(declare render-language-view) +(declare on-language-add-clicked) +(declare template-language-add) +(declare handler-language-add) +(declare render-language-add) +(declare on-language-add-submit-clicked) +(declare handler-language-add-submit) +(declare render-language-add-submit) +(declare on-language-modify-clicked) +(declare template-language-modify) +(declare handler-language-modify) +(declare render-language-modify) +(declare on-language-modify-submit-clicked) +(declare handler-language-modify-submit) +(declare render-language-modify-submit) +(declare on-language-delete-clicked) +(declare handler-language-delete) +(declare render-language-delete) +(declare template-skill) +(declare handler-skill) +(declare render-skill) +(declare template-skill-view) +(declare handler-skill-view) +(declare render-skill-view) +(declare on-skill-add-clicked) +(declare template-skill-add) +(declare handler-skill-add) +(declare render-skill-add) +(declare on-skill-add-submit-clicked) +(declare handler-skill-add-submit) +(declare render-skill-add-submit) +(declare on-skill-modify-clicked) +(declare template-skill-modify) +(declare handler-skill-modify) +(declare render-skill-modify) +(declare on-skill-modify-submit-clicked) +(declare handler-skill-modify-submit) +(declare render-skill-modify-submit) +(declare on-skill-delete-clicked) +(declare handler-skill-delete) +(declare render-skill-delete) +(declare on-menu-clicked) +(declare handler-location) +(declare goto-location) +(declare goto-register) +(declare reset-app) +(declare reset-about-us-category) + +(enable-console-print!) + +(def jquery (js* "$")) +(def sql-formatter (time-format/formatter "yyyy-MM-dd HH:mm:ss")) +(def pretty-formatter (time-format/formatters :rfc822)) +(def location-state (r/atom "/home")) +(def about-us-category-state (r/atom "home")) +(def menu-main-state (r/atom [])) +(def menu-user-state (r/atom [])) +(def menu-user-label (r/atom "Guest User")) + +;; helper functions + +(defn date-sql-to-pretty [sql-date] + (first (str/split (time-format/unparse pretty-formatter (time-format/parse sql-formatter (first (str/split sql-date ".")))) " Z"))) + +(defn markdown-to-html [markdown] + (let [converter (js/showdown.Converter.)] + (.makeHtml converter markdown))) + +(defn reduce-checkboxes [selector] + "Reduces the names of all checked checkboxes to a pipe-separated + list. Assumes that the checkboxes are named via the convention + `chk_something-more'. The important thing is the underscore + 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 + :else "")) + (map (fn [elem] + (let [this (jquery (str "#" (dommy/attr elem :id)))] + (when (-> this (.prop "checked")) + (second (str/split (-> this (.prop "id")) "_"))))) + (.toArray (jquery selector))))) + +;; body + +(defn comp-app [] + [:div {:class "container-fluid"} + [:div {:class "banner"} + [:table {:width "100%" :height "100%"} + [:tbody + [:tr + [:td {:class "banner-menu"} + [comp-menu-user]] + [:td {:class "banner-title"} "Resume Builder"] + [:td {:class "banner-menu"} " "]]]]] + [comp-menu-main] + [ck-notifications/comp-errormsg] + [ck-notifications/comp-message] + [:div {:id "body"}] + [:div {:id "footer"} + [:hr] + "Carlos Konstanski (970) 294-9708" + [:br] + [:a {:href "https://github.com/ckonstanski/resume/tree/master" + :target "_blank"} + "Source code on GitHub"]]]) + +;; start the react app + +(defn start-render [] + (let [app-root (rdc/create-root (js/document.getElementById "app"))] + (rdc/render app-root [comp-app]))) + +(defn start-location [] + (cond (str/starts-with? @location-state "/register/") + (goto-register (str/replace-first @location-state "/register/" "")) + :else + (goto-location @location-state))) + +(defn reset-location [url] + (reset! location-state url)) + +(defn reset-about-us-category [category] + (reset! about-us-category-state category)) + +(defn ^:dev/after-load start + ([] + (start-render) + (start-location)) + ([url] + (reset-location url) + (start-render) + (start-location))) + +;; notifications + +(defn notifications [jsonobj] + (ck-notifications/reset-message (get jsonobj "message")) + (ck-notifications/reset-errormsg (get jsonobj "errormsg"))) + +(defn auth-notifications [jsonobj] + (cond (empty? (get jsonobj "errormsg")) + (notifications jsonobj) + :else + (do + (render-home "" (get jsonobj "errormsg")) + (render-menu)))) + +;; menu + +(defn comp-menu-main [] + [:div {:class "well"} + [:ul {:class "nav nav-pills"} + (for [menuitem (doall @menu-main-state)] + [:li {:key (str "li_" (get menuitem "id")) + :class "nav-item"} + [:a {:class (cond (= (str/upper-case (get menuitem "handler")) + (str/upper-case @location-state)) + "nav-link active" + :else + "nav-link") + :key (get menuitem "id") + :on-click #(on-menu-clicked (get menuitem "handler"))} + (get menuitem "label")]])]]) + +(defn comp-menu-user [] + [:div {:class "dropdown"} + [:button {:class "btn btn-primary dropdown-toggle" + :type "button" + :id "button-menu-user" + :data-toggle "dropdown" + :aria-haspopup "true" + :aria-expanded "false"} + @menu-user-label] + [:div {:class "dropdown-menu" :aria-labelledby "button-menu-user"} + (for [menuitem (doall @menu-user-state)] + [:a {:key (get menuitem "id") + :class "dropdown-item" + :on-click #(on-menu-clicked (get menuitem "handler"))} + (get menuitem "label")])]]) + +(defn handler-menu [response] + (let [jsonobj (js->clj (js/JSON.parse response))] + (reset! menu-main-state (get jsonobj "menuitems")))) + +(defn handler-menu-user [response] + (let [jsonobj (js->clj (js/JSON.parse response))] + (reset! menu-user-state (get jsonobj "menuitems")) + (reset! menu-user-label (get jsonobj "label")))) + +(defn render-menu [] + (GET "/menu" {:handler handler-menu}) + (GET "/menu/user" {:handler handler-menu-user})) + +;; login + +(hiccups/defhtml template-login [jsonobj] + [:h3 {:style "text-align: center"} (get jsonobj "title")] + (ck-form/template-generic-form (get jsonobj "form") (namespace ::x)) + [:div {:style "text-align: center"} + [:a {:href ""} "Forgot password?"]]) + +(defn handler-login [response] + (let [jsonobj (js->clj (js/JSON.parse response))] + (notifications jsonobj) + (dommy/set-html! (dommy/sel1 :#body) (template-login jsonobj)))) + +(defn render-login [] + (GET "/login" {:handler handler-login})) + +;; login-authenticate + +(defn on-login-submit-clicked [] + (when (-> (jquery "#login-form") + (.get "0") + (.checkValidity)) + (render-login-authenticate))) + +(defn handler-login-authenticate [response] + (let [jsonobj (js->clj (js/JSON.parse response))] + (cond (get jsonobj "errormsg") + (goto-location "/login") + (get jsonobj "message") + (do + (reset-location "/home") + (render-home) + (render-menu))))) + +(defn render-login-authenticate [] + (POST "/login/authenticate" + {:format :raw + :params {:username (dommy/value (dommy/sel1 :#username)) + :pwd (dommy/value (dommy/sel1 :#pwd))} + :handler handler-login-authenticate})) + +;; logout + +(defn handler-logout [response] + (let [jsonobj (js->clj (js/JSON.parse response))] + (render-home "You are now logged out" "") + (reset-location "/home") + (render-menu))) + +(defn render-logout [] + (GET "/logout" {:handler handler-logout})) + +;; profile + +(hiccups/defhtml template-profile [jsonobj] + [:h3 {:style "text-align: center"} (get jsonobj "title")] + [:div {:id "content"}] + [:div {:id "modify" + :class "modal fade" + :role "dialog" + :tabindex "-1"} + [:div {:class "modal-dialog modal-lg"} + [:div {:class "modal-content"} + [:div {:class "modal-header"} + [:h5 {:class "modal-title"} "Profile - Modify"] + [:button {:type "button" + :class "close" + :data-dismiss "modal"} + "×"]] + [:div {:id "modify-body" + :class "modal-body" + :style "height: 460px;"}] + [:div {:class "modal-footer"} + [:button {:type "submit" + :class "btn btn-danger btn-default" + :data-dismiss "modal"} + [:span {:class "glyphicon glyphicon-remove"}] + "Cancel"]]]]]) + +(defn handler-profile [response] + (let [jsonobj (js->clj (js/JSON.parse response))] + (notifications jsonobj) + (dommy/set-html! (dommy/sel1 :#body) (template-profile jsonobj)) + (render-profile-view))) + +(defn render-profile [] + (GET "/profile" {:handler handler-profile})) + +;; profile-view + +(hiccups/defhtml template-profile-view [jsonobj] + [:div {:style "text-align: right"} + [:img {:src "/static/images/edit.png" + :style "cursor:pointer; cursor:hand" + :onclick (str (namespace ::x) ".on_profile_modify_clicked()")}]] + [:div {:class "container"} + [:div {:class "row"} + [:div {:class "col" :style "text-align: right"} "Username:"] + [:div {:class "col-10"} (get jsonobj "username")]] + [:div {:class "row"} + [:div {:class "col" :style "text-align: right"} "First Name:"] + [:div {:class "col-10"} (get jsonobj "first_name")]] + [:div {:class "row"} + [:div {:class "col" :style "text-align: right"} "Last Name:"] + [:div {:class "col-10"} (get jsonobj "last_name")]] + [:div {:class "row"} + [:div {:class "col" :style "text-align: right"} "Email:"] + [:div {:class "col-10"} (get jsonobj "email")]] + [:div {:class "row"} + [:div {:class "col" :style "text-align: right"} "Phone:"] + [:div {:class "col-10"} (get jsonobj "phone")]]]) + +(defn handler-profile-view [response] + (let [jsonobj (js->clj (js/JSON.parse response))] + (dommy/set-html! (dommy/sel1 :#content) (template-profile-view jsonobj)))) + +(defn render-profile-view [] + (GET "/profile/view" {:handler handler-profile-view})) + +;; profile-modify + +(defn on-profile-modify-clicked [] + (render-profile-modify)) + +(hiccups/defhtml template-profile-modify [jsonobj] + (ck-form/template-generic-form (get jsonobj "form") (namespace ::x))) + +(defn handler-profile-modify [response] + (let [jsonobj (js->clj (js/JSON.parse response))] + (auth-notifications jsonobj) + (dommy/set-html! (dommy/sel1 :#modify-body) (template-profile-modify jsonobj)) + (.modal (jquery "#modify")))) + +(defn render-profile-modify [] + (POST "/profile/modify" {:handler handler-profile-modify})) + +;; profile-modify-submit + +(defn on-profile-modify-submit-clicked [] + (when (-> (jquery "#profile-modify-form") + (.get "0") + (.checkValidity)) + (.modal (jquery "#modify") "hide") + (render-profile-modify-submit))) + +(defn handler-profile-modify-submit [response] + (let [jsonobj (js->clj (js/JSON.parse response))] + (auth-notifications jsonobj) + (on-menu-clicked "/profile"))) + +(defn render-profile-modify-submit [] + (POST "/profile/modify/submit" + {:format :raw + :params {:id (dommy/value (dommy/sel1 :#id)) + :username (dommy/value (dommy/sel1 :#username)) + :first_name (dommy/value (dommy/sel1 :#first_name)) + :last_name (dommy/value (dommy/sel1 :#last_name)) + :email (dommy/value (dommy/sel1 :#email)) + :phone (dommy/value (dommy/sel1 :#phone))} + :handler handler-profile-modify-submit})) + +;; password + +(hiccups/defhtml template-password [jsonobj] + [:h3 {:style "text-align: center"} (get jsonobj "title")] + (ck-form/template-generic-form (get jsonobj "form") (namespace ::x))) + +(defn handler-password [response] + (let [jsonobj (js->clj (js/JSON.parse response))] + (notifications jsonobj) + (dommy/set-html! (dommy/sel1 :#body) (template-password jsonobj)))) + +(defn render-password [] + (GET "/password" {:handler handler-password})) + +;; password-submit + +(defn on-password-submit-clicked [] + (when (-> (jquery "#password-form") + (.get "0") + (.checkValidity)) + (render-password-submit))) + +(defn handler-password-submit [response] + (let [jsonobj (js->clj (js/JSON.parse response))] + (auth-notifications jsonobj) + (on-menu-clicked "/password"))) + +(defn render-password-submit [] + (POST "/password/submit" + {:format :raw + :params {:id (dommy/value (dommy/sel1 :#id)) + :pwd (dommy/value (dommy/sel1 :#pwd)) + :pwd2 (dommy/value (dommy/sel1 :#pwd2))} + :handler handler-password-submit})) + +;; about-us (home) + +(hiccups/defhtml template-about-us [jsonobj] + [:h1 {:style "text-align: center"} + (cond (= @about-us-category-state "home") "Home")] + [:div {:id "content"}] + [:div {:id "modify" + :class "modal fade" + :role "dialog" + :tabindex "-1"} + [:div {:class "modal-dialog modal-lg"} + [:div {:class "modal-content"} + [:div {:class "modal-header"} + [:h5 [:span {:id "modify-title"}]] + [:button {:type "button" + :class "close" + :data-dismiss "modal"} + "×"]] + [:div {:id "modify-body" + :class "modal-body" + :style "height: 460px;"}] + [:div {:class "modal-footer"} + [:button {:type "submit" + :class "btn btn-danger btn-default" + :data-dismiss "modal"} + [:span {:class "glyphicon glyphicon-remove"}] + "Cancel"]]]]]) + +(defn handler-about-us [response] + (let [jsonobj (js->clj (js/JSON.parse response))] + (reset-about-us-category (get jsonobj "category")) + (notifications jsonobj) + (dommy/set-html! (dommy/sel1 :#body) (template-about-us jsonobj)) + (render-about-us-view))) + +(defn render-home + ([] + (GET "/home" {:handler handler-about-us})) + ([message errormsg] + (POST "/home" + {:format :raw + :params {:message message + :errormsg errormsg} + :handler handler-about-us}))) + +;; about-us-view + +(hiccups/defhtml template-about-us-view [jsonobj] + (when (get jsonobj "adminP") + [:div {:style "text-align: right;"} + [:img {:src "/static/images/edit.png" + :style "cursor:pointer; cursor:hand" + :onclick (str (namespace ::x) ".on_about_us_modify_clicked()")}]]) + [:div {:id "markdown"}]) + +(defn handler-about-us-view [response] + (let [jsonobj (js->clj (js/JSON.parse response))] + (dommy/set-html! (dommy/sel1 :#content) (template-about-us-view jsonobj)) + (dommy/set-html! (dommy/sel1 :#markdown) (markdown-to-html (get jsonobj "content"))))) + +(defn render-about-us-view [] + (GET (str "/" @about-us-category-state "/view") + {:handler handler-about-us-view})) + +;; about-us-modify + +(defn on-about-us-modify-clicked [] + (render-about-us-modify)) + +(hiccups/defhtml template-about-us-modify [jsonobj] + (ck-form/template-generic-form (get jsonobj "form") (namespace ::x))) + +(defn handler-about-us-modify [response] + (let [jsonobj (js->clj (js/JSON.parse response))] + (auth-notifications jsonobj) + (dommy/set-html! (dommy/sel1 :#modify-title) + (str (cond (= @about-us-category-state "home") "Home") + " - Modify")) + (dommy/set-html! (dommy/sel1 :#modify-body) (template-about-us-modify jsonobj)) + (.modal (jquery "#modify")))) + +(defn render-about-us-modify [] + (POST (str "/" @about-us-category-state "/modify") + {:handler handler-about-us-modify})) + +;; about-us-modify-submit + +(defn on-about-us-modify-submit-clicked [] + (when (-> (jquery "#about-us-modify-form") + (.get "0") + (.checkValidity)) + (.modal (jquery "#modify") "hide") + (render-about-us-modify-submit))) + +(defn handler-about-us-modify-submit [response] + (let [jsonobj (js->clj (js/JSON.parse response))] + (auth-notifications jsonobj) + (dommy/set-html! (dommy/sel1 :#content) (template-about-us-view jsonobj)) + (dommy/set-html! (dommy/sel1 :#markdown) (markdown-to-html (get jsonobj "content"))))) + +(defn render-about-us-modify-submit [] + (POST (str "/" @about-us-category-state "/modify/submit") + {:format :raw + :params {:content (dommy/value (dommy/sel1 :#txt-content))} + :handler handler-about-us-modify-submit})) + +;; contact-us + +(hiccups/defhtml template-contact-us [jsonobj] + [:h1 {:style "text-align: center"} "Reach out to me by filling out the form."] + [:div {:id "content"}] + [: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"}]]]]) + +(defn handler-contact-us [response] + (let [jsonobj (js->clj (js/JSON.parse response))] + (notifications jsonobj) + (dommy/set-html! (dommy/sel1 :#body) (template-contact-us jsonobj)) + (render-contact-us-view))) + +(defn render-contact-us [] + (GET "/contact-us" {:handler handler-contact-us})) + +;; contact-us-view + +(hiccups/defhtml template-contact-us-view [jsonobj] + (ck-form/template-generic-form (get jsonobj "form") (namespace ::x))) + +(defn handler-contact-us-view [response] + (let [jsonobj (js->clj (js/JSON.parse response))] + (notifications jsonobj) + (dommy/set-html! (dommy/sel1 :#content) (template-contact-us-view jsonobj)))) + +(defn render-contact-us-view [] + (GET "/contact-us/view" {:handler handler-contact-us-view})) + +;; contact-us-submit + +(defn on-contact-us-email-submit-clicked [] + (when (-> (jquery "#contact-us-form") + (.get "0") + (.checkValidity)) + (render-contact-us-email-submit))) + +(defn handler-contact-us-email-submit [response] + (on-menu-clicked "/contact-us")) + +(defn render-contact-us-email-submit [] + (POST "/contact-us/email" + {:format :raw + :params {:first_name (dommy/value (dommy/sel1 :#first_name)) + :last_name (dommy/value (dommy/sel1 :#last_name)) + :email (dommy/value (dommy/sel1 :#email)) + :phone (dommy/value (dommy/sel1 :#phone)) + :comments (dommy/value (dommy/sel1 :#comments))} + :handler handler-contact-us-email-submit})) + +;; messages + +(hiccups/defhtml template-messages [jsonobj] + [:h3 {:style "text-align: center"} (get jsonobj "title")] + (ck-form/template-generic-form (get jsonobj "form") (namespace ::x)) + [:div {:id "results"}]) + +(defn handler-messages [response] + (let [jsonobj (js->clj (js/JSON.parse response))] + (notifications jsonobj) + (dommy/set-html! (dommy/sel1 :#body) (template-messages jsonobj)) + (when (not (empty? (dommy/value (dommy/sel1 :#read)))) + (render-messages-results)))) + +(defn render-messages [] + (GET "/messages" {:handler handler-messages})) + +;; messages-results + +(defn on-messages-mode-clicked [read] + (dommy/set-value! (dommy/sel1 :#read) read) + (render-messages-results)) + +(hiccups/defhtml template-messages-results [jsonobj] + (let [results (get jsonobj "results") + keys (remove (fn [x] + (not (get (first results) x))) + (keys (first results)))] + (cond (empty? results) + [:h5 {:style "text-align: center"} "No results found."] + :else + [:table {:class "table table-hover"} + [:thead + [:tr + (for [key keys] + [:th key]) + [:th + (str "Mark " (cond (= (dommy/value (dommy/sel1 :#read)) "read") + "unread" + :else + "read"))]]] + [:tbody + (for [rec results] + (let [onclick "void()"] + [:tr + (for [key keys] + [:td {:onclick onclick} (get rec key)]) + [:td [:img {:src (str "/static/images/" + (cond (= (dommy/value (dommy/sel1 :#read)) "read") + "edit-undo.png" + :else + "edit-redo.png")) + :style "cursor: pointer; cursor: hand" + :onclick (str (namespace ::x) + ".on_messages_mark(" + (cond (= (dommy/value (dommy/sel1 :#read)) "read") + "'unread'" + :else + "'read'") + "," (get rec "id") ")")}]]]))]]))) + +(defn handler-messages-results [response] + (let [jsonobj (js->clj (js/JSON.parse response))] + (auth-notifications jsonobj) + (dommy/set-html! (dommy/sel1 :#results) (template-messages-results jsonobj)))) + +(defn render-messages-results [] + (POST "/messages/results" + {:format :raw + :params {:read (dommy/value (dommy/sel1 :#read))} + :handler handler-messages-results})) + +;; messages-mark + +(defn on-messages-mark [read id] + (render-messages-mark read id)) + +(defn handler-messages-mark [response] + (let [jsonobj (js->clj (js/JSON.parse response))] + (auth-notifications jsonobj) + (on-menu-clicked "/messages"))) + +(defn render-messages-mark [read id] + (POST "/messages/mark" + {:format :raw + :params {:read read + :id id} + :handler handler-messages-mark})) + +;; users + +(hiccups/defhtml template-users [jsonobj] + [:h3 {:style "text-align: center"} (get jsonobj "title")] + [:div {:id "content"}] + [:div {:id "modify" + :class "modal fade" + :role "dialog" + :tabindex "-1"} + [:div {:class "modal-dialog modal-lg"} + [:div {:class "modal-content"} + [:div {:class "modal-header"} + [:h5 [:span {:id "modify-title"}]] + [:button {:type "button" + :class "close" + :data-dismiss "modal"} + "×"]] + [:div {:id "modify-body" + :class "modal-body" + :style "height: 450px;"}] + [:div {:class "modal-footer"} + [:button {:type "submit" + :class "btn btn-danger btn-default" + :data-dismiss "modal"} + [:span {:class "glyphicon glyphicon-remove"}] + "Cancel"]]]]]) + +(defn handler-users [response] + (let [jsonobj (js->clj (js/JSON.parse response))] + (notifications jsonobj) + (dommy/set-html! (dommy/sel1 :#body) (template-users jsonobj)) + (render-users-view))) + +(defn render-users [] + (GET "/users" {:handler handler-users})) + +;; users-view + +(hiccups/defhtml template-users-view [jsonobj] + [:div {:style "text-align: right"} + [:img {:src "/static/images/add.png" + :style "cursor:pointer; cursor:hand" + :onclick (str (namespace ::x) ".on_users_add_clicked()")}]] + [:table {:class "table table-striped table-hover table-sm"} + [:thead + [:tr + [:th {:scope "col"} "Active?"] + [:th {:scope "col"} "Last Name"] + [:th {:scope "col"} "First Name"] + [:th {:scope "col"} "Username"] + [:th {:scope "col"} "Email"] + [:th {:scope "col"} "Phone"] + [:th {:scope "col"} "Del"]]] + [:tbody + (for [user (get jsonobj "users")] + (let [onclick (str (namespace ::x) ".on_users_modify_clicked(" (get user "id") ")") + toggle-active (str (namespace ::x) ".on_users_toggle_active_clicked(" (get user "id") ")")] + [:tr + [:td [:img {:src (cond (get user "active") + "/static/images/yes.png" + :else + "/static/images/no.png") + :onclick toggle-active}]] + [:td {:onclick onclick} (get user "last_name")] + [:td {:onclick onclick} (get user "first_name")] + [:td {:onclick onclick} (get user "username")] + [:td {:onclick onclick} (get user "email")] + [:td {:onclick onclick} (get user "phone")] + [:td [:img {:src "/static/images/delete.png" + :onclick (str (namespace ::x) ".on_users_delete_clicked(" (get user "id") ", '" (get user "first_name") "', '" (get user "last_name") "')")}]]]))]]) + +(defn handler-users-view [response] + (let [jsonobj (js->clj (js/JSON.parse response))] + (dommy/set-html! (dommy/sel1 :#content) (template-users-view jsonobj)))) + +(defn render-users-view [] + (GET "/users/view" {:handler handler-users-view})) + +;; users-add + +(defn on-users-add-clicked [] + (render-users-add)) + +(hiccups/defhtml template-users-add [jsonobj] + (ck-form/template-generic-form (get jsonobj "form") (namespace ::x))) + +(defn handler-users-add [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-add jsonobj)) + (.modal (jquery "#modify")))) + +(defn render-users-add [] + (POST "/users/add" {:handler handler-users-add})) + +;; users-add-submit + +(defn on-users-add-submit-clicked [] + (when (-> (jquery "#users-add-form") + (.get "0") + (.checkValidity)) + (.modal (jquery "#modify") "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"))) + +(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))} + :handler handler-users-add-submit})) + +;; users-register + +(hiccups/defhtml template-users-register [jsonobj] + [:h3 {:style "text-align: center"} (get jsonobj "title")] + [:div {:id "content"}]) + +(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")))) + +(defn render-users-register [hash] + (POST "/users/register" + {:format :raw + :params {:hash hash} + :handler handler-users-register})) + +;; 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 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)))) + +(defn render-users-register-form [hash] + (POST "/users/register/form" + {:format :raw + :params {:hash hash} + :handler handler-users-register-form})) + +;; users-register-submit + +(defn on-users-register-submit-clicked [] + (when (-> (jquery "#users-register-form") + (.get "0") + (.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 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))))) + +(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))} + :handler handler-users-register-submit})) + +;; users-modify + +(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 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")))) + +(defn render-users-modify [id] + (POST "/users/modify" + {:format :raw + :params {:id id} + :handler handler-users-modify})) + +;; users-modify-submit + +(defn on-users-modify-submit-clicked [] + (when (-> (jquery "#users-modify-form") + (.get "0") + (.checkValidity)) + (.modal (jquery "#modify") "hide") + (render-users-modify-submit))) + +(defn handler-users-modify-submit [response] + (let [jsonobj (js->clj (js/JSON.parse response))] + (auth-notifications jsonobj) + (on-menu-clicked "/users"))) + +(defn render-users-modify-submit [] + (POST "/users/modify/submit" + {:format :raw + :params {:id (dommy/value (dommy/sel1 :#id)) + :role_groups (reduce-checkboxes "[id^='chk_']") + :username (dommy/value (dommy/sel1 :#username)) + :first_name (dommy/value (dommy/sel1 :#first_name)) + :last_name (dommy/value (dommy/sel1 :#last_name)) + :email (dommy/value (dommy/sel1 :#email)) + :phone (dommy/value (dommy/sel1 :#phone))} + :handler handler-users-modify-submit})) + +;; users-toggle-active + +(defn on-users-toggle-active-clicked [id] + (render-users-toggle-active id)) + +(defn handler-users-toggle-active [response] + (let [jsonobj (js->clj (js/JSON.parse response))] + (auth-notifications jsonobj) + (on-menu-clicked "/users"))) + +(defn render-users-toggle-active [id] + (POST "/users/toggle-active" + {:format :raw + :params {:id id} + :handler handler-users-toggle-active})) + +;; users-delete + +(defn on-users-delete-clicked [id first-name last-name] + (when (js/confirm (str "Are you sure you want to delete " first-name " " last-name "? This action cannot be undone.")) + (render-users-delete id))) + +(defn handler-users-delete [response] + (let [jsonobj (js->clj (js/JSON.parse response))] + (auth-notifications jsonobj) + (on-menu-clicked "/users"))) + +(defn render-users-delete [id] + (DELETE (str "/users/delete/" id) + {:format :raw + :handler handler-users-delete})) + +;; resume + +(defn generic-table [component jsonobj & [reverse-p]] + (let [results (get jsonobj "components") + keys (remove (fn [x] + (not (get (first results) x))) + (sort #(if reverse-p (compare %2 %1) (compare %1 %2)) (keys (first results))))] + (cond (empty? results) + [:h5 {:style "text-align: center"} (str "No " component "s found.")] + :else + [:div + [:p (str (count results) " " component "s.")] + [:table {:class "table table-striped table-hover table-sm"} + [:thead + [:tr + (for [key keys] + [:th {:scope "col"} key]) + [:th {:scope "col"} "Mod"] + [:th {:scope "col"} "Del"]]] + [:tbody + (for [rec results] + [:tr + (for [key keys] + [:td (str (get rec key))]) + [:td {:width "30"} + [:img {:src "/static/images/modify.png" + :onclick (str (namespace ::x) ".on_" component "_modify_clicked(" (get rec "id") ")")}]] + [:td {:width "30"} + [:img {:src "/static/images/delete.png" + :onclick (str (namespace ::x) ".on_" component "_delete_clicked(" (get rec "id") "')")}]]])]]]))) + +(hiccups/defhtml generic-component-add [jsonobj] + (ck-form/template-generic-form (get jsonobj "form") (namespace ::x))) + +(hiccups/defhtml template-resume [jsonobj] + [:h3 {:style "text-align: center"} (get jsonobj "title")] + [:div {:id "content"}] + [:div {:id "modify" + :class "modal fade" + :role "dialog" + :tabindex "-1"} + [:div {:class "modal-dialog modal-lg"} + [:div {:class "modal-content"} + [:div {:class "modal-header"} + [:h5 [:span {:id "modify-title"}]] + [:button {:type "button" + :class "close" + :data-dismiss "modal"} + "×"]] + [:div {:id "modify-body" + :class "modal-body" + :style "height: 450px;"}] + [:div {:class "modal-footer"} + [:button {:type "submit" + :class "btn btn-danger btn-default" + :data-dismiss "modal"} + [:span {:class "glyphicon glyphicon-remove"}] + "Cancel"]]]]]) + +(defn handler-resume [response] + (let [jsonobj (js->clj (js/JSON.parse response))] + (notifications jsonobj) + (dommy/set-html! (dommy/sel1 :#body) (template-resume jsonobj)) + (render-resume-view))) + +(defn render-resume [] + (GET "/resume/resume" {:handler handler-resume})) + +;; resume-view + +(hiccups/defhtml template-resume-view [jsonobj] + [:div {:style "text-align: right"} + [:img {:src "/static/images/add.png" + :style "cursor:pointer; cursor:hand" + :onclick (str (namespace ::x) ".on_resume_add_clicked()")}]] + [:table {:class "table table-striped table-hover table-sm"} + [:thead + [:tr + [:th {:scope "col"} "Name"] + [:th {:scope "col"} "Mod"] + [:th {:scope "col"} "Del"]]] + [:tbody + (for [resume (get jsonobj "resumes")] + [:tr + [:td (get resume "name")] + [:td {:width "30"} + [:img {:src "/static/images/modify.png" + :onclick (str (namespace ::x) ".on_resume_modify_clicked(" (get resume "id") ")")}]] + [:td {:width "30"} + [:img {:src "/static/images/delete.png" + :onclick (str (namespace ::x) ".on_resume_delete_clicked(" (get resume "id") ", '" (get resume "name") "')")}]]])]]) + +(defn handler-resume-view [response] + (let [jsonobj (js->clj (js/JSON.parse response))] + (dommy/set-html! (dommy/sel1 :#content) (template-resume-view jsonobj)))) + +(defn render-resume-view [] + (GET "/resume/resume/view" {:handler handler-resume-view})) + +;; resume-add + +(defn on-resume-add-clicked [] + (render-resume-add)) + +(hiccups/defhtml template-resume-add [jsonobj] + (ck-form/template-generic-form (get jsonobj "form") (namespace ::x))) + +(defn handler-resume-add [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-resume-add jsonobj)) + (.modal (jquery "#modify")))) + +(defn render-resume-add [] + (POST "/resume/resume/add" {:handler handler-resume-add})) + +;; resume-add-submit + +(defn on-resume-add-submit-clicked [] + (when (-> (jquery "#resume-add-form") + (.get "0") + (.checkValidity)) + (.modal (jquery "#modify") "hide") + (render-resume-add-submit))) + +(defn handler-resume-add-submit [response] + (let [jsonobj (js->clj (js/JSON.parse response))] + (auth-notifications jsonobj) + (on-menu-clicked "/resume/resume"))) + +(defn render-resume-add-submit [] + (POST "/resume/resume/add/submit" + {:format :raw + :params {:name (dommy/value (dommy/sel1 :#name))} + :handler handler-resume-add-submit})) + +;; resume-modify + +(defn on-resume-modify-clicked [id] + (render-resume-modify id)) + +(hiccups/defhtml template-resume-modify [jsonobj] + (ck-form/template-generic-form (get jsonobj "form") (namespace ::x))) + +(defn handler-resume-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-resume-modify jsonobj)) + (.modal (jquery "#modify")))) + +(defn render-resume-modify [id] + (POST "/resume/resume/modify" + {:format :raw + :params {:id id} + :handler handler-resume-modify})) + +;; resume-modify-submit + +(defn on-resume-modify-submit-clicked [] + (when (-> (jquery "#resume-modify-form") + (.get "0") + (.checkValidity)) + (.modal (jquery "#modify") "hide") + (render-resume-modify-submit))) + +(defn handler-resume-modify-submit [response] + (let [jsonobj (js->clj (js/JSON.parse response))] + (auth-notifications jsonobj) + (on-menu-clicked "/resume/resume"))) + +(defn render-resume-modify-submit [] + (POST "/resume/resume/modify/submit" + {:format :raw + :params {:id (dommy/value (dommy/sel1 :#id)) + :name (dommy/value (dommy/sel1 :#name))} + :handler handler-resume-modify-submit})) + +;; resume-delete + +(defn on-resume-delete-clicked [id name] + (when (js/confirm (str "Are you sure you want to delete " name "? This action cannot be undone.")) + (render-resume-delete id))) + +(defn handler-resume-delete [response] + (let [jsonobj (js->clj (js/JSON.parse response))] + (auth-notifications jsonobj) + (on-menu-clicked "/resume/resume"))) + +(defn render-resume-delete [id] + (DELETE (str "/resume/resume/delete/" id) + {:format :raw + :handler handler-resume-delete})) + +;; contactinfo + +(hiccups/defhtml template-contactinfo [jsonobj] + [:h3 {:style "text-align: center"} (get jsonobj "title")] + [:div {:id "content"}] + [:div {:id "modify" + :class "modal fade" + :role "dialog" + :tabindex "-1"} + [:div {:class "modal-dialog modal-lg"} + [:div {:class "modal-content"} + [:div {:class "modal-header"} + [:h5 [:span {:id "modify-title"}]] + [:button {:type "button" + :class "close" + :data-dismiss "modal"} + "×"]] + [:div {:id "modify-body" + :class "modal-body" + :style "height: 450px;"}] + [:div {:class "modal-footer"} + [:button {:type "submit" + :class "btn btn-danger btn-default" + :data-dismiss "modal"} + [:span {:class "glyphicon glyphicon-remove"}] + "Cancel"]]]]]) + +(defn handler-contactinfo [response] + (let [jsonobj (js->clj (js/JSON.parse response))] + (notifications jsonobj) + (dommy/set-html! (dommy/sel1 :#body) (template-contactinfo jsonobj)) + (render-contactinfo-view))) + +(defn render-contactinfo [] + (GET "/resume/contactinfo" {:handler handler-contactinfo})) + +;; contactinfo-view + +(hiccups/defhtml template-contactinfo-view [jsonobj] + [:div {:style "text-align: right"} + [:img {:src "/static/images/add.png" + :style "cursor:pointer; cursor:hand" + :onclick (str (namespace ::x) ".on_contactinfo_add_clicked()")}]] + [:table {:class "table table-striped table-hover table-sm"} + [:thead + [:tr + [:th {:scope "col"} "Address"] + [:th {:scope "col"} "City"] + [:th {:scope "col"} "State"] + [:th {:scope "col"} "Phone"] + [:th {:scope "col"} "Email"] + [:th {:scope "col"} "URL"] + [:th {:scope "col"} "VISA Status"] + [:th {:scope "col"} "Mod"] + [:th {:scope "col"} "Del"]]] + [:tbody + (for [contactinfo (get jsonobj "components")] + [:tr + [:td (get contactinfo "address")] + [:td (get contactinfo "city")] + [:td (get contactinfo "state_abbr")] + [:td (get contactinfo "phone")] + [:td (get contactinfo "email")] + [:td (get contactinfo "url")] + [:td (get contactinfo "visastatus")] + [:td {:width "30"} + [:img {:src "/static/images/modify.png" + :onclick (str (namespace ::x) ".on_contactinfo_modify_clicked(" (get contactinfo "id") ")")}]] + [:td {:width "30"} + [:img {:src "/static/images/delete.png" + :onclick (str (namespace ::x) ".on_contactinfo_delete_clicked(" (get contactinfo "id") ", '" (str (get contactinfo "address") ", " (get contactinfo "city") " " (get contactinfo "state_abbr")) "')")}]]])]]) + +(defn handler-contactinfo-view [response] + (let [jsonobj (js->clj (js/JSON.parse response))] + (dommy/set-html! (dommy/sel1 :#content) (template-contactinfo-view jsonobj)))) + +(defn render-contactinfo-view [] + (GET "/resume/contactinfo/view" {:handler handler-contactinfo-view})) + +;; contactinfo-add + +(defn on-contactinfo-add-clicked [] + (render-contactinfo-add)) + +(hiccups/defhtml template-contactinfo-add [jsonobj] + (ck-form/template-generic-form (get jsonobj "form") (namespace ::x))) + +(defn handler-contactinfo-add [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-contactinfo-add jsonobj)) + (.modal (jquery "#modify")))) + +(defn render-contactinfo-add [] + (POST "/resume/contactinfo/add" {:handler handler-contactinfo-add})) + +;; contactinfo-add-submit + +(defn on-contactinfo-add-submit-clicked [] + (when (-> (jquery "#contactinfo-add-form") + (.get "0") + (.checkValidity)) + (.modal (jquery "#modify") "hide") + (render-contactinfo-add-submit))) + +(defn handler-contactinfo-add-submit [response] + (let [jsonobj (js->clj (js/JSON.parse response))] + (auth-notifications jsonobj) + (on-menu-clicked "/resume/contactinfo"))) + +(defn render-contactinfo-add-submit [] + (POST "/resume/contactinfo/add/submit" + {:format :raw + :params {:address (dommy/value (dommy/sel1 :#address)) + :city (dommy/value (dommy/sel1 :#city)) + :state_id (dommy/value (dommy/sel1 :#state_id)) + :phone (dommy/value (dommy/sel1 :#phone)) + :email (dommy/value (dommy/sel1 :#email)) + :url (dommy/value (dommy/sel1 :#url)) + :visastatus_id (dommy/value (dommy/sel1 :#visastatus_id))} + :handler handler-contactinfo-add-submit})) + +;; contactinfo-modify + +(defn on-contactinfo-modify-clicked [id] + (render-contactinfo-modify id)) + +(hiccups/defhtml template-contactinfo-modify [jsonobj] + (ck-form/template-generic-form (get jsonobj "form") (namespace ::x))) + +(defn handler-contactinfo-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-contactinfo-modify jsonobj)) + (.modal (jquery "#modify")))) + +(defn render-contactinfo-modify [id] + (POST "/resume/contactinfo/modify" + {:format :raw + :params {:id id} + :handler handler-contactinfo-modify})) + +;; contactinfo-modify-submit + +(defn on-contactinfo-modify-submit-clicked [id] + (when (-> (jquery "#contactinfo-modify-form") + (.get "0") + (.checkValidity)) + (.modal (jquery "#modify") "hide") + (render-contactinfo-modify-submit id))) + +(defn handler-contactinfo-modify-submit [response] + (let [jsonobj (js->clj (js/JSON.parse response))] + (auth-notifications jsonobj) + (on-menu-clicked "/resume/contactinfo"))) + +(defn render-contactinfo-modify-submit [id] + (POST "/resume/contactinfo/modify/submit" + {:format :raw + :params {:id id + :address (dommy/value (dommy/sel1 :#address)) + :city (dommy/value (dommy/sel1 :#city)) + :state_id (dommy/value (dommy/sel1 :#state_id)) + :phone (dommy/value (dommy/sel1 :#phone)) + :email (dommy/value (dommy/sel1 :#email)) + :url (dommy/value (dommy/sel1 :#url)) + :visastatus_id (dommy/value (dommy/sel1 :#visastatus_id))} + :handler handler-contactinfo-modify-submit})) + +;; contactinfo-delete + +(defn on-contactinfo-delete-clicked [id name] + (when (js/confirm (str "Are you sure you want to delete " name "? This action cannot be undone.")) + (render-contactinfo-delete id))) + +(defn handler-contactinfo-delete [response] + (let [jsonobj (js->clj (js/JSON.parse response))] + (auth-notifications jsonobj) + (on-menu-clicked "/resume/contactinfo"))) + +(defn render-contactinfo-delete [id] + (DELETE (str "/resume/contactinfo/delete/" id) + {:format :raw + :handler handler-contactinfo-delete})) + +;; education + +(hiccups/defhtml template-education [jsonobj] + [:h3 {:style "text-align: center"} (get jsonobj "title")] + [:div {:id "content"}] + [:div {:id "modify" + :class "modal fade" + :role "dialog" + :tabindex "-1"} + [:div {:class "modal-dialog modal-lg"} + [:div {:class "modal-content"} + [:div {:class "modal-header"} + [:h5 [:span {:id "modify-title"}]] + [:button {:type "button" + :class "close" + :data-dismiss "modal"} + "×"]] + [:div {:id "modify-body" + :class "modal-body" + :style "height: 450px;"}] + [:div {:class "modal-footer"} + [:button {:type "submit" + :class "btn btn-danger btn-default" + :data-dismiss "modal"} + [:span {:class "glyphicon glyphicon-remove"}] + "Cancel"]]]]]) + +(defn handler-education [response] + (let [jsonobj (js->clj (js/JSON.parse response))] + (notifications jsonobj) + (dommy/set-html! (dommy/sel1 :#body) (template-education jsonobj)) + (render-education-view))) + +(defn render-education [] + (GET "/resume/education" {:handler handler-education})) + +;; education-view + +(hiccups/defhtml template-education-view [jsonobj] + [:div {:style "text-align: right"} + [:img {:src "/static/images/add.png" + :style "cursor:pointer; cursor:hand" + :onclick (str (namespace ::x) ".on_education_add_clicked()")}]] + [:table {:class "table table-striped table-hover table-sm"} + [:thead + [:tr + [:th {:scope "col"} "School"] + [:th {:scope "col"} "Start Date"] + [:th {:scope "col"} "End Date"] + [:th {:scope "col"} "Major"] + [:th {:scope "col"} "Minor"] + [:th {:scope "col"} "Degree"] + [:th {:scope "col"} "Progress"] + [:th {:scope "col"} "Mod"] + [:th {:scope "col"} "Del"]]] + [:tbody + (for [education (get jsonobj "components")] + [:tr + [:td (get education "school")] + [:td (get education "start_date")] + [:td (get education "end_date")] + [:td (get education "major")] + [:td (get education "minor")] + [:td (get education "degree")] + [:td (get education "progress")] + [:td {:width "30"} + [:img {:src "/static/images/modify.png" + :onclick (str (namespace ::x) ".on_education_modify_clicked(" (get education "id") ")")}]] + [:td {:width "30"} + [:img {:src "/static/images/delete.png" + :onclick (str (namespace ::x) ".on_education_delete_clicked(" (get education "id") ", '" (str (get education "school") ", " (get education "major")) "')")}]]])]]) + +(defn handler-education-view [response] + (let [jsonobj (js->clj (js/JSON.parse response))] + (dommy/set-html! (dommy/sel1 :#content) (template-education-view jsonobj)))) + +(defn render-education-view [] + (GET "/resume/education/view" {:handler handler-education-view})) + +;; education-add + +(defn on-education-add-clicked [] + (render-education-add)) + +(hiccups/defhtml template-education-add [jsonobj] + (ck-form/template-generic-form (get jsonobj "form") (namespace ::x))) + +(defn handler-education-add [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-education-add jsonobj)) + (.modal (jquery "#modify")))) + +(defn render-education-add [] + (POST "/resume/education/add" {:handler handler-education-add})) + +;; education-add-submit + +(defn on-education-add-submit-clicked [] + (when (-> (jquery "#education-add-form") + (.get "0") + (.checkValidity)) + (.modal (jquery "#modify") "hide") + (render-education-add-submit))) + +(defn handler-education-add-submit [response] + (let [jsonobj (js->clj (js/JSON.parse response))] + (auth-notifications jsonobj) + (on-menu-clicked "/resume/education"))) + +(defn render-education-add-submit [] + (POST "/resume/education/add/submit" + {:format :raw + :params {:school (dommy/value (dommy/sel1 :#school)) + :major (dommy/value (dommy/sel1 :#major)) + :minor (dommy/value (dommy/sel1 :#minor)) + :degree (dommy/value (dommy/sel1 :#degree)) + :progress (dommy/value (dommy/sel1 :#progress)) + :start_date (dommy/value (dommy/sel1 :#start_date)) + :end_date (dommy/value (dommy/sel1 :#end_date))} + :handler handler-education-add-submit})) + +;; education-modify + +(defn on-education-modify-clicked [id] + (render-education-modify id)) + +(hiccups/defhtml template-education-modify [jsonobj] + (ck-form/template-generic-form (get jsonobj "form") (namespace ::x))) + +(defn handler-education-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-education-modify jsonobj)) + (.modal (jquery "#modify")))) + +(defn render-education-modify [id] + (POST "/resume/education/modify" + {:format :raw + :params {:id id} + :handler handler-education-modify})) + +;; education-modify-submit + +(defn on-education-modify-submit-clicked [id] + (when (-> (jquery "#education-modify-form") + (.get "0") + (.checkValidity)) + (.modal (jquery "#modify") "hide") + (render-education-modify-submit id))) + +(defn handler-education-modify-submit [response] + (let [jsonobj (js->clj (js/JSON.parse response))] + (auth-notifications jsonobj) + (on-menu-clicked "/resume/education"))) + +(defn render-education-modify-submit [id] + (POST "/resume/education/modify/submit" + {:format :raw + :params {:id id + :school (dommy/value (dommy/sel1 :#school)) + :major (dommy/value (dommy/sel1 :#major)) + :minor (dommy/value (dommy/sel1 :#minor)) + :degree (dommy/value (dommy/sel1 :#degree)) + :progress (dommy/value (dommy/sel1 :#progress)) + :start_date (dommy/value (dommy/sel1 :#start_date)) + :end_date (dommy/value (dommy/sel1 :#end_date))} + :handler handler-education-modify-submit})) + +;; education-delete + +(defn on-education-delete-clicked [id name] + (when (js/confirm (str "Are you sure you want to delete " name "? This action cannot be undone.")) + (render-education-delete id))) + +(defn handler-education-delete [response] + (let [jsonobj (js->clj (js/JSON.parse response))] + (auth-notifications jsonobj) + (on-menu-clicked "/resume/education"))) + +(defn render-education-delete [id] + (DELETE (str "/resume/education/delete/" id) + {:format :raw + :handler handler-education-delete})) + +;; language + +(hiccups/defhtml template-language [jsonobj] + [:h3 {:style "text-align: center"} (get jsonobj "title")] + [:div {:id "content"}] + [:div {:id "modify" + :class "modal fade" + :role "dialog" + :tabindex "-1"} + [:div {:class "modal-dialog modal-lg"} + [:div {:class "modal-content"} + [:div {:class "modal-header"} + [:h5 [:span {:id "modify-title"}]] + [:button {:type "button" + :class "close" + :data-dismiss "modal"} + "×"]] + [:div {:id "modify-body" + :class "modal-body" + :style "height: 450px;"}] + [:div {:class "modal-footer"} + [:button {:type "submit" + :class "btn btn-danger btn-default" + :data-dismiss "modal"} + [:span {:class "glyphicon glyphicon-remove"}] + "Cancel"]]]]]) + +(defn handler-language [response] + (let [jsonobj (js->clj (js/JSON.parse response))] + (notifications jsonobj) + (dommy/set-html! (dommy/sel1 :#body) (template-language jsonobj)) + (render-language-view))) + +(defn render-language [] + (GET "/resume/language" {:handler handler-language})) + +;; language-view + +(hiccups/defhtml template-language-view [jsonobj] + [:div {:style "text-align: right"} + [:img {:src "/static/images/add.png" + :style "cursor:pointer; cursor:hand" + :onclick (str (namespace ::x) ".on_language_add_clicked()")}]] + [:table {:class "table table-striped table-hover table-sm"} + [:thead + [:tr + [:th {:scope "col"} "Name"] + [:th {:scope "col"} "Understanding Listening"] + [:th {:scope "col"} "Understanding Reading"] + [:th {:scope "col"} "Speaking Interaction"] + [:th {:scope "col"} "Speaking Production"] + [:th {:scope "col"} "Writing"] + [:th {:scope "col"} "Mod"] + [:th {:scope "col"} "Del"]]] + [:tbody + (for [language (get jsonobj "components")] + [:tr + [:td (get language "name")] + [:td (get language "understanding_listening")] + [:td (get language "understanding_reading")] + [:td (get language "speaking_interaction")] + [:td (get language "speaking_production")] + [:td (get language "writing")] + [:td {:width "30"} + [:img {:src "/static/images/modify.png" + :onclick (str (namespace ::x) ".on_language_modify_clicked(" (get language "id") ")")}]] + [:td {:width "30"} + [:img {:src "/static/images/delete.png" + :onclick (str (namespace ::x) ".on_language_delete_clicked(" (get language "id") ", '" (get language "name") "')")}]]])]]) + +(defn handler-language-view [response] + (let [jsonobj (js->clj (js/JSON.parse response))] + (dommy/set-html! (dommy/sel1 :#content) (template-language-view jsonobj)))) + +(defn render-language-view [] + (GET "/resume/language/view" {:handler handler-language-view})) + +;; language-add + +(defn on-language-add-clicked [] + (render-language-add)) + +(hiccups/defhtml template-language-add [jsonobj] + (ck-form/template-generic-form (get jsonobj "form") (namespace ::x))) + +(defn handler-language-add [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-language-add jsonobj)) + (.modal (jquery "#modify")))) + +(defn render-language-add [] + (POST "/resume/language/add" {:handler handler-language-add})) + +;; language-add-submit + +(defn on-language-add-submit-clicked [] + (when (-> (jquery "#language-add-form") + (.get "0") + (.checkValidity)) + (.modal (jquery "#modify") "hide") + (render-language-add-submit))) + +(defn handler-language-add-submit [response] + (let [jsonobj (js->clj (js/JSON.parse response))] + (auth-notifications jsonobj) + (on-menu-clicked "/resume/language"))) + +(defn render-language-add-submit [] + (POST "/resume/language/add/submit" + {:format :raw + :params {:name (dommy/value (dommy/sel1 :#name)) + :understanding_listening (dommy/value (dommy/sel1 :#understanding_listening)) + :understanding_reading (dommy/value (dommy/sel1 :#understanding_reading)) + :speaking_interaction (dommy/value (dommy/sel1 :#speaking_interaction)) + :speaking_production (dommy/value (dommy/sel1 :#speaking_production)) + :writing (dommy/value (dommy/sel1 :#writing))} + :handler handler-language-add-submit})) + +;; language-modify + +(defn on-language-modify-clicked [id] + (render-language-modify id)) + +(hiccups/defhtml template-language-modify [jsonobj] + (ck-form/template-generic-form (get jsonobj "form") (namespace ::x))) + +(defn handler-language-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-language-modify jsonobj)) + (.modal (jquery "#modify")))) + +(defn render-language-modify [id] + (POST "/resume/language/modify" + {:format :raw + :params {:id id} + :handler handler-language-modify})) + +;; language-modify-submit + +(defn on-language-modify-submit-clicked [id] + (when (-> (jquery "#language-modify-form") + (.get "0") + (.checkValidity)) + (.modal (jquery "#modify") "hide") + (render-language-modify-submit id))) + +(defn handler-language-modify-submit [response] + (let [jsonobj (js->clj (js/JSON.parse response))] + (auth-notifications jsonobj) + (on-menu-clicked "/resume/language"))) + +(defn render-language-modify-submit [id] + (POST "/resume/language/modify/submit" + {:format :raw + :params {:id id + :name (dommy/value (dommy/sel1 :#name)) + :understanding_listening (dommy/value (dommy/sel1 :#understanding_listening)) + :understanding_reading (dommy/value (dommy/sel1 :#understanding_reading)) + :speaking_interaction (dommy/value (dommy/sel1 :#speaking_interaction)) + :speaking_production (dommy/value (dommy/sel1 :#speaking_production)) + :writing (dommy/value (dommy/sel1 :#writing))} + :handler handler-language-modify-submit})) + +;; language-delete + +(defn on-language-delete-clicked [id name] + (when (js/confirm (str "Are you sure you want to delete " name "? This action cannot be undone.")) + (render-language-delete id))) + +(defn handler-language-delete [response] + (let [jsonobj (js->clj (js/JSON.parse response))] + (auth-notifications jsonobj) + (on-menu-clicked "/resume/language"))) + +(defn render-language-delete [id] + (DELETE (str "/resume/language/delete/" id) + {:format :raw + :handler handler-language-delete})) + +;; skill + +(hiccups/defhtml template-skill [jsonobj] + [:h3 {:style "text-align: center"} (get jsonobj "title")] + [:div {:id "content"}] + [:div {:id "modify" + :class "modal fade" + :role "dialog" + :tabindex "-1"} + [:div {:class "modal-dialog modal-lg"} + [:div {:class "modal-content"} + [:div {:class "modal-header"} + [:h5 [:span {:id "modify-title"}]] + [:button {:type "button" + :class "close" + :data-dismiss "modal"} + "×"]] + [:div {:id "modify-body" + :class "modal-body" + :style "height: 450px;"}] + [:div {:class "modal-footer"} + [:button {:type "submit" + :class "btn btn-danger btn-default" + :data-dismiss "modal"} + [:span {:class "glyphicon glyphicon-remove"}] + "Cancel"]]]]]) + +(defn handler-skill [response] + (let [jsonobj (js->clj (js/JSON.parse response))] + (notifications jsonobj) + (dommy/set-html! (dommy/sel1 :#body) (template-skill jsonobj)) + (render-skill-view))) + +(defn render-skill [] + (GET "/resume/skill" {:handler handler-skill})) + +;; skill-view + +(hiccups/defhtml template-skill-view [jsonobj] + [:div {:style "text-align: right"} + [:img {:src "/static/images/add.png" + :style "cursor:pointer; cursor:hand" + :onclick (str (namespace ::x) ".on_skill_add_clicked()")}]] + [:table {:class "table table-striped table-hover table-sm"} + [:thead + [:tr + [:th {:scope "col"} "Skill"] + [:th {:scope "col"} "Mod"] + [:th {:scope "col"} "Del"]]] + [:tbody + (for [skill (get jsonobj "components")] + [:tr + [:td (get skill "skill")] + [:td {:width "30"} + [:img {:src "/static/images/modify.png" + :onclick (str (namespace ::x) ".on_skill_modify_clicked(" (get skill "id") ")")}]] + [:td {:width "30"} + [:img {:src "/static/images/delete.png" + :onclick (str (namespace ::x) ".on_skill_delete_clicked(" (get skill "id") ", '" (get skill "skill") "')")}]]])]]) + +(defn handler-skill-view [response] + (let [jsonobj (js->clj (js/JSON.parse response))] + (dommy/set-html! (dommy/sel1 :#content) (template-skill-view jsonobj)))) + +(defn render-skill-view [] + (GET "/resume/skill/view" {:handler handler-skill-view})) + +;; skill-add + +(defn on-skill-add-clicked [] + (render-skill-add)) + +(hiccups/defhtml template-skill-add [jsonobj] + (ck-form/template-generic-form (get jsonobj "form") (namespace ::x))) + +(defn handler-skill-add [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-skill-add jsonobj)) + (.modal (jquery "#modify")))) + +(defn render-skill-add [] + (POST "/resume/skill/add" {:handler handler-skill-add})) + +;; skill-add-submit + +(defn on-skill-add-submit-clicked [] + (when (-> (jquery "#skill-add-form") + (.get "0") + (.checkValidity)) + (.modal (jquery "#modify") "hide") + (render-skill-add-submit))) + +(defn handler-skill-add-submit [response] + (let [jsonobj (js->clj (js/JSON.parse response))] + (auth-notifications jsonobj) + (on-menu-clicked "/resume/skill"))) + +(defn render-skill-add-submit [] + (POST "/resume/skill/add/submit" + {:format :raw + :params {:skill (dommy/value (dommy/sel1 :#skill))} + :handler handler-skill-add-submit})) + +;; skill-modify + +(defn on-skill-modify-clicked [id] + (render-skill-modify id)) + +(hiccups/defhtml template-skill-modify [jsonobj] + (ck-form/template-generic-form (get jsonobj "form") (namespace ::x))) + +(defn handler-skill-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-skill-modify jsonobj)) + (.modal (jquery "#modify")))) + +(defn render-skill-modify [id] + (POST "/resume/skill/modify" + {:format :raw + :params {:id id} + :handler handler-skill-modify})) + +;; skill-modify-submit + +(defn on-skill-modify-submit-clicked [id] + (when (-> (jquery "#skill-modify-form") + (.get "0") + (.checkValidity)) + (.modal (jquery "#modify") "hide") + (render-skill-modify-submit id))) + +(defn handler-skill-modify-submit [response] + (let [jsonobj (js->clj (js/JSON.parse response))] + (auth-notifications jsonobj) + (on-menu-clicked "/resume/skill"))) + +(defn render-skill-modify-submit [id] + (POST "/resume/skill/modify/submit" + {:format :raw + :params {:id id + :skill (dommy/value (dommy/sel1 :#skill))} + :handler handler-skill-modify-submit})) + +;; skill-delete + +(defn on-skill-delete-clicked [id name] + (when (js/confirm (str "Are you sure you want to delete " name "? This action cannot be undone.")) + (render-skill-delete id))) + +(defn handler-skill-delete [response] + (let [jsonobj (js->clj (js/JSON.parse response))] + (auth-notifications jsonobj) + (on-menu-clicked "/resume/skill"))) + +(defn render-skill-delete [id] + (DELETE (str "/resume/skill/delete/" id) + {:format :raw + :handler handler-skill-delete})) + +;; location + +(defn on-menu-clicked [handler] + (reset-location handler) + (render-menu) + (cond (= handler "/home") (render-home) + (= handler "/login") (render-login) + (= handler "/logout") (render-logout) + (= handler "/profile") (render-profile) + (= handler "/password") (render-password) + (= handler "/contact-us") (render-contact-us) + (= handler "/messages") (render-messages) + (= handler "/users") (render-users) + (= handler "/resume/resume") (render-resume) + (= handler "/resume/contactinfo") (render-contactinfo) + (= handler "/resume/education") (render-education) + (= handler "/resume/language") (render-language) + (= handler "/resume/skill") (render-skill))) + +(defn handler-location [response] + (let [jsonobj (js->clj (js/JSON.parse response))] + (on-menu-clicked (get jsonobj "location")) + (notifications jsonobj))) + +(defn goto-location [location] + (POST "/location" + {:format :raw + :params {:location location} + :handler handler-location})) + +(defn reset-app [] + (set! (.-location js/document) "/")) + +(defn goto-register [hash] + (reset-location "/users/register") + (render-menu) + (render-users-register hash)) diff --git a/lisp/webapps/resume/clojurescript/resume/src/resume/util.clj b/lisp/webapps/resume/clojurescript/resume/src/resume/util.clj new file mode 100644 index 0000000..16276b3 --- /dev/null +++ b/lisp/webapps/resume/clojurescript/resume/src/resume/util.clj @@ -0,0 +1,92 @@ +(ns resume.util) + +(defmacro define-resume-component [component] + `(do + (declare ~(symbol (str "template-" component))) + (declare ~(symbol (str "handler-" component))) + (declare ~(symbol (str "render-" component))) + (declare ~(symbol (str "template-" component "-view"))) + (declare ~(symbol (str "handler-" component "-view"))) + (declare ~(symbol (str "render-" component "-view"))) + (declare ~(symbol (str "on-" component "-add-clicked"))) + (declare ~(symbol (str "template-" component "-add"))) + (declare ~(symbol (str "handler-" component "-add"))) + (declare ~(symbol (str "render-" component "-add"))) + (declare ~(symbol (str "on-" component "-add-submit-clicked"))) + (declare ~(symbol (str "handler-" component "-add-submit"))) + (declare ~(symbol (str "render-" component "-add-submit"))) + (declare ~(symbol (str "on-" component "-modify-clicked"))) + (declare ~(symbol (str "template-" component "-modify"))) + (declare ~(symbol (str "handler-" component "-modify"))) + (declare ~(symbol (str "render-" component "-modify"))) + (declare ~(symbol (str "on-" component "-modify-submit-clicked"))) + (declare ~(symbol (str "handler-" component "-modify-submit"))) + (declare ~(symbol (str "render-" component "-modify-submit"))) + (declare ~(symbol (str "on-" component" -delete-clicked"))) + (declare ~(symbol (str "handler-" component "-delete"))) + (declare ~(symbol (str "render-" component "-delete"))) + + (defn ~(symbol (str "handler-" component)) [response] + (let [jsonobj (js->clj (js/JSON.parse response))] + (notifications jsonobj) + (dommy/set-html! (dommy/sel1 :#body) (template-resume jsonobj)) + (~(symbol (str "template-" component "-view"))))) + + (defn ~(symbol (str "render-" component)) [] + (GET ~(str "/resume/" component) {:handler handler-resume})) + + (hiccups/defhtml ~(symbol (str "template-" component "-view")) [jsonobj] + [:div {:style "text-align: right"} + [:img {:src "/static/images/add.png" + :style "cursor:pointer; cursor:hand" + :onclick (str (namespace ::x) ".on_contactinfo_add_clicked()")}]] + (generic-table ~component jsonobj)) + + (defn ~(symbol (str "handler-" component "-view")) [response] + (let [jsonobj (js->clj (js/JSON.parse response))] + (dommy/set-html! (dommy/sel1 :#content) (template-contactinfo-view jsonobj)))) + + (defn ~(symbol (str "render-" component "-view")) [] + (GET ~(str "/resume/" component "/view") + {:handler ~(symbol (str "handler-" component "-view"))})) + + (defn ~(symbol (str "on-" component "-add-clicked")) [] + (~(symbol (str "render-" component "-add")))) + + (hiccups/defhtml template-component-add [jsonobj] + (ck-form/template-generic-form (get jsonobj "form") (namespace ::x))) + + (defn ~(symbol (str "handler-" component "-add")) [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) (generic-component-add jsonobj)) + (.modal (jquery "#modify")))) + + (defn ~(symbol (str "render-" component "-add")) [] + (POST ~(str "/resume/" component "/add") + {:handler ~(symbol (str "handler-" component "-add"))})) + + (defn ~(symbol (str "on-" component "-add-submit-clicked")) [] + (when (-> (jquery "#contactinfo-add-form") + (.get "0") + (.checkValidity)) + (.modal (jquery "#modify") "hide") + (~(symbol (str "render-" component "-add-submit"))))) + + (defn ~(symbol (str "handler-" component "-add-submit")) [response] + (let [jsonobj (js->clj (js/JSON.parse response))] + (auth-notifications jsonobj) + (on-menu-clicked ~(str "/resume/" component)))) + + (defn ~(symbol (str "render-" component "-add-submit")) [] + (POST ~(str "/resume/" component "/add/submit") + {:format :raw + :params {:address (dommy/value (dommy/sel1 :#address)) + :city (dommy/value (dommy/sel1 :#city)) + :state_id (dommy/value (dommy/sel1 :#state_id)) + :phone (dommy/value (dommy/sel1 :#phone)) + :email (dommy/value (dommy/sel1 :#email)) + :url (dommy/value (dommy/sel1 :#url)) + :visastatus_id (dommy/value (dommy/sel1 :#visastatus_id))} + :handler ~(symbol (str "handler-" component "-add-submit"))})))) diff --git a/lisp/webapps/resume/clojurescript/resume/src/resume/util.cljs b/lisp/webapps/resume/clojurescript/resume/src/resume/util.cljs new file mode 100644 index 0000000..b9d75a3 --- /dev/null +++ b/lisp/webapps/resume/clojurescript/resume/src/resume/util.cljs @@ -0,0 +1,2 @@ +(ns resume.util + (:require-macros [resume.util])) diff --git a/lisp/webapps/resume/site.lisp b/lisp/webapps/resume/site.lisp index 1a1c7a7..bc2d3b0 100644 --- a/lisp/webapps/resume/site.lisp +++ b/lisp/webapps/resume/site.lisp @@ -165,10 +165,10 @@ (define-endpoint ("/users/modify/submit" :method :post) (&post (id :parameter-type 'integer) (role_groups :parameter-type 'string) (username :parameter-type 'string) (first_name :parameter-type 'string) (last_name :parameter-type 'string) (email :parameter-type 'string) (phone :parameter-type 'string)) .users-modify-submit) (define-endpoint ("/users/toggle-active" :method :post) (&post (id :parameter-type 'integer)) .users-toggle-active) (define-endpoint ("/users/delete/:id" :method :delete) (&path (id 'integer)) .users-delete) -(define-endpoint ("/resume" :method :get) () .resume) -(define-endpoint ("/resume/view" :method :get) () .resume-view) -(define-endpoint ("/resume/add" :method :post) () .resume-add) -(define-endpoint ("/resume/add/submit" :method :post) (&post (name :parameter-type 'string)) .resume-add-submit) -(define-endpoint ("/resume/modify" :method :post) (&post (id :parameter-type 'integer)) .resume-modify) -(define-endpoint ("/resume/modify/submit" :method :post) (&post (id :parameter-type 'integer) (name :parameter-type 'string)) .resume-modify-submit) -(define-endpoint ("/resume/delete/:id" :method :delete) (&path (id 'integer)) .resume-delete) +(define-endpoint ("/resume/resume" :method :get) () .resume) +(define-endpoint ("/resume/resume/view" :method :get) () .resume-view) +(define-endpoint ("/resume/resume/add" :method :post) () .resume-add) +(define-endpoint ("/resume/resume/add/submit" :method :post) (&post (name :parameter-type 'string)) .resume-add-submit) +(define-endpoint ("/resume/resume/modify" :method :post) (&post (id :parameter-type 'integer)) .resume-modify) +(define-endpoint ("/resume/resume/modify/submit" :method :post) (&post (id :parameter-type 'integer) (name :parameter-type 'string)) .resume-modify-submit) +(define-endpoint ("/resume/resume/delete/:id" :method :delete) (&path (id 'integer)) .resume-delete) -- cgit v1.3