1 (in-package :it.bese.ucw
)
4 (defslot-presentation clsql-wall-time-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 (setf (presentation-slot-value slot instance
) (clsql:parse-date-time
(remove #\Space value
))))
16 (defmethod label :around
((slot clsql-wall-time-slot-presentation
))
17 (concatenate 'string
(call-next-method) " (mm/dd/yyyy)"))
19 (defmethod present-slot ((slot clsql-wall-time-slot-presentation
) instance
)
20 (let ((date (presentation-slot-value slot instance
))
21 (input-id (string (gensym))))
22 (if (and date
(not (editablep slot
)))
23 (<:span
(<:as-html date
)))
24 (when (editablep slot
)
25 (<ucw
:input
:accessor
(presentation-slot-value slot instance
) :id input-id
)
26 (<:script
:type
"text/javascript"
27 (<:as-is
(format nil
"
30 ifFormat : \"%m/%d/%Y\",
33 (defslot-presentation mewa-relation-slot-presentation
()
34 ((slot-name :accessor slot-name
:initarg
:slot-name
)
35 (foreign-instance :accessor foreign-instance
)
36 (linkedp :accessor linkedp
:initarg
:linkedp
:initform t
))
37 (:type-name relation
))
39 (defmethod present-relation ((slot mewa-relation-slot-presentation
) instance
)
40 ;;;;(<:as-html (slot-name slot) "=> " (foreign-instance slot) " from " instance )
41 (let* ((i (foreign-instance slot
))
42 (pres (mewa::make-presentation
47 (list :editablep nil
:linkedp nil
)))))
48 (when (ucw::parent slot
) (setf (component.place pres
) (component.place
(ucw::parent slot
))))
49 (flet ((render () (when i
(<ucw
:render-component
:component pres
))))
53 (<ucw
:a
:action
(search-records slot i
) (<:as-html
" (search)"))
54 (<ucw
:a
:action
(create-record slot i
) (<:as-html
" (new)")))
56 (<ucw
:a
:action
(view-instance slot i
)
61 (defmethod present-slot ((slot mewa-relation-slot-presentation
) instance
)
62 (present-relation slot instance
))
64 (defslot-presentation foreign-key-slot-presentation
(mewa-relation-slot-presentation)
66 (:type-name foreign-key
)
69 (defaction view-instance
((self component
) instance
&rest initargs
)
70 (call-component (parent self
) (apply #'mewa
:make-presentation instance initargs
)))
72 (defmethod present-slot :before
((slot foreign-key-slot-presentation
) instance
)
73 (setf (foreign-instance slot
) (meta-model:explode-foreign-key instance
(slot-name slot
))))
76 (defslot-presentation has-many-slot-presentation
(mewa-relation-slot-presentation)
78 (:type-name has-many
))
80 (defmethod present-slot ((slot has-many-slot-presentation
) instance
)
81 (let ((i (get-foreign-instances slot instance
))
82 (linkedp (linkedp slot
)))
86 (setf (foreign-instance slot
) s
)
87 (<ucw
:a
:action
(view-instance slot s
:initargs
`(:global-properties
,(list :linkedp t
:editablep nil
)))
88 (<:li
(setf (linkedp slot
) nil
)
89 (present-relation slot instance
))))))))
92 (defmethod get-foreign-instances ((slot has-many-slot-presentation
) instance
)
93 (slot-value instance
(slot-name slot
)))
95 (defslot-presentation has-very-many-slot-presentation
(has-many-slot-presentation)
96 ((number-to-display :accessor number-to-display
:initarg
:number-to-display
:initform
10)
97 (current :accessor current
:initform
0)
99 (instances :accessor instances
))
101 (:type-name has-very-many
))
103 (defmethod list-next ((slot has-very-many-slot-presentation
))
104 (setf (current slot
) (incf (current slot
) (number-to-display slot
)))
105 (when (< (len slot
) (current slot
))
106 (setf (current slot
) (- (number-to-display slot
) (len slot
)))))
108 (defmethod list-prev ((slot has-very-many-slot-presentation
))
109 (setf (current slot
) (decf (current slot
) (number-to-display slot
)))
110 (when (> 0 (current slot
))
111 ;;what to do here is open to debate
112 (setf (current slot
) (- (len slot
)(number-to-display slot
) ))))
115 (defmethod present-slot ((slot has-very-many-slot-presentation
) instance
)
116 ;;(<:as-html "isance: " instance)
117 (<ucw
:a
:action
(list-prev slot
) (<:as-html
"<<"))
118 (let ((self (parent slot
)))
119 (<ucw
:a
:action
(call-component self
(mewa:make-presentation
(car (slot-value instance
(slot-name slot
))) :type
:listing
:initargs
(list :instances
(instances slot
))))
120 (<:as-html
(label slot
) (format nil
" ~a-~a " (current slot
) (+ (current slot
) (number-to-display slot
))))))
121 (<ucw
:a
:action
(list-next slot
) (<:as-html
">>"))
123 (<:as-html
"total :" (len slot
)))
125 (defmethod get-foreign-instances :around
((slot has-very-many-slot-presentation
) instance
)
126 (let ((f (call-next-method)))
127 (setf (len slot
) (length f
))
128 (setf (instances slot
) f
)
129 (loop for cons on
(nthcdr (current slot
) f
)
130 for i from
0 upto
(number-to-display slot
)
131 collect
(car cons
))))
133 (defslot-presentation has-a-slot-presentation
(one-of-presentation)
134 ((key :initarg
:key
:accessor key
))
137 (defmethod get-foreign-slot-value ((slot has-a-slot-presentation
) (object t
) (slot-name t
))
138 (slot-value object slot-name
))
140 (defmethod present-slot ((slot has-a-slot-presentation
) instance
)
141 (<:as-html
(presentation-slot-value slot instance
))
143 (<ucw
:select
:accessor
(presentation-slot-value slot instance
) :test
#'equalp
144 (when (allow-nil-p slot
)
145 (<ucw
:option
:value nil
(<:as-html
(none-label slot
))))
146 (dolist (option (get-foreign-instances (presentation slot
) instance
))
147 (setf (instance (presentation slot
)) option
)
148 (<ucw
:option
:value
(get-foreign-slot-value slot option
(key slot
)) (present (presentation slot
)))))
149 (if (presentation-slot-value slot instance
)
151 (setf (instance (presentation slot
)) (presentation-slot-value slot instance
))
152 (present (presentation slot
)))