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 (defmethod present-relation ((slot mewa-relation-slot-presentation
) instance
)
46 ;;;;(<:as-html (slot-name slot) "=> " (foreign-instance slot) " from " instance )
47 (let* ((i (foreign-instance slot
))
48 (pres (mewa::make-presentation
53 (list :editablep nil
:linkedp nil
)))))
54 (when (ucw::parent slot
) (setf (component.place pres
) (component.place
(ucw::parent slot
))))
55 (flet ((render () (when i
(<ucw
:render-component
:component pres
))))
59 (<ucw
:a
:action
(search-records slot i
) (<:as-html
" (search)"))
60 (<ucw
:a
:action
(create-record slot i
) (<:as-html
" (new)")))
62 (<ucw
:a
:action
(view-instance slot i
)
67 (defmethod present-slot ((slot mewa-relation-slot-presentation
) instance
)
68 (present-relation slot instance
))
70 (defslot-presentation foreign-key-slot-presentation
(mewa-relation-slot-presentation)
72 (:type-name foreign-key
)
75 (defaction view-instance
((self component
) instance
&rest initargs
)
76 (call-component (parent self
) (apply #'mewa
:make-presentation instance initargs
)))
78 (defmethod present-slot :before
((slot foreign-key-slot-presentation
) instance
)
79 (setf (foreign-instance slot
) (meta-model:explode-foreign-key instance
(slot-name slot
))))
82 (defslot-presentation has-many-slot-presentation
(mewa-relation-slot-presentation)
84 (:type-name has-many
))
86 (defmethod present-slot ((slot has-many-slot-presentation
) instance
)
87 (let ((i (get-foreign-instances slot instance
))
88 (linkedp (linkedp slot
)))
92 (setf (foreign-instance slot
) s
)
93 (<ucw
:a
:action
(view-instance slot s
:initargs
`(:global-properties
,(list :linkedp t
:editablep nil
)))
94 (<:li
(setf (linkedp slot
) nil
)
95 (present-relation slot instance
))))))))
98 (defmethod get-foreign-instances ((slot has-many-slot-presentation
) instance
)
99 (slot-value instance
(slot-name slot
)))
101 (defslot-presentation has-very-many-slot-presentation
(has-many-slot-presentation)
102 ((number-to-display :accessor number-to-display
:initarg
:number-to-display
:initform
10)
103 (current :accessor current
:initform
0)
105 (instances :accessor instances
))
107 (:type-name has-very-many
))
109 (defmethod list-next ((slot has-very-many-slot-presentation
))
110 (setf (current slot
) (incf (current slot
) (number-to-display slot
)))
111 (when (< (len slot
) (current slot
))
112 (setf (current slot
) (- (number-to-display slot
) (len slot
)))))
114 (defmethod list-prev ((slot has-very-many-slot-presentation
))
115 (setf (current slot
) (decf (current slot
) (number-to-display slot
)))
116 (when (> 0 (current slot
))
117 ;;what to do here is open to debate
118 (setf (current slot
) (- (len slot
)(number-to-display slot
) ))))
121 (defmethod present-slot ((slot has-very-many-slot-presentation
) instance
)
122 ;;(<:as-html "isance: " instance)
123 (<ucw
:a
:action
(list-prev slot
) (<:as-html
"<<"))
124 (let ((self (parent slot
)))
125 (<ucw
:a
:action
(call-component self
(mewa:make-presentation
(car (slot-value instance
(slot-name slot
))) :type
:listing
:initargs
(list :instances
(instances slot
))))
126 (<:as-html
(label slot
) (format nil
" ~a-~a " (current slot
) (+ (current slot
) (number-to-display slot
))))))
127 (<ucw
:a
:action
(list-next slot
) (<:as-html
">>"))
129 (<:as-html
"total :" (len slot
)))
131 (defmethod get-foreign-instances :around
((slot has-very-many-slot-presentation
) instance
)
132 (let ((f (call-next-method)))
133 (setf (len slot
) (length f
))
134 (setf (instances slot
) f
)
135 (loop for cons on
(nthcdr (current slot
) f
)
136 for i from
0 upto
(number-to-display slot
)
137 collect
(car cons
))))
139 (defslot-presentation has-a-slot-presentation
(one-of-presentation)
140 ((key :initarg
:key
:accessor key
))
143 (defmethod get-foreign-slot-value ((slot has-a-slot-presentation
) (object t
) (slot-name t
))
144 (slot-value object slot-name
))
146 (defmethod present-slot ((slot has-a-slot-presentation
) instance
)
147 (<:as-html
(presentation-slot-value slot instance
))
149 (<ucw
:select
:accessor
(presentation-slot-value slot instance
) :test
#'equalp
150 (when (allow-nil-p slot
)
151 (<ucw
:option
:value nil
(<:as-html
(none-label slot
))))
152 (dolist (option (get-foreign-instances (presentation slot
) instance
))
153 (setf (instance (presentation slot
)) option
)
154 (<ucw
:option
:value
(get-foreign-slot-value slot option
(key slot
)) (present (presentation slot
)))))
155 (if (presentation-slot-value slot instance
)
157 (setf (instance (presentation slot
)) (presentation-slot-value slot instance
))
158 (present (presentation slot
)))