Work on getting forms to work - almost, but not quite, complete
This commit is contained in:
parent
9d34005f9e
commit
2d7e39ca29
|
@ -259,6 +259,31 @@
|
||||||
:content (apply vector (get-options property form entity application))})))}))
|
:content (apply vector (get-options property form entity application))})))}))
|
||||||
|
|
||||||
|
|
||||||
|
(defn permissions-for
|
||||||
|
[property entity application]
|
||||||
|
(first
|
||||||
|
(remove
|
||||||
|
empty?
|
||||||
|
(list
|
||||||
|
(children-with-tag property :permission)
|
||||||
|
(children-with-tag entity :permission)
|
||||||
|
(children-with-tag application :permission)))))
|
||||||
|
|
||||||
|
|
||||||
|
(defn compose-if-member-of-tag
|
||||||
|
[property entity application writable?]
|
||||||
|
(let
|
||||||
|
[all-permissions (permissions-for property entity application)
|
||||||
|
permissions (if writable? (writable-by all-permissions) (visible-to all-permissions))]
|
||||||
|
(s/join
|
||||||
|
" "
|
||||||
|
(flatten
|
||||||
|
(list
|
||||||
|
"{% ifmemberof"
|
||||||
|
permissions
|
||||||
|
"%}")))))
|
||||||
|
|
||||||
|
|
||||||
(defn widget
|
(defn widget
|
||||||
"Generate a widget for this `field-or-property` of this `form` for this `entity`
|
"Generate a widget for this `field-or-property` of this `form` for this `entity`
|
||||||
taken from within this `application`."
|
taken from within this `application`."
|
||||||
|
@ -294,7 +319,7 @@
|
||||||
:content [{:tag :label
|
:content [{:tag :label
|
||||||
:attrs {:for widget-name}
|
:attrs {:for widget-name}
|
||||||
:content [(prompt field-or-property form entity application)]}
|
:content [(prompt field-or-property form entity application)]}
|
||||||
(str "{% ifwritable " (:name (:attrs entity)) " " (:name (:attrs property)) " %}")
|
(compose-if-member-of-tag property entity application true)
|
||||||
(cond
|
(cond
|
||||||
select?
|
select?
|
||||||
(select-widget property form entity application)
|
(select-widget property form entity application)
|
||||||
|
@ -312,14 +337,14 @@
|
||||||
(:maximum (:attrs typedef))
|
(:maximum (:attrs typedef))
|
||||||
{:max (:maximum (:attrs typedef))}))})
|
{:max (:maximum (:attrs typedef))}))})
|
||||||
"{% else %}"
|
"{% else %}"
|
||||||
(str "{% ifreadable " (:name (:attrs entity)) " " (:name (:attrs property)) "%}")
|
(compose-if-member-of-tag property entity application false)
|
||||||
{:tag :span
|
{:tag :span
|
||||||
:attrs {:id widget-name
|
:attrs {:id widget-name
|
||||||
:name widget-name
|
:name widget-name
|
||||||
:class "pseudo-widget disabled"}
|
:class "pseudo-widget disabled"}
|
||||||
:content [(str "{{record." widget-name "}}")]}
|
:content [(str "{{record." widget-name "}}")]}
|
||||||
"{% endifreadable %}"
|
"{% endifmemberof %}"
|
||||||
"{% endifwritable %}"]})))
|
"{% endifmemberof %}"]})))
|
||||||
|
|
||||||
|
|
||||||
(defn fields
|
(defn fields
|
||||||
|
@ -335,8 +360,8 @@
|
||||||
[form entity application]
|
[form entity application]
|
||||||
(let
|
(let
|
||||||
[keyfields (children
|
[keyfields (children
|
||||||
;; there should only be one key; its keys are properties
|
;; there should only be one key; its keys are properties
|
||||||
(first (children entity #(= (:tag %) :key))))]
|
(first (children entity #(= (:tag %) :key))))]
|
||||||
{:tag :div
|
{:tag :div
|
||||||
:attrs {:id "content" :class "edit"}
|
:attrs {:id "content" :class "edit"}
|
||||||
:content
|
:content
|
||||||
|
@ -344,16 +369,18 @@
|
||||||
:attrs {:action (str "{{servlet-context}}/" (editor-name entity application))
|
:attrs {:action (str "{{servlet-context}}/" (editor-name entity application))
|
||||||
:method "POST"}
|
:method "POST"}
|
||||||
:content (flatten
|
:content (flatten
|
||||||
(list
|
(list
|
||||||
(csrf-widget)
|
(csrf-widget)
|
||||||
(map
|
(map
|
||||||
#(widget % form entity application)
|
#(widget % form entity application)
|
||||||
keyfields)
|
keyfields)
|
||||||
(map
|
(map
|
||||||
#(widget % form entity application)
|
#(widget % form entity application)
|
||||||
(fields entity))
|
(remove
|
||||||
(save-widget form entity application)
|
#(= (:distict (:attrs %)) :system)
|
||||||
(delete-widget form entity application)))}]}))
|
(fields entity)))
|
||||||
|
(save-widget form entity application)
|
||||||
|
(delete-widget form entity application)))}]}))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -222,8 +222,10 @@
|
||||||
|
|
||||||
|
|
||||||
(defn writable-by
|
(defn writable-by
|
||||||
"Return a list of names of groups to which are granted read access,
|
"Return a list of names of groups to which are granted write access,
|
||||||
given these `permissions`, else nil."
|
given these `permissions`, else nil.
|
||||||
|
TODO: TOTHINKABOUT: properties are also writable by `insert` and `noedit`, but only if the
|
||||||
|
current value is nil."
|
||||||
[permissions]
|
[permissions]
|
||||||
(permission-groups permissions #(#{"edit" "all"} (:permission (:attrs %)))))
|
(permission-groups permissions #(#{"edit" "all"} (:permission (:attrs %)))))
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue