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 present-slot ((slot clsql-wall-time-slot-presentation
) instance
)
17 (let ((date (presentation-slot-value slot instance
))
18 (input-id (string (gensym))))
19 (if (and date
(not (editablep slot
)))
20 (<:span
(<:as-html date
)))
21 (when (editablep slot
)
22 (<ucw
:input
:accessor
(presentation-slot-value slot instance
) :id input-id
)
23 (<:script
:type
"text/javascript"
24 (<:as-is
(format nil
"
27 ifFormat : \"%m/%d/%Y\",
30 (defslot-presentation mewa-relation-slot-presentation
()
31 ((slot-name :accessor slot-name
:initarg
:slot-name
)
32 (foreign-instance :accessor foreign-instance
)
33 (linkedp :accessor linkedp
:initarg
:linkedp
:initform t
))
34 (:type-name relation
))
36 (defmethod present-relation ((slot mewa-relation-slot-presentation
) instance
)
37 ;;;;(<:as-html (slot-name slot) "=> " (foreign-instance slot) " from " instance )
38 (let* ((e (getf (mewa::global-properties
(parent slot
)) :editablep
))
39 (i (foreign-instance slot
))
40 (pres (mewa::make-presentation
45 (list :editablep nil
:linkedp
(linkedp slot
))))))
46 (when (ucw::parent slot
) (setf (component.place pres
) (component.place
(ucw::parent slot
))))
47 (flet ((render () (when i
(<ucw
:render-component
:component pres
))))
51 (<ucw
:a
:action
(search-records slot i
) (<:as-html
" (search)"))
52 (<ucw
:a
:action
(create-record slot i
) (<:as-html
" (new)")))
54 (<ucw
:a
:action
(view-instance slot i
)
59 (defmethod present-slot ((slot mewa-relation-slot-presentation
) instance
)
60 (present-relation slot instance
))
62 (defslot-presentation foreign-key-slot-presentation
(mewa-relation-slot-presentation)
64 (:type-name foreign-key
)
67 (defaction view-instance
((self component
) instance
&rest initargs
)
68 (call-component (parent self
) (apply #'mewa
:make-presentation instance initargs
)))
70 (defmethod present-slot :before
((slot foreign-key-slot-presentation
) instance
)
71 (setf (foreign-instance slot
) (meta-model:explode-foreign-key instance
(slot-name slot
))))
74 (defslot-presentation has-many-slot-presentation
(mewa-relation-slot-presentation)
76 (:type-name has-many
))
78 (defmethod present-slot ((slot has-many-slot-presentation
) instance
)
79 (let ((i (get-foreign-instances slot instance
))
80 (linkedp (linkedp slot
)))
84 (setf (foreign-instance slot
) s
)
85 (<ucw
:a
:action
(view-instance slot s
:initargs
`(:global-properties
,(list :linkedp t
:editablep nil
)))
86 (<:li
(setf (linkedp slot
) nil
)
87 (present-relation slot instance
))))))))
90 (defmethod get-foreign-instances ((slot has-many-slot-presentation
) instance
)
91 (slot-value instance
(slot-name slot
)))
93 (defslot-presentation has-very-many-slot-presentation
(has-many-slot-presentation)
94 ((number-to-display :accessor number-to-display
:initarg
:number-to-display
:initform
10)
95 (current :accessor current
:initform
0)
97 (instances :accessor instances
))
99 (:type-name has-very-many
))
101 (defmethod list-next ((slot has-very-many-slot-presentation
))
102 (setf (current slot
) (incf (current slot
) (number-to-display slot
)))
103 (when (< (len slot
) (current slot
))
104 (setf (current slot
) (- (number-to-display slot
) (len slot
)))))
106 (defmethod list-prev ((slot has-very-many-slot-presentation
))
107 (setf (current slot
) (decf (current slot
) (number-to-display slot
)))
108 (when (> 0 (current slot
))
109 ;;what to do here is open to debate
110 (setf (current slot
) (- (len slot
)(number-to-display slot
) ))))
113 (defmethod present-slot ((slot has-very-many-slot-presentation
) instance
)
114 ;;(<:as-html "isance: " instance)
115 (<ucw
:a
:action
(list-prev slot
) (<:as-html
"<<"))
116 (let ((self (parent slot
)))
117 (<ucw
:a
:action
(call-component self
(mewa:make-presentation
(car (slot-value instance
(slot-name slot
))) :type
:listing
:initargs
(list :instances
(instances slot
))))
118 (<:as-html
(label slot
) (format nil
" ~a-~a " (current slot
) (+ (current slot
) (number-to-display slot
))))))
119 (<ucw
:a
:action
(list-next slot
) (<:as-html
">>"))
121 (<:as-html
"total :" (len slot
)))
123 (defmethod get-foreign-instances :around
((slot has-very-many-slot-presentation
) instance
)
124 (let ((f (call-next-method)))
125 (setf (len slot
) (length f
))
126 (setf (instances slot
) f
)
127 (loop for cons on
(nthcdr (current slot
) f
)
128 for i from
0 upto
(number-to-display slot
)
129 collect
(car cons
))))
131 (defslot-presentation has-a-slot-presentation
(one-of-presentation)
132 ((key :initarg
:key
:accessor key
))
135 (defmethod get-foreign-slot-value ((slot has-a-slot-presentation
) (object t
) (slot-name t
))
136 (slot-value object slot-name
))
138 (defmethod present-slot ((slot has-a-slot-presentation
) instance
)
139 (<:as-html
(presentation-slot-value slot instance
))
141 (<ucw
:select
:accessor
(presentation-slot-value slot instance
) :test
#'equalp
142 (when (allow-nil-p slot
)
143 (<ucw
:option
:value nil
(<:as-html
(none-label slot
))))
144 (dolist (option (get-foreign-instances (presentation slot
) instance
))
145 (setf (instance (presentation slot
)) option
)
146 (<ucw
:option
:value
(get-foreign-slot-value slot option
(key slot
)) (present (presentation slot
)))))
147 (if (presentation-slot-value slot instance
)
149 (setf (instance (presentation slot
)) (presentation-slot-value slot instance
))
150 (present (presentation slot
)))