Work on getting forms working. Not complete but a considerable advance.
This commit is contained in:
parent
40fc3a99cc
commit
adca71875c
|
@ -61,7 +61,10 @@
|
|||
'defn
|
||||
(symbol n)
|
||||
(vector 'r)
|
||||
(list 'let (vector 'p (list :form-params 'r))
|
||||
(list 'let (vector 'p (list :params 'r)) ;; TODO: we must take key params out of just params,
|
||||
;; but we should take all other params out of form-params - because we need the key to
|
||||
;; load the form in the first place, but just accepting values of other params would
|
||||
;; allow spoofing.
|
||||
(list
|
||||
'l/render
|
||||
(list 'resolve-template (str n ".html"))
|
||||
|
@ -71,10 +74,12 @@
|
|||
(case (:tag f)
|
||||
(:form :page)
|
||||
{:record
|
||||
(list 'if (list 'empty? (list 'remove 'nil? (list 'vals 'p))) []
|
||||
(list
|
||||
(symbol
|
||||
(str "db/get-" (singularise (:name (:attrs e)))))
|
||||
'p)}
|
||||
(symbol "db/*db*")
|
||||
'p))}
|
||||
:list
|
||||
{:records
|
||||
(list
|
||||
|
|
|
@ -366,12 +366,36 @@
|
|||
)
|
||||
|
||||
|
||||
(defn compose-list-search-widget
|
||||
[field entity]
|
||||
(let [property (first
|
||||
(children
|
||||
entity
|
||||
(fn [p] (and (= (:tag p) :property)
|
||||
(= (:name (:attrs p)) (:property (:attrs field)))))))
|
||||
input-type (case (:type (:attrs property))
|
||||
("integer" "real" "money") "number"
|
||||
("date" "timestamp") "date"
|
||||
"time" "time"
|
||||
"text")
|
||||
base-name (:property (:attrs field))
|
||||
search-name (if
|
||||
(= (:type (:attrs property)) "entity")
|
||||
(str base-name "_expanded") base-name)]
|
||||
(hash-map
|
||||
:tag :th
|
||||
:content
|
||||
[{:tag :input
|
||||
:attrs {:id search-name
|
||||
:type input-type
|
||||
:name search-name
|
||||
:value (str "{{ params." search-name " }}")}}])))
|
||||
|
||||
|
||||
|
||||
(defn- list-thead
|
||||
"Return a table head element for the list view for this `list-spec` of this `entity` within
|
||||
this `application`.
|
||||
|
||||
TODO: where entity fields are being shown/searched on, we should be using the user-distinct
|
||||
fields of the far side, rather than key values"
|
||||
this `application`."
|
||||
[list-spec entity application]
|
||||
{:tag :thead
|
||||
:content
|
||||
|
@ -390,24 +414,7 @@
|
|||
vector
|
||||
(concat
|
||||
(map
|
||||
(fn [f]
|
||||
(let [property (first
|
||||
(children
|
||||
entity
|
||||
(fn [p] (and (= (:tag p) :property)
|
||||
(= (:name (:attrs p)) (:property (:attrs f)))))))]
|
||||
(hash-map
|
||||
:tag :th
|
||||
:content
|
||||
[{:tag :input
|
||||
:attrs {:id (:property (:attrs f))
|
||||
:type (case (:type (:attrs property))
|
||||
("integer" "real" "money") "number"
|
||||
("date" "timestamp") "date"
|
||||
"time" "time"
|
||||
"text")
|
||||
:name (:property (:attrs f))
|
||||
:value (str "{{ params." (:property (:attrs f)) " }}")}}])))
|
||||
#(compose-list-search-widget % entity)
|
||||
(fields list-spec))
|
||||
'({:tag :th
|
||||
:content
|
||||
|
@ -425,8 +432,7 @@
|
|||
(s/join
|
||||
"&"
|
||||
(map
|
||||
#(let [n (:name (:attrs %1))]
|
||||
(str n "={{ record." %2 " }}"))
|
||||
#(str %1 "={{ record." %2 " }}")
|
||||
(key-names entity)
|
||||
parameters))))
|
||||
|
||||
|
|
Loading…
Reference in a new issue