3 (defaction edit-instance
((self mewa
))
4 (call-presentation (instance self
) :type
:editor
))
7 (defcomponent mewa-one-line-presentation
(mewa one-line-presentation
)
9 (:default-initargs
:attributes-getter
#'one-line-attributes-getter
))
11 (defmethod one-line-attributes-getter ((self mewa
))
12 (or (meta-model:list-keys
(instance self
))))
15 (defcomponent mewa-object-presentation
(mewa ucw
:object-presentation
) ())
17 (defcomponent two-column-presentation
(mewa-object-presentation) ())
19 (defmethod present ((pres two-column-presentation
))
21 (<:table
:class
(css-class pres
)
22 (loop for slot on
(slots pres
) by
#'cddr
24 (<:tr
:class
"presentation-slot-row"
25 (<:td
:class
"presentation-slot-label"
26 (<:as-html
(label (first slot
))))
27 (<:td
:class
"presentation-slot-value"
28 (present-slot (first slot
) (instance pres
)))
30 (<:td
:class
"presentation-slot-label"
31 (<:as-html
(label (second slot
))))
32 (<:td
:class
"presentation-slot-value"
33 (present-slot (second slot
) (instance pres
))))))
34 (render-options pres
(instance pres
))))
38 (defcomponent mewa-list-presentation
(mewa ucw
:list-presentation
)
39 ((ucw::instances
:accessor instances
:initarg
:instances
:initform nil
)
40 (instance :accessor instance
)
41 (select-label :accessor select-label
:initform
"select" :initarg
:select-label
)
42 (selectablep :accessor selectablep
:initform t
:initarg
:selectablep
)))
44 (defaction select-from-listing
((listing mewa-list-presentation
) object index
)
47 (defmethod render-list-row ((listing mewa-list-presentation
) object index
)
48 (<:tr
:class
"item-row"
49 (<:td
:align
"center" :valign
"top"
50 (when (ucw::editablep listing
)
51 (let ((object object
))
52 (<ucw
:input
:type
"submit"
53 :action
(edit-from-listing listing object index
)
54 :value
(ucw::edit-label listing
))))
56 (when (ucw::deleteablep listing
)
58 (<ucw
:input
:type
"submit"
59 :action
(delete-from-listing listing object index
)
60 :value
(ucw::delete-label listing
))))
61 (when (selectablep listing
)
63 (<ucw
:input
:type
"submit"
64 :action
(select-from-listing listing object index
)
65 :value
(select-label listing
)))))
66 (dolist (slot (slots listing
))
67 (<:td
:class
"data-cell" (present-slot slot object
)))
68 (<:td
:class
"index-number-cell")
71 (defmethod get-all-instances ((self mewa-list-presentation
))
76 (defgeneric search-expr
(criteria instance
)
77 (:documentation
"Return ready to apply criteria.
78 What to do with it is backend dependent."))
80 (defmacro def-search-expr
(((self criteria-type
)) (model-expr &body body
))
81 `(defmethod search-expr ((,self
,criteria-type
) instance
)
84 (ucw::slot-name
(ucw::presentation
,self
))
87 (defmethod search-expr ((self ucw
::negated-criteria
) instance
)
88 (when (ucw::criteria self
)
91 (search-expr (ucw::criteria self
) instance
))))
93 (def-search-expr ((self ucw
::string-starts-with
))
94 (meta-model:expr-starts-with
(ucw::search-text self
)))
96 (def-search-expr ((self ucw
::string-ends-with
))
97 (meta-model:expr-ends-with
(ucw::search-text self
)))
99 (def-search-expr ((self ucw
::string-contains
))
100 (meta-model:expr-contains
(ucw::search-text self
)))
102 (def-search-expr ((self ucw
::number-less-than
))
103 (meta-model:expr-
< (ucw::number-input self
)))
105 (def-search-expr ((self ucw
::number-greater-than
))
106 (meta-model:expr-
> (ucw::number-input self
)))
108 (def-search-expr ((self ucw
::number-equal-to
))
109 (meta-model:expr-
= (ucw::number-input self
)))
111 (defcomponent mewa-presentation-search
(ucw::presentation-search
)
112 ((display-results-p :accessor display-results-p
:initarg
:display-results-p
:initform nil
)))
114 (defmethod instance ((self mewa
:mewa-presentation-search
))
115 (instance (ucw::search-presentation self
)))
117 (defmethod search-expr ((self mewa
:mewa-presentation-search
) instance
)
118 (apply #'meta-model
:expr-and instance
119 (mapcan (lambda (c) (let ((e (search-expr c instance
)))
120 (if (listp e
) e
(list e
))))
121 (ucw::criteria self
))))
123 (defmethod search-query ((self mewa
:mewa-presentation-search
))
124 (search-expr self
(instance self
)))
126 (defmethod valid-instances ((self mewa
:mewa-presentation-search
))
127 (meta-model:select-instances
(instance self
) (search-query self
)))
129 (defmethod get-all-instances ((self mewa-presentation-search
))
130 (meta-model:select-instances
(instance self
)))
132 (defmethod ok ((self mewa-presentation-search
) &optional arg
)
133 (declare (ignore arg
))
134 (setf (ucw::instances
(ucw::list-presentation self
)) (valid-instances self
))
135 (setf (display-results-p self
) t
))
137 (defmethod render-on ((res response
) (self mewa-presentation-search
))
138 ;(<:as-html (search-query self))
139 (ucw::render-criteria res self
)
140 (<ucw
:input
:type
"submit" :value
"Search" :action
(ok self
))
141 (when (display-results-p self
)
142 (let ((listing (ucw::list-presentation self
)))
144 (slot-value listing
'ucw
::calling-component
) (slot-value self
'ucw
::calling-component
)
145 (slot-value listing
'ucw
::place
) (slot-value self
'ucw
::place
)
146 (slot-value listing
'ucw
::continuation
) (slot-value self
'ucw
::continuation
))
148 (render-on res listing
))))
151 (defcomponent dont-show-unset-slots
()())
153 (defmethod slots :around
((self dont-show-unset-slots
))
154 (remove-if-not #'(lambda (s) (let ((s (presentation-slot-value s
(instance self
))))
155 (and s
(not (equal "" s
)))))