added support
This commit is contained in:
@@ -0,0 +1,2 @@
|
||||
-- 1523724426 DOWN add-vendor-client-relationship
|
||||
drop table vendors_companies;
|
||||
@@ -0,0 +1,8 @@
|
||||
-- 1523724426 UP add-vendor-client-relationship
|
||||
CREATE TABLE vendors_companies (
|
||||
id serial primary key,
|
||||
vendor_id int references vendors(id),
|
||||
company_id int references companies(id),
|
||||
account_id varchar(255),
|
||||
data text
|
||||
);
|
||||
@@ -86,6 +86,21 @@
|
||||
(assoc-in db (concat [:admin :vendor] path)
|
||||
value)))
|
||||
|
||||
(re-frame/reg-event-db
|
||||
::add-relationship
|
||||
(fn [db [_ ]]
|
||||
(-> db
|
||||
(update-in [:admin :vendor :relationships] #(conj (or % [])
|
||||
{:account-number (get-in db [:admin :vendor :new-relationship-account-number])
|
||||
:company-id (get-in db [:admin :vendor :new-relationship-company])}))
|
||||
(update-in [:admin :vendor] dissoc :new-relationship-account-number :new-relationship-company))))
|
||||
|
||||
(re-frame/reg-event-db
|
||||
::remove-relationship
|
||||
(fn [db [_ i]]
|
||||
(-> db
|
||||
(update-in [:admin :vendor :relationships] #(vec (concat (subvec % 0 i) (subvec % (min (count %) (inc i)))))))))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::mounted
|
||||
(fn [{:keys [db]} _]
|
||||
|
||||
@@ -230,6 +230,46 @@
|
||||
:subscription editing-vendor}]]
|
||||
" Never"]]]
|
||||
|
||||
|
||||
[:h2.subtitle "Clients"]
|
||||
|
||||
[horizontal-field
|
||||
nil
|
||||
[:div.control
|
||||
[:div.select.is-expanded
|
||||
[bind-field
|
||||
[:select {:type "select"
|
||||
:field :new-relationship-company
|
||||
:event ::events/change
|
||||
:subscription editing-vendor
|
||||
}
|
||||
(for [company @(re-frame/subscribe [::subs/companies])]
|
||||
[:option {:value (:id company)} (:name company)])]]]]
|
||||
[:div.control
|
||||
[bind-field
|
||||
[:input.input {:type "text"
|
||||
:field :new-relationship-account-number
|
||||
:subscription editing-vendor
|
||||
:event ::events/change
|
||||
:placeholder "Account number"}]]]
|
||||
[:div.control
|
||||
[:button.button.is-primary
|
||||
{:on-click (dispatch-event [::events/add-relationship])}
|
||||
[:span.icon
|
||||
[:i.fa.fa-plus]]]]]
|
||||
[horizontal-field
|
||||
nil
|
||||
[:ul
|
||||
(for [[i r] (map vector (range) (:relationships editing-vendor))]
|
||||
^{:key i}
|
||||
[:li (:account-number r)
|
||||
(:company-id r)
|
||||
[:a
|
||||
{:on-click (dispatch-event [::events/remove-relationship i])}
|
||||
[:span.icon
|
||||
[:i.fa.fa-times]]]]
|
||||
)]]
|
||||
|
||||
|
||||
(when (:saving? editing-vendor) [:div.is-overlay {:style {"backgroundColor" "rgba(150,150,150, 0.5)"}}])]
|
||||
|
||||
|
||||
@@ -37,6 +37,15 @@
|
||||
(defmulti do-bind (fn [_ {:keys [type]}]
|
||||
type))
|
||||
|
||||
(defmethod do-bind "select" [dom {:keys [field subscription event class value spec] :as keys} & rest]
|
||||
(let [keys (assoc keys
|
||||
:on-change (dispatch-value-change [event [field]])
|
||||
:class (str class
|
||||
(when (and spec (not (s/valid? spec (field subscription))))
|
||||
" is-danger")))
|
||||
keys (dissoc keys :field :subscription :event :spec)]
|
||||
(vec (concat [dom keys] rest))))
|
||||
|
||||
|
||||
(defmethod do-bind "radio" [dom {:keys [field subscription event class value spec] :as keys} & rest]
|
||||
(let [keys (assoc keys
|
||||
|
||||
Reference in New Issue
Block a user