2 ;V URL: /matrix_select_contents
3 ;V Return html code for the dropdown menu V
4 ;V (html's "select" element) to list all V
6 (defun matrix-select-contents ()
7 (with-html-output-to-string
10 (dolist (v *saved-tuples
*)
12 (s) (:option
(princ v s
))))
13 (dolist (m *saved-matrices
*)
15 (s) (:option
(princ m s
))))))
17 ;V URL: /post_matrix_input
18 ;V Read input from client, store matrix.V
19 (defun get-matrix-input
20 (&aux
(cols (read-from-string (parameter "cols"))))
23 ;V If there's only one column, user input a vector.V
26 :dim
(read-from-string (parameter "rows"))
27 :elems
(mapcar #'car
(read-from-string
28 (parameter "matrix"))))
31 :dimcodom
(read-from-string (parameter "rows"))
32 :elems
(read-from-string (parameter "matrix")))))
33 (matrix-select-contents))
35 ;V URL: /matrix_request
36 ;V Pass javascript code back to the client for eval, V
37 ;V which stores the matrix's elements in a 2D array V
38 ;V named /matrix/. Also pass code that sets variables V
39 ;V named /rows/ and /cols/ to their obvious values. V
41 (&aux
(name (parameter "name"))
42 (s (make-string-output-stream)))
43 "Return javascript code for storing"
44 ;^ the named matrix in the variable: /matrix/ ^
46 (let ((m (symbol-value
47 (find-symbol name
:lineal.client-vars
))))
48 ;V State the rows and columns of the matrix, V
49 ;V store the list of rows in /matrows/ V
52 (format s
"rows = ~D; cols = ~D;"
55 (setq matrows
(mtrix-elems m
)))
57 (format s
"rows = ~D; cols = ~D;"
59 (setq matrows
(mapcar #'list
(tuple-elems m
))))
60 (otherwise (throw 'unknown-variable name
))))
61 (princ "matrix = new Array(" s
)
64 :and raystr
= "new Array("
67 :do
(format s
"\"~D\"" (car row
))
70 :for elem
:in
(cdr row
)
71 :do
(format s
",\"~D\"" elem
))
74 (get-output-stream-string s
)))
77 ;V The matrix input page.V
78 (defun matrix-input-code
79 (&aux
(rows (parameter "rows"))
80 (cols (parameter "cols")))
81 (unless (integerp rows
) (setq rows
2))
82 (unless (integerp cols
) (setq cols
2))
83 (with-html-output-to-string
87 (jsfile s
"matrix-edit")
88 (jsfile s
"connects"))
90 (:div
(:a
:href
"/" "Main") " Page" :br
96 :onchange
(ps-inline (select-name-change))
97 (princ (matrix-select-contents) s
))
98 " " (:input
:type
"text" :onfocus
"select()" :id
"nameField")
99 " " (:button
:tabindex
"-1"
100 :onclick
(ps-inline (recall-matrix))
104 :action
(ps-inline (reset-fields))
106 (:tr
(:td
"Rows") (:td
"Columns") :td
)
107 (:tr
(:td
(:input
:id
"rowField" :onfocus
"select()" :value rows
))
108 (:td
(:input
:id
"colField" :onfocus
"select()" :value cols
))
109 (:td
(:button
:tabindex
"-1" "Resize!" )))))
112 :action
(ps-inline (send-matrix))
113 (:div
:id
"fieldDiv")
114 (:div
(:button
"Update")))
115 (:div
:id
"outDiv" "")
118 (setf name-field
(.get-element-by-id document
"nameField")
119 name-select
(.get-element-by-id document
"nameSelect")
120 row-field
(.get-element-by-id document
"rowField")
121 col-field
(.get-element-by-id document
"colField")
122 field-div
(.get-element-by-id document
"fieldDiv")
123 out-div
(.get-element-by-id document
"outDiv"))