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
) (setf (component.place pres
) (component.place
(ucw::parent slot
))))
86 (flet ((render () (when i
(<ucw
:render-component
:component pres
))))
90 (<ucw
:a
:action
(search-records slot instance
) (<:as-html
" (search)"))
91 (<ucw
:a
:action
(create-record slot i
) (<:as-html
" (new)")))
93 (<ucw
:a
:action
(view-instance slot i
)
100 (defmethod present-slot ((slot mewa-relation-slot-presentation
) instance
)
101 (present-relation slot instance
))
103 (defslot-presentation foreign-key-slot-presentation
(mewa-relation-slot-presentation)
105 (:type-name foreign-key
)
108 (defaction view-instance
((self component
) instance
&rest initargs
)
109 (call-component (parent self
) (apply #'mewa
:make-presentation instance initargs
)))
111 (defmethod present-slot :before
((slot foreign-key-slot-presentation
) instance
)
112 (setf (foreign-instance slot
) (meta-model:explode-foreign-key instance
(slot-name slot
))))
115 (defslot-presentation has-many-slot-presentation
(mewa-relation-slot-presentation)
117 (:type-name has-many
))
119 (defmethod present-slot ((slot has-many-slot-presentation
) instance
)
120 (let ((i (get-foreign-instances slot instance
))
121 (linkedp (linkedp slot
)))
125 (setf (foreign-instance slot
) s
)
126 (<ucw
:a
:action
(view-instance slot s
:initargs
`(:global-properties
,(list :linkedp t
:editablep nil
)))
127 (<:li
(setf (linkedp slot
) nil
)
128 (present-relation slot instance
))))))))
131 (defmethod get-foreign-instances ((slot has-many-slot-presentation
) instance
)
132 (slot-value instance
(slot-name slot
)))
134 (defslot-presentation has-very-many-slot-presentation
(has-many-slot-presentation)
135 ((number-to-display :accessor number-to-display
:initarg
:number-to-display
:initform
10)
136 (current :accessor current
:initform
0)
138 (instances :accessor instances
))
140 (:type-name has-very-many
))
142 (defmethod list-next ((slot has-very-many-slot-presentation
))
143 (setf (current slot
) (incf (current slot
) (number-to-display slot
)))
144 (when (< (len slot
) (current slot
))
145 (setf (current slot
) (- (number-to-display slot
) (len slot
)))))
147 (defmethod list-prev ((slot has-very-many-slot-presentation
))
148 (setf (current slot
) (decf (current slot
) (number-to-display slot
)))
149 (when (> 0 (current slot
))
150 ;;what to do here is open to debate
151 (setf (current slot
) (- (len slot
)(number-to-display slot
) ))))
154 (defmethod present-slot ((slot has-very-many-slot-presentation
) instance
)
155 ;;(<:as-html "isance: " instance)
156 (<ucw
:a
:action
(list-prev slot
) (<:as-html
"<<"))
157 (let ((self (parent slot
)))
158 (<ucw
:a
:action
(call-component self
(mewa:make-presentation
(car (slot-value instance
(slot-name slot
))) :type
:listing
:initargs
(list :instances
(instances slot
))))
159 (<:as-html
(label slot
) (format nil
" ~a-~a " (current slot
) (+ (current slot
) (number-to-display slot
))))))
160 (<ucw
:a
:action
(list-next slot
) (<:as-html
">>"))
162 (<:as-html
"total :" (len slot
)))
164 (defmethod get-foreign-instances :around
((slot has-very-many-slot-presentation
) instance
)
165 (let ((f (call-next-method)))
166 (setf (len slot
) (length f
))
167 (setf (instances slot
) f
)
168 (loop for cons on
(nthcdr (current slot
) f
)
169 for i from
0 upto
(number-to-display slot
)
170 collect
(car cons
))))
172 (defslot-presentation has-a-slot-presentation
(one-of-presentation)
173 ((key :initarg
:key
:accessor key
))
176 (defmethod get-foreign-slot-value ((slot has-a-slot-presentation
) (object t
) (slot-name t
))
177 (slot-value object slot-name
))
179 (defmethod present-slot ((slot has-a-slot-presentation
) instance
)
180 (<:as-html
(presentation-slot-value slot instance
))
182 (<ucw
:select
:accessor
(presentation-slot-value slot instance
) :test
#'equalp
183 (when (allow-nil-p slot
)
184 (<ucw
:option
:value nil
(<:as-html
(none-label slot
))))
185 (dolist (option (get-foreign-instances (presentation slot
) instance
))
186 (setf (instance (presentation slot
)) option
)
187 (<ucw
:option
:value
(get-foreign-slot-value slot option
(key slot
)) (present (presentation slot
)))))
188 (if (presentation-slot-value slot instance
)
190 (setf (instance (presentation slot
)) (presentation-slot-value slot instance
))
191 (present (presentation slot
)))