Major patch touching a lot, representing the new lol. is mostly drop-in backwards...
[clinton/lisp-on-lines.git] / src / dojo-attributes.lisp
1 (in-package :lisp-on-lines)
2
3 (deflayer dojo)
4
5 (define-layered-class
6 attribute :in-layer dojo ()
7 ((dojo-type :accessor dojo-type :initarg :dojo-type :initform nil :special t)))
8
9
10 (defgeneric display-as-dojo-type (type attribute object component))
11
12 (defdisplay
13 :in-layer dojo :after ((attribute standard-attribute) object)
14 (when (dojo-type attribute)
15 (display-as-dojo-type (dojo-type attribute) attribute object self)))
16
17 (defcomponent dojo-test (window-component)
18 (
19 (results :accessor results :initarg :results)))
20
21 (defmethod render ((self dojo-test))
22 (<:as-is (js:js* `(array
23 ,@(loop for r in (results self)
24 for n upfrom 0
25 collect `(array ,
26 (with-output-to-string (s)
27 (yaclml:with-yaclml-stream s
28 (display self r :type 'as-string))) ,n))))))
29
30
31 (defmethod display-as-dojo-type ((type (eql 'combo-box)) attribute object component)
32
33 (let* ((search-function (search-function attribute))
34 (select-function (select-function attribute))
35 (select-callback (ucw::make-new-callback (lambda (x)
36 (warn "setting index to ~A" (parse-integer x))
37 (funcall select-function
38 (parse-integer x))))))
39 "The combo box widget"
40 (<ucw:script
41 `(dojo.require "dojo.*")
42 `(dojo.require "dojo.widget.*")
43 `(dojo.require "dojo.widget.html.ComboBox")
44 (js:with-unique-js-names (element combo-box)
45
46 `(dojo.add-on-load
47 (lambda ()
48 (setf ,element (dojo.by-id ,(id attribute)))
49 (setf ,combo-box
50 (dojo.widget.from-script
51 "ComboBox"
52 (create
53 :data-url (+ , (lol::make-action-url
54 component
55 (call-component
56 (context.window-component *context*)
57 (make-instance 'dojo-test
58 :results
59 (funcall search-function
60 (attribute-value object attribute)))))
61 "&"
62 ,(escape-as-uri (callback attribute))
63 "=%{searchString}")
64 :mode "remote")
65 ,element))
66 ((slot-value ,combo-box 'set-value) (slot-value ,element 'value))
67 (dojo.event.connect
68 ,combo-box "selectOption"
69 (lambda ()
70 (setf (slot-value ,element 'value)
71 (slot-value ,combo-box 'selected-result))
72 (dojo.io.bind
73 (create
74 :url (+ ,(lol::make-action-url
75 component
76 nil)
77 "&"
78 ,(escape-as-uri (callback attribute))
79 "="
80 (slot-value ,combo-box 'selected-result)
81 "&"
82 ,select-callback
83 "="
84 (slot-value ,combo-box 'combo-box-selection-value.value))))))))))))
85