1 (in-package :it.bese.ucw
)
4 (defslot-presentation clsql-wall-time-slot-presentation
(mewa-relation-slot-presentation)
6 (:type-name clsql-sys
:wall-time
))
8 (defmethod presentation-slot-value ((slot clsql-wall-time-slot-presentation
) instance
)
9 (let ((date (call-next-method)))
10 (when date
(multiple-value-bind (y m d
) (clsql:time-ymd date
)
11 (format nil
"~a/~a/~a" m d y
)))))
13 (defmethod (setf presentation-slot-value
) ((value string
) (slot clsql-wall-time-slot-presentation
) instance
)
14 (let ((new-time (clsql:parse-date-time
(remove #\Space value
)))
15 (old-time (when (slot-boundp instance
(slot-name slot
))
16 (slot-value instance
(slot-name slot
)))))
17 (unless (or (eql old-time new-time
)
18 (and (null old-time
) new-time
)
19 (equal :equal
(clsql:time-compare new-time old-time
)))
20 (setf (presentation-slot-value slot instance
) new-time
))))
22 (defmethod label :around
((slot clsql-wall-time-slot-presentation
))
23 (concatenate 'string
(call-next-method) " (mm/dd/yyyy)"))
25 (defmethod present-slot ((slot clsql-wall-time-slot-presentation
) instance
)
26 (let ((date (presentation-slot-value slot instance
))
27 (input-id (string (gensym))))
28 (if (and date
(not (editablep slot
)))
29 (<:span
(<:as-html date
)))
30 (when (editablep slot
)
31 (<ucw
:input
:accessor
(presentation-slot-value slot instance
) :id input-id
)
32 (<:script
:type
"text/javascript"
33 (<:as-is
(format nil
"
36 ifFormat : \"%m/%d/%Y\",
39 (defslot-presentation mewa-relation-slot-presentation
()
40 ((slot-name :accessor slot-name
:initarg
:slot-name
)
41 (foreign-instance :accessor foreign-instance
)
42 (linkedp :accessor linkedp
:initarg
:linkedp
:initform t
))
43 (:type-name relation
))
45 (defun get-fkey-data (instance slot-name
)
46 "ugly workaround b/c UCW does not like M-V-B"
47 (multiple-value-bind (finstance foreign-slot-name
)
48 (meta-model:explode-foreign-key instance slot-name
)
49 (cons finstance foreign-slot-name
)))
51 (defaction search-records
((slot mewa-relation-slot-presentation
) instance
)
52 (let* ((d (get-fkey-data instance
(slot-name slot
)))
54 (foreign-slot-name (cdr d
))
58 (make-instance 'mewa
::mewa-presentation-search
60 (mewa:make-presentation finstance
61 :type
:search-presentation
)
63 (mewa:make-presentation finstance
65 (setf (slot-value instance
(slot-name slot
)) (slot-value new-instance foreign-slot-name
))
66 (meta-model:sync-instance instance
)
67 (clsql:update-objects-joins
(list instance
))))
69 (defmethod present-relation ((slot mewa-relation-slot-presentation
) instance
)
70 ;;;;(<:as-html (slot-name slot) "=> " (foreign-instance slot) " from " instance )
71 (let* ((i (foreign-instance slot
))
72 (pres (mewa::make-presentation
77 (list :editablep nil
:linkedp nil
)))))
78 (when (ucw::parent slot
) (setf (component.place pres
) (component.place
(ucw::parent slot
))))
79 (flet ((render () (when i
(<ucw
:render-component
:component pres
))))
83 (<ucw
:a
:action
(search-records slot instance
) (<:as-html
" (search)"))
84 (<ucw
:a
:action
(create-record slot i
) (<:as-html
" (new)")))
86 (<ucw
:a
:action
(view-instance slot i
)
93 (defmethod present-slot ((slot mewa-relation-slot-presentation
) instance
)
94 (present-relation slot instance
))
96 (defslot-presentation foreign-key-slot-presentation
(mewa-relation-slot-presentation)
98 (:type-name foreign-key
)
101 (defaction view-instance
((self component
) instance
&rest initargs
)
102 (call-component (parent self
) (apply #'mewa
:make-presentation instance initargs
)))
104 (defmethod present-slot :before
((slot foreign-key-slot-presentation
) instance
)
105 (setf (foreign-instance slot
) (meta-model:explode-foreign-key instance
(slot-name slot
))))
108 (defslot-presentation has-many-slot-presentation
(mewa-relation-slot-presentation)
110 (:type-name has-many
))
112 (defmethod present-slot ((slot has-many-slot-presentation
) instance
)
113 (let ((i (get-foreign-instances slot instance
))
114 (linkedp (linkedp slot
)))
118 (setf (foreign-instance slot
) s
)
119 (<ucw
:a
:action
(view-instance slot s
:initargs
`(:global-properties
,(list :linkedp t
:editablep nil
)))
120 (<:li
(setf (linkedp slot
) nil
)
121 (present-relation slot instance
))))))))
124 (defmethod get-foreign-instances ((slot has-many-slot-presentation
) instance
)
125 (slot-value instance
(slot-name slot
)))
127 (defslot-presentation has-very-many-slot-presentation
(has-many-slot-presentation)
128 ((number-to-display :accessor number-to-display
:initarg
:number-to-display
:initform
10)
129 (current :accessor current
:initform
0)
131 (instances :accessor instances
))
133 (:type-name has-very-many
))
135 (defmethod list-next ((slot has-very-many-slot-presentation
))
136 (setf (current slot
) (incf (current slot
) (number-to-display slot
)))
137 (when (< (len slot
) (current slot
))
138 (setf (current slot
) (- (number-to-display slot
) (len slot
)))))
140 (defmethod list-prev ((slot has-very-many-slot-presentation
))
141 (setf (current slot
) (decf (current slot
) (number-to-display slot
)))
142 (when (> 0 (current slot
))
143 ;;what to do here is open to debate
144 (setf (current slot
) (- (len slot
)(number-to-display slot
) ))))
147 (defmethod present-slot ((slot has-very-many-slot-presentation
) instance
)
148 ;;(<:as-html "isance: " instance)
149 (<ucw
:a
:action
(list-prev slot
) (<:as-html
"<<"))
150 (let ((self (parent slot
)))
151 (<ucw
:a
:action
(call-component self
(mewa:make-presentation
(car (slot-value instance
(slot-name slot
))) :type
:listing
:initargs
(list :instances
(instances slot
))))
152 (<:as-html
(label slot
) (format nil
" ~a-~a " (current slot
) (+ (current slot
) (number-to-display slot
))))))
153 (<ucw
:a
:action
(list-next slot
) (<:as-html
">>"))
155 (<:as-html
"total :" (len slot
)))
157 (defmethod get-foreign-instances :around
((slot has-very-many-slot-presentation
) instance
)
158 (let ((f (call-next-method)))
159 (setf (len slot
) (length f
))
160 (setf (instances slot
) f
)
161 (loop for cons on
(nthcdr (current slot
) f
)
162 for i from
0 upto
(number-to-display slot
)
163 collect
(car cons
))))
165 (defslot-presentation has-a-slot-presentation
(one-of-presentation)
166 ((key :initarg
:key
:accessor key
))
169 (defmethod get-foreign-slot-value ((slot has-a-slot-presentation
) (object t
) (slot-name t
))
170 (slot-value object slot-name
))
172 (defmethod present-slot ((slot has-a-slot-presentation
) instance
)
173 (<:as-html
(presentation-slot-value slot instance
))
175 (<ucw
:select
:accessor
(presentation-slot-value slot instance
) :test
#'equalp
176 (when (allow-nil-p slot
)
177 (<ucw
:option
:value nil
(<:as-html
(none-label slot
))))
178 (dolist (option (get-foreign-instances (presentation slot
) instance
))
179 (setf (instance (presentation slot
)) option
)
180 (<ucw
:option
:value
(get-foreign-slot-value slot option
(key slot
)) (present (presentation slot
)))))
181 (if (presentation-slot-value slot instance
)
183 (setf (instance (presentation slot
)) (presentation-slot-value slot instance
))
184 (present (presentation slot
)))