1 (in-package :it.bese.ucw
)
3 (defun multiple-value-funcall->list
(function &rest args
)
4 (multiple-value-call #'list
(apply function args
)))
6 (defmacro multiple-value-bindf
(vars form
&body body
)
7 `(destructuring-bind ,vars
8 (multiple-value-funcall->list
#',(car form
) ,@(cdr form
))
11 (defslot-presentation clsql-wall-time-slot-presentation
(mewa-relation-slot-presentation)
13 (:type-name clsql-sys
:wall-time
))
15 (defmethod presentation-slot-value ((slot clsql-wall-time-slot-presentation
) instance
)
16 (let ((date (call-next-method)))
17 (when date
(multiple-value-bind (y m d
) (clsql:time-ymd date
)
18 (format nil
"~a/~a/~a" m d y
)))))
20 (defmethod (setf presentation-slot-value
) ((value string
) (slot clsql-wall-time-slot-presentation
) instance
)
21 (let ((new-time (clsql:parse-date-time
(remove #\Space value
)))
22 (old-time (when (slot-boundp instance
(slot-name slot
))
23 (slot-value instance
(slot-name slot
)))))
24 (unless (or (eql old-time new-time
)
25 (and (null old-time
) new-time
)
26 (equal :equal
(clsql:time-compare new-time old-time
)))
27 (setf (presentation-slot-value slot instance
) new-time
))))
29 (defmethod label :around
((slot clsql-wall-time-slot-presentation
))
30 (concatenate 'string
(call-next-method) " (mm/dd/yyyy)"))
32 (defmethod present-slot ((slot clsql-wall-time-slot-presentation
) instance
)
33 (let ((date (presentation-slot-value slot instance
))
34 (input-id (string (gensym))))
35 (if (and date
(not (editablep slot
)))
36 (<:span
(<:as-html date
)))
37 (when (editablep slot
)
38 (<ucw
:input
:accessor
(presentation-slot-value slot instance
) :id input-id
)
39 (<:script
:type
"text/javascript"
40 (<:as-is
(format nil
"
43 ifFormat : \"%m/%d/%Y\",
46 (defslot-presentation mewa-relation-slot-presentation
()
47 ((slot-name :accessor slot-name
:initarg
:slot-name
)
48 (foreign-instance :accessor foreign-instance
)
49 (linkedp :accessor linkedp
:initarg
:linkedp
:initform t
))
50 (:type-name relation
))
52 (defun get-fkey-data (instance slot-name
)
53 "ugly workaround b/c UCW does not like M-V-B"
54 (multiple-value-bind (finstance foreign-slot-name
)
55 (meta-model:explode-foreign-key instance slot-name
)
56 (cons finstance foreign-slot-name
)))
58 (defaction search-records
((slot mewa-relation-slot-presentation
) instance
)
59 (let* ((d (get-fkey-data instance
(slot-name slot
)))
61 (foreign-slot-name (cdr d
))
65 (make-instance 'mewa
::mewa-presentation-search
67 (mewa:make-presentation finstance
68 :type
:search-presentation
)
70 (mewa:make-presentation finstance
72 (setf (slot-value instance
(slot-name slot
)) (slot-value new-instance foreign-slot-name
))
73 (meta-model:sync-instance instance
)
74 (clsql:update-objects-joins
(list instance
))))
76 (defmethod present-relation ((slot mewa-relation-slot-presentation
) instance
)
77 ;;;;(<:as-html (slot-name slot) "=> " (foreign-instance slot) " from " instance )
78 (let* ((i (foreign-instance slot
))
79 (pres (mewa::make-presentation
84 (list :editablep nil
:linkedp nil
)))))
85 (when (ucw::parent slot
)
86 (setf (component.place pres
) (component.place
(ucw::parent slot
))))
87 (when i
(<ucw
:render-component
:component pres
))))
92 (defmethod present-slot ((slot mewa-relation-slot-presentation
) instance
)
93 (present-relation slot instance
))
95 (defslot-presentation foreign-key-slot-presentation
(mewa-relation-slot-presentation)
97 (:type-name foreign-key
)
100 (defaction view-instance
((self component
) instance
&rest initargs
)
101 (call-component (parent self
) (apply #'mewa
:make-presentation instance initargs
)))
104 (defmethod present-slot :around
((slot foreign-key-slot-presentation
) instance
)
105 (setf (foreign-instance slot
) (when (presentation-slot-value slot instance
) (meta-model:explode-foreign-key instance
(slot-name slot
))))
106 (flet ((render () (call-next-method)))
110 (<ucw
:a
:action
(search-records slot instance
) (<:as-html
" (search)"))
111 (<ucw
:a
:action
(create-record slot instance
) (<:as-html
" (new)")))
113 (<ucw
:a
:action
(view-instance slot
(foreign-instance slot
))
119 (defslot-presentation has-many-slot-presentation
(mewa-relation-slot-presentation)
121 (:type-name has-many
))
124 (defun get-join-class-info (slot instance
)
126 (multiple-value-bind (s h f
) (meta-model:explode-has-many instance
(slot-name slot
))
128 ((jci (get-join-class-info slot instance
))
131 (foreign (third jci
)))
133 (defaction add-to-has-many
((slot has-many-slot-presentation
) instance
)
134 (destructuring-bind (class home foreign
)
135 (maxwell-web-gui::multiple-value-funcall
#'meta-model
:explode-has-many instance
(slot-name slot
))
136 (let ((new (make-instance class
)))
137 (setf (slot-value new foreign
) (slot-value instance home
))
138 (meta-model:sync-instance new
)
139 (call-component (parent slot
) (mewa:make-presentation new
:type
:editor
)))))
141 (defmethod present-slot ((slot has-many-slot-presentation
) instance
)
142 (<ucw
:a
:action
(add-to-has-many slot instance
)
143 (<:as-html
"(add new)"))
144 (let ((i (get-foreign-instances slot instance
))
145 (linkedp (linkedp slot
)))
149 (setf (foreign-instance slot
) s
)
150 (<ucw
:a
:action
(view-instance slot s
:initargs
`(:global-properties
,(list :linkedp t
:editablep nil
)))
151 (<:li
(setf (linkedp slot
) nil
)
152 (present-relation slot instance
))))))))
155 (defmethod get-foreign-instances ((slot has-many-slot-presentation
) instance
)
156 (slot-value instance
(slot-name slot
)))
158 (defslot-presentation has-very-many-slot-presentation
(has-many-slot-presentation)
159 ((number-to-display :accessor number-to-display
:initarg
:number-to-display
:initform
10)
160 (current :accessor current
:initform
0)
162 (instances :accessor instances
))
164 (:type-name has-very-many
))
166 (defmethod list-next ((slot has-very-many-slot-presentation
))
167 (setf (current slot
) (incf (current slot
) (number-to-display slot
)))
168 (when (< (len slot
) (current slot
))
169 (setf (current slot
) (- (number-to-display slot
) (len slot
)))))
171 (defmethod list-prev ((slot has-very-many-slot-presentation
))
172 (setf (current slot
) (decf (current slot
) (number-to-display slot
)))
173 (when (> 0 (current slot
))
174 ;;what to do here is open to debate
175 (setf (current slot
) (- (len slot
)(number-to-display slot
) ))))
178 (defmethod present-slot ((slot has-very-many-slot-presentation
) instance
)
179 ;;(<:as-html "isance: " instance)
180 (<ucw
:a
:action
(list-prev slot
) (<:as-html
"<<"))
181 (let ((self (parent slot
)))
182 (<ucw
:a
:action
(call-component self
(mewa:make-presentation
(car (slot-value instance
(slot-name slot
))) :type
:listing
:initargs
(list :instances
(instances slot
))))
183 (<:as-html
(label slot
) (format nil
" ~a-~a " (current slot
) (+ (current slot
) (number-to-display slot
))))))
184 (<ucw
:a
:action
(list-next slot
) (<:as-html
">>"))
186 (<:as-html
"total :" (len slot
)))
188 (defmethod get-foreign-instances :around
((slot has-very-many-slot-presentation
) instance
)
189 (let ((f (call-next-method)))
190 (setf (len slot
) (length f
))
191 (setf (instances slot
) f
)
192 (loop for cons on
(nthcdr (current slot
) f
)
193 for i from
0 upto
(number-to-display slot
)
194 collect
(car cons
))))
196 (defslot-presentation has-a-slot-presentation
(one-of-presentation)
197 ((key :initarg
:key
:accessor key
))
200 (defmethod get-foreign-slot-value ((slot has-a-slot-presentation
) (object t
) (slot-name t
))
201 (slot-value object slot-name
))
203 (defmethod present-slot ((slot has-a-slot-presentation
) instance
)
204 (<:as-html
(presentation-slot-value slot instance
))
206 (<ucw
:select
:accessor
(presentation-slot-value slot instance
) :test
#'equalp
207 (when (allow-nil-p slot
)
208 (<ucw
:option
:value nil
(<:as-html
(none-label slot
))))
209 (dolist (option (get-foreign-instances (presentation slot
) instance
))
210 (setf (instance (presentation slot
)) option
)
211 (<ucw
:option
:value
(get-foreign-slot-value slot option
(key slot
)) (present (presentation slot
)))))
212 (if (presentation-slot-value slot instance
)
214 (setf (instance (presentation slot
)) (presentation-slot-value slot instance
))
215 (present (presentation slot
)))