Created
July 13, 2016 09:53
-
-
Save robinchew/81cb3c3702f45def46615032a3552013 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn quote-form [{:keys [floor-plan-update-url floor-plan-create-url] :as urls} data-atom history-atom quote-id db-index search-index variant-search-index after-save] | |
(let [a (deref data-atom) | |
q (a :quote) | |
floor-plan-create-update-url (if quote-id floor-plan-update-url floor-plan-create-url) | |
field-errors (a :field-errors) | |
quoted-product-errors ((a :field-errors) "quoted_products") | |
quote-id ((a :quote) "id") | |
pdf-list ((a :quote) "pdfs") | |
client-list (a :clients) | |
staff-list (a :staffs) | |
status-list (a :statuses) | |
packs ((a :quote) "packs") | |
quote-form-fields-with-options (-> quote-form-fields | |
(add-options "status" status-list) | |
(add-options "client" client-list) | |
(add-options "assigned_to" staff-list))] | |
[:form {:id (aget js/window "QUOTE_FORM_ID") | |
:action "" | |
:onsubmit (fn [e] | |
(save-quote urls quote-id data-atom history-atom :after-save after-save) | |
false) | |
:class "quote-form"} | |
[:input {:type "hidden" :name "csrfmiddlewaretoken" :value (cookie/get "csrftoken")}] | |
[:div {:class "form-header"} | |
[:span {:class "edge-button x"}] | |
[:a {:href (floor-plan-create-update-url quote-id) | |
:class "edge-button large id"} | |
[:span {:class "lamp"}] | |
[:span (or quote-id "")]] | |
[:span {:class "edge-button title"}]] | |
[:div {:class "form-horizontal form"} | |
(for [field quote-form-fields-with-options] | |
[:div {:key (str "field-"(:name field)) :class (str "field-row field-" (:name field))} | |
[:label (:name field)] | |
[:div {:class "field"} | |
(render (assoc | |
field | |
:value (q (field :name)) | |
:on-update (fn [value] | |
(swap! data-atom assoc-in [:quote (field :name)] (string-or-int-or-nil value))))) | |
[:ul {:class "errorlist"} | |
(for [error (field-errors (:name field))] | |
[:li error])] ]]) | |
(for [pack (if (not-empty packs) packs [{}])] | |
[:div | |
(pack-input data-atom pack :single-line "name" "Name") | |
(pack-input data-atom pack :multi-line "temp_billee_address" "Bill To") | |
(pack-input data-atom pack :multi-line "temp_shippee_address" "Ship To")])] | |
[:div {:class "formset-bg"} | |
[:div {:class "background-buttons"} | |
[:div {:class "button visibility-menu-button dropper"} | |
[:span {:class "fa fa-eye"}] | |
[:span {:class "fa fa-caret-down"}]] | |
[:ul {:class "visibility-menu-list droppee"} | |
[:li [:input {:type "checkbox"}] [:a {:class "visible"} "Extra Conditions"]] | |
[:li [:input {:type "checkbox"}] [:a {:class "visible"} "Description"]]]] | |
[:div {:class "formset"} | |
(map-indexed | |
(fn [qp-i qp] | |
(let [qp-errors (or (get quoted-product-errors qp-i) {})] | |
[:fieldset {:key (str "qp" qp-i)} | |
[:div {:class "box"} | |
(product-and-variant-field urls data-atom qp-i qp db-index search-index qp-errors) | |
(quoted-product-field data-atom qp-i {:name "quantity" | |
:label "Quantity" | |
:type :single-line | |
:errors (qp-errors "quantity") | |
:value (qp "quantity")} | |
:suffix "-") | |
(quoted-product-field data-atom qp-i {:name "price_tax" | |
:label "Price + Tax" | |
:type :single-line | |
:value (qp "price_tax") | |
:errors (qp-errors "price_tax")} | |
:prefix "$") | |
(quoted-product-field data-atom qp-i {:name "custom" | |
:label "Custom" | |
:type :multi-line | |
:value (qp "custom") | |
:errors (qp-errors "custom")}) | |
[:a { :class "delete" | |
:onclick (fn [e] | |
(swap! data-atom update-in [:quote "quoted_products"] #(dissocv % qp-i)))}]]])) | |
((@data-atom :quote) "quoted_products"))] | |
[:div {:class "background-buttons"} | |
[:button {:id "add_quoted_product" :type "button" :class "button" | |
:onclick (fn [e] | |
(swap! data-atom update-in [:quote "quoted_products"] #(conj % {})) | |
(m/redraw))} | |
[:span {:class "fa fa-plus"}] | |
"Product"]]] | |
[:div {:class "control-buttons second-last"} | |
"Total price + tax = " (reduce + (map #(parse-float (or (% "price_tax") 0)) (-> @data-atom :quote (get "quoted_products"))))] | |
[:div {:class "control-buttons last"} | |
(result-buttons urls data-atom history-atom quote-id pdf-list after-save) | |
(undo-buttons data-atom history-atom)]])) | |
(m/mount element { | |
"view" #(m/build (quote-form | |
urls | |
data-atom | |
history-atom | |
quote-id | |
db-index | |
product-search-index | |
variant-search-index | |
after-save))}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment