Massive patch to compile with modern versions of the libraries. This is only 1/2...
[clinton/lisp-on-lines.git] / src / attributes / standard-attributes.lisp
CommitLineData
7733a777
DC
1(in-package :lisp-on-lines)
2
1cc831d4 3
4;TODO: get rid of this.
5(defun attribute.name (attribute)
6 (attribute-name attribute))
7
8
e1645f63 9;;;; A few layers related to attributes
2b0fd9c8
DC
10(deflayer omit-nil-attributes)
11
12(defdisplay :in-layer omit-nil-attributes
13 :around ((attribute standard-attribute) object)
14 (when (attribute-value object attribute)
15 (call-next-method)))
16
1cc831d4 17;;;; Labels
e1645f63 18(deflayer show-attribute-labels)
2b0fd9c8 19
1cc831d4 20(defattribute attribute-label (attribute)
21 ()
22 (:default-properties
23 :attribute nil))
24
25(defdisplay
26 ((label attribute-label) object)
27 (<:label
28 :class "lol-label"
29 (<:as-html (or (label (attribute label))
30 (attribute-name (attribute label)) " ")
31 " ")))
32
33(defvar *attribute-label-attribute*
34 (make-instance 'attribute-label))
35
e1645f63 36(defdisplay
37 :in-layer show-attribute-labels
e4f96295 38 :around ((attribute standard-attribute) object)
1cc831d4 39 (display-attribute *attribute-label-attribute* object :attribute attribute)
40 (call-next-method))
e1645f63 41
42(deflayer use-pretty-labels)
43
44(define-layered-method label
45 :in-layer use-pretty-labels
46 :around (standard-attribute)
47 (let ((label (call-next-method)))
48 (when label
49 (string-capitalize
50 (substitute #\Space #\- label)))))
51
e4f96295 52(deflayer inspect-attributes)
53
54(defdisplay :in-layer inspect-attributes
55 :around ((attribute standard-attribute) object)
56 (call-next-method)
1cc831d4 57 (<ucw:a :action-body (ucw::call-inspector self attribute)
e4f96295 58 :title
59 (strcat "Inspect "
1cc831d4 60 (attribute-name attribute) ":"
61 (description-type attribute) ":"
e4f96295 62 (type-of attribute))
63 (<:as-html "(i)")))
64
65;;;; Functional attributes
66(defattribute display-attribute ()
67 ((display-arguments
68 :accessor display-arguments
69 :initarg :display
70 :special t
71 :initform nil))
72 (:type-name display)
e1645f63 73 (:documentation "Apply the display function to this object"))
2b0fd9c8 74
e4f96295 75(defdisplay ((attribute display-attribute) object)
e1645f63 76 (apply #'display self (attribute-value object attribute)
e4f96295 77 (display-arguments attribute)))
2b0fd9c8 78
e4f96295 79(defattribute function-attribute ()
80 ((function :accessor function-of
81 :initarg :function
82 :initform #'funcall
83 :special t))
84 (:type-name function)
85 (:documentation ""))
2b0fd9c8 86
e4f96295 87(defdisplay ((function function-attribute) object)
88 (funcall (function-of function)
89 (attribute-value object function)))
2b0fd9c8 90
2b0fd9c8 91
e4f96295 92;;;; Attribute Grouping
93(defattribute attribute-group ()
9af22ce3 94 ()
a4e6154d 95 (:default-properties
e4f96295 96 :group nil)
97 (:type-name group))
e1645f63 98
e4f96295 99(defdisplay ((group attribute-group) object)
100 (apply #'display self object
101 :attributes (attributes group)
102 (group group)))
e1645f63 103
fb04c0a8 104
105(defattribute select-attribute (display-attribute)
106 ()
107 (:default-properties
108 :test 'meta-model::generic-equal
109 :options-getter (constantly nil))
110 (:type-name select))
111
112(defdisplay ((attribute select-attribute) object)
113 (<ucw:select
114 :accessor (attribute-value object attribute)
115
116 :test (test attribute)
117 (dolist* (obj (funcall (options-getter attribute) object))
118 (<ucw:option
119 :value obj
120 (apply #'display* obj (display-arguments attribute))))))
121
e4f96295 122;;;; * Base Types
e1645f63 123
e4f96295 124(defattribute base-attribute ()
125 ()
126 (:default-properties
127 :default-value ""))
e1645f63 128
e4f96295 129(defdisplay ((base base-attribute) object)
130 (<:as-html (attribute-value object base)))
e1645f63 131
fb04c0a8 132(defattribute base-attribute ()
e4f96295 133 ()
134 (:in-layer editor)
135 (:default-properties
136 :callback nil
137 :default-value nil
fb04c0a8 138 :default-value-predicate #'null
139 :dom-id (js:gen-js-name-string :prefix "_ucw_")
140 :input-size nil))
e1645f63 141
e4f96295 142(define-layered-function display-value (attribute value)
143 (:method (attribute value)
144 (if (funcall (default-value-predicate attribute) value)
145 (default-value attribute)
146 value)))
e1645f63 147
148(defdisplay
e4f96295 149 :in-layer editor ((field base-attribute) object)
150 (LET ((value (attribute-value (object field) field)))
151 (<:input
152 :NAME
153 (callback field)
154 :VALUE (escape-as-html (strcat (display-value field value)))
155 :TYPE
156 "text"
157 :ID
158 (DOM-ID FIELD)
159 :SIZE
fb04c0a8 160 (INPUT-SIZE FIELD))))
e1645f63 161
a4e6154d
DC
162(defdisplay
163 :in-layer editor :around ((string base-attribute) object)
e4f96295 164 (dletf (((callback string)
165 (or (callback string)
1cc831d4 166 (ucw::register-callback
e4f96295 167 #'(lambda (val)
168 (setf (attribute-value object string) val)))))
e1645f63 169 ((object string) object))
a4e6154d 170 (call-next-method)))
2b0fd9c8 171
a4e6154d
DC
172;;;; Strings
173
e1645f63 174(defattribute string-attribute (base-attribute)
a4e6154d 175 ()
9af22ce3
DC
176 (:type-name string)
177 (:default-properties
2b0fd9c8
DC
178 :escape-html-p t
179 :size nil
e4f96295 180 :max-length nil
181 :default-value ""))
9af22ce3 182
1cc831d4 183
184#|
185
2b0fd9c8
DC
186(defdisplay :in-layer omit-nil-attributes
187 :around ((attribute string-attribute) object)
188 (when (< 0 (length (attribute-value object attribute)))
189 (call-next-method)))
190
2b0fd9c8 191;;;; default
a4e6154d
DC
192(defdisplay :in-layer viewer
193 ((string string-attribute) object)
2b0fd9c8 194 (if (escape-html-p string)
9af22ce3
DC
195 (<:as-html (attribute-value object string))
196 (<:as-is (attribute-value object string))))
197
198
2b0fd9c8 199;;;; editor
1cc831d4 200#+nil (defattribute string-attribute (base-attribute)
2b0fd9c8
DC
201 ()
202 (:in-layer editor)
203 (:default-properties
204 :callback nil))
205
a4e6154d 206
2b0fd9c8
DC
207(defattribute string-search-attribute (string-attribute)
208 ()
209 (:default-properties
210 ;; the func that find search results
211
212 :search-action #'(lambda ()
213 (with-call/cc
214 nil))
215 ;; when chosing from a list of results, this function selects one.
216 :select-function (constantly t))
217 (:type-name string-search))
218
219(defdisplay
220 :in-layer editor :after ((search string-search-attribute) object)
a4e6154d
DC
221 (<:input
222 :TYPE "submit"
223 :VALUE "search"
224 :ONCLICK
225 (JS:JS-INLINE*
226 `(PROGN
227 (IT.BESE.UCW::SET-ACTION-PARAMETER
228 ,(IT.BESE.UCW::MAKE-NEW-ACTION
229 (IT.BESE.UCW::CONTEXT.CURRENT-FRAME *CONTEXT*)
230 (search-action search)))
231 (RETURN T)))))
2b0fd9c8
DC
232
233;;;; textarea
234
235(defattribute text-attribute (string-attribute)
a4e6154d
DC
236 ()
237 (:type-name text))
2b0fd9c8
DC
238
239(defdisplay :in-layer editor ((string text-attribute) object)
240 (<:textarea
e4f96295 241 :id (dom-id string)
2b0fd9c8 242 :name (callback string)
a4e6154d 243 (or (attribute-value object string) "")))
2b0fd9c8
DC
244
245
246
247;;;; WALL-TIME
248
249(defattribute wall-time-attribute (string-attribute)
250 ()
251 (:type-name clsql-sys:wall-time))
252
253(define-layered-method attribute-value (object (attribute wall-time-attribute))
254 (let ((date (call-next-method)))
255 (when date (multiple-value-bind (y m d) (clsql:time-ymd date)
256 (format nil "~a/~a/~a" m d y)))))
257
258(defdisplay
259 ((time wall-time-attribute) object)
260 (<:as-html (attribute-value object time)))
261
262
263
7733a777 264(defattribute image ()
a4e6154d
DC
265 ()
266 (:default-properties
267 :css-class "lol-image"
268 :prefix "images/"))
7733a777 269
2b0fd9c8 270(defdisplay ((buttons (eql 'image-editor-buttons)) object)
60a24293
DC
271 (<ucw:a :action (ok component object)
272 (<:as-html "select this image")))
273
2b0fd9c8 274(defdisplay ((image image) object)
7733a777 275 (<:img
a4e6154d 276 :class (or (css-class image) "lol-image")
7733a777 277 :src (arnesi:strcat
a4e6154d 278 (or (prefix image) "images/")
7733a777
DC
279 (escape-as-uri
280 (attribute-value object image)))))
281
2b0fd9c8
DC
282(defdisplay
283 :in-layer editor ((image image) object)
284
60a24293 285 (<:div
2b0fd9c8 286 :class "lol-image-thumbnails"
1cc831d4 287 (<:as-html "imagie"))) |#
60a24293 288
7733a777
DC
289
290
291
292
293