(ns wanijo.instance.view.bulk-link-selection (:require [hiccup.form :as hform] [hiccup.core :refer [h]] [wanijo.infra.view :as view] [wanijo.infra.routing :refer [path]] [wanijo.infra.time :refer [prettify-dt]] [wanijo.instance.view.view :refer [req-attrs-headings req-attrs-cells tags-for-search]] [formulare.core :as form] [ring.util.anti-forgery :refer [anti-forgery-field]])) (defn bulk-link-selection [instance forms req] (view/layout :request req :content [[:h1 [:small "Link " (-> instance :schema :name h) " "] (h (:name instance)) [:small " with..."]] (hform/form-to {:class "no-grid"} [:post (path :instance-bulk-link-create instance)] (anti-forgery-field) (hform/hidden-field "source-uuid" (:uuid instance)) (for [{:keys [schema instances]} forms] (list [:h2 "Schema " (h (:name schema))] (let [ident (str "name[" (:uuid schema) "]")] [:div.sub-form [:label {:for ident} "Link name"] [:input {:name ident :id ident}]]) [:table [:thead [:tr [:th "Selection"] [:th "Name"] (req-attrs-headings schema) [:th "Updated"] [:th "Created"]]] [:tbody (for [inst instances] [:tr [:td {:style "text-align: center;"} [:input {:type "checkbox" :name (str "instances[" (:uuid schema) "]") :value (:uuid inst)}]] [:td (h (:name inst)) (tags-for-search inst)] (req-attrs-cells schema inst) [:td (-> inst :updated_at prettify-dt)] [:td (-> inst :created_at prettify-dt)]])]])) [:h2 "Actions"] (hform/submit-button "Create links!"))]))