-
Notifications
You must be signed in to change notification settings - Fork 2
/
form-with-refresh-button-view.lisp
81 lines (77 loc) · 4.96 KB
/
form-with-refresh-button-view.lisp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
(in-package :weblocks-cms)
(defclass form-with-refresh-button-view (form-with-sticky-buttons-view)
())
(defclass form-with-refresh-button-view-field (form-view-field)
())
(defclass form-with-refresh-button-scaffold (form-scaffold)
())
(defmethod render-form-view-buttons ((view form-with-refresh-button-view) obj widget &rest args &key buttons &allow-other-keys)
(declare (ignore obj args))
(setf form-view-buttons (form-view-buttons view))
(flet ((find-button (name)
(weblocks::ensure-list
(if form-view-buttons
(find name form-view-buttons
:key (lambda (item)
(car (weblocks::ensure-list item))))
(find name (form-view-buttons view)
:key (lambda (item)
(car (weblocks::ensure-list item))))))))
(let ((submit (find-button :submit))
(cancel (find-button :cancel))
(other-buttons (loop for i in form-view-buttons
unless (find (car (weblocks::ensure-list i)) (list :submit :cancel))
collect (weblocks::ensure-list i))))
(write-string
(weblocks::render-wt-to-string
:form-view-buttons-wt
(list :view view :object obj :widget widget)
:submit-html (let ((submit submit))
(weblocks::capture-weblocks-output
(when submit
(render-button *submit-control-name*
:value (widget-dynamic-translate
view
:submit-button-title
(translate (or (cdr submit)
(humanize-name (car submit)))))))
(loop for (name . title) in other-buttons
do
(with-yaclml
(<:as-is " ")
(<input
:onclick (ps:ps
(initiate-form-action
(ps:LISP
(function-or-action->action
(lambda (&rest args)
(multiple-value-bind (success errors)
(apply #'update-object-view-from-request
(dataform-data widget) view
:class-store (dataform-class-store widget)
args)
(mark-dirty widget :propagate t)
(if success
(progn
(setf (slot-value widget 'weblocks::validation-errors) errors)
(send-script
(ps:ps (alert "Saved successfully"))))
(progn
(setf (slot-value widget 'weblocks::validation-errors) errors)
(setf (slot-value widget 'weblocks::intermediate-form-values)
(apply #'request-parameters-for-object-view
view (dataform-data widget) args))))))))
(ps:chain (j-query this) (parents "form"))
(ps:LISP (session-name-string-pair))))
:type "button" :name name :value title :class "submit btn btn-primary")))))
:cancel-html (let ((cancel cancel))
(when cancel
(weblocks::capture-weblocks-output
(render-button *cancel-control-name*
:class "submit cancel"
:value (widget-dynamic-translate
view
:cancel-button-title
(translate (or (cdr cancel)
(humanize-name (car cancel))))))))))
*weblocks-output-stream*))))