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