2003-01-19 11:57:27 -05:00
|
|
|
(define-structure surflet surflet-interface
|
2002-12-02 03:39:10 -05:00
|
|
|
(open scheme-with-scsh
|
2003-01-19 11:57:27 -05:00
|
|
|
surflets
|
2003-04-16 08:32:24 -04:00
|
|
|
receiving
|
|
|
|
srfi-1
|
|
|
|
srfi-13
|
|
|
|
srfi-14
|
2003-04-14 04:30:27 -04:00
|
|
|
surflets/utilities
|
|
|
|
surflets/callbacks
|
2002-09-13 03:21:19 -04:00
|
|
|
httpd-responses)
|
|
|
|
(begin
|
2003-04-16 08:32:24 -04:00
|
|
|
(define global 0)
|
2003-03-09 15:15:08 -05:00
|
|
|
|
2003-04-16 08:32:24 -04:00
|
|
|
(define selections (cons '("a" "b" "c")
|
|
|
|
'("Andreas" "Bernd" "Clara")))
|
|
|
|
(define radio-elements '(1 2 3 "a" *))
|
2003-07-08 17:22:06 -04:00
|
|
|
(define select (make-annotated-select
|
|
|
|
(map make-annotated-select-option
|
2003-04-16 08:32:24 -04:00
|
|
|
(car selections)
|
|
|
|
(cdr selections))
|
|
|
|
#t '(@ (size 2))))
|
2003-07-08 17:22:06 -04:00
|
|
|
(define select2 (make-select (car selections)))
|
|
|
|
(define text (make-text-field "yoho"))
|
|
|
|
(define number (make-number-field 23))
|
|
|
|
(define hidden (make-hidden-field "value"))
|
|
|
|
(define password (make-password-field "asdf"))
|
|
|
|
(define textarea (make-textarea "This
|
2003-04-16 08:32:24 -04:00
|
|
|
is
|
|
|
|
a
|
|
|
|
test"))
|
2003-07-08 17:22:06 -04:00
|
|
|
(define radio (make-annotated-radio-group))
|
2003-04-16 08:32:24 -04:00
|
|
|
(define radios (map radio radio-elements))
|
2003-07-08 17:22:06 -04:00
|
|
|
(define checkbox (make-annotated-checkbox "hooray!"))
|
2002-10-04 09:56:46 -04:00
|
|
|
|
2003-05-22 09:32:49 -04:00
|
|
|
(define submit (make-submit-button))
|
|
|
|
(define image (make-image-button "/img/221.gif"))
|
|
|
|
(define reset (make-reset-button))
|
|
|
|
|
2003-04-16 08:32:24 -04:00
|
|
|
(define (translate-line-breaks text)
|
|
|
|
(let lp ((result '())
|
|
|
|
(text text))
|
|
|
|
(let ((index (string-index text char-set:iso-control)))
|
|
|
|
(if index
|
|
|
|
(lp (cons '(br)
|
|
|
|
(cons (substring/shared text 0 index) result))
|
|
|
|
;; +2, as we probably have cr+lf
|
|
|
|
(substring/shared text (+ index 2)))
|
|
|
|
(reverse (cons text result))))))
|
|
|
|
|
|
|
|
(define (cb-result req arg)
|
|
|
|
(send-html
|
|
|
|
`(html (title "Result")
|
|
|
|
(body (h2 "Result")
|
|
|
|
(p "Returned via callback with arg" (br)
|
|
|
|
,(format #f "~s" arg))
|
|
|
|
(hr)
|
|
|
|
(p (url "test.scm" "Test again.") (br)
|
|
|
|
(url "/" "Return to main menu."))))))
|
|
|
|
|
|
|
|
(define an-cb (make-annotated-callback cb-result))
|
|
|
|
(define addr (make-annotated-address))
|
2002-09-24 12:56:00 -04:00
|
|
|
(define (main req)
|
2003-04-16 08:32:24 -04:00
|
|
|
(set! global (+ 1 global))
|
|
|
|
(let* ((req (send-html/suspend
|
|
|
|
(lambda (new-url)
|
2003-07-04 10:46:31 -04:00
|
|
|
`((plain-html "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">")
|
|
|
|
(html
|
|
|
|
(head
|
|
|
|
(meta (@ (http-equiv "Content-Type")
|
|
|
|
(content "text/html; charset=ISO-8859-15")))
|
|
|
|
(title "Test"))
|
2003-04-16 08:32:24 -04:00
|
|
|
(body
|
|
|
|
(h1 "This is from SUrflet")
|
|
|
|
(p "called " ,global " times")
|
2003-07-04 10:46:31 -04:00
|
|
|
(p "Choose an annotated address:")
|
|
|
|
(ul
|
2004-02-02 12:49:37 -05:00
|
|
|
(li (url ,(addr new-url 13) "ab=ba"))
|
2003-07-04 10:46:31 -04:00
|
|
|
(li (url ,(addr new-url "be<ta") "be<ta"))
|
|
|
|
(li (url ,(addr new-url) "<nothing>")))
|
|
|
|
(p "Or choose an annotated callback")
|
|
|
|
(ul
|
|
|
|
(li (url ,(an-cb 13) "13"))
|
|
|
|
(li (url ,(an-cb '(1 2 3)) "'(1 2 3)"))
|
|
|
|
(li (url ,(an-cb "hello") "hello"))
|
|
|
|
(li (url ,(an-cb #f) "#f")))
|
|
|
|
(p "Or choose an input field.")
|
|
|
|
(surflet-form
|
|
|
|
,new-url
|
|
|
|
POST
|
|
|
|
(table
|
|
|
|
(tr (td "Selection:") (td ,select))
|
|
|
|
(tr (td "Selection2:") (td ,select2))
|
|
|
|
(tr (td "Simple text: ") (td ,text))
|
|
|
|
(tr (td "Number: " ) (td ,number))
|
|
|
|
(tr (td "Hidden: " ) (td ,hidden))
|
|
|
|
(tr (td "Password: " ) (td ,password))
|
|
|
|
(tr (td "Textarea: " ) (td ,textarea))
|
|
|
|
(tr (td "Radio:")
|
|
|
|
(td ,(zip radios
|
|
|
|
(map (lambda (elem)
|
|
|
|
(list (format #f "~%~s" elem)
|
|
|
|
'(nbsp) '(nbsp)))
|
|
|
|
radio-elements))))
|
|
|
|
(tr (td "Checkbox:") (td ,checkbox)))
|
|
|
|
,submit ,reset (br) ,image)
|
2003-04-16 08:32:24 -04:00
|
|
|
(hr)
|
2003-07-04 10:46:31 -04:00
|
|
|
(p (url "/" "Return to main menu."))))))))
|
2003-03-09 15:15:08 -05:00
|
|
|
(bindings (get-bindings req))
|
2003-04-16 08:32:24 -04:00
|
|
|
(selected (input-field-value select bindings))
|
|
|
|
(selected2 (input-field-value select2 bindings))
|
|
|
|
(text-entered (input-field-value text bindings))
|
|
|
|
(number-entered (input-field-value number bindings))
|
|
|
|
(hidden-value (input-field-value hidden bindings))
|
|
|
|
(password-text (input-field-value password bindings))
|
|
|
|
(textarea-text (input-field-value textarea bindings))
|
|
|
|
(radio-result (input-field-value (radio #f) bindings))
|
|
|
|
(checkbox-result (input-field-value checkbox bindings))
|
2003-05-22 09:32:49 -04:00
|
|
|
(submit-result (returned-via? submit bindings))
|
|
|
|
(reset-result (returned-via? reset bindings))
|
|
|
|
(image-result (returned-via image bindings))
|
2003-03-09 15:15:08 -05:00
|
|
|
(result
|
|
|
|
(cond
|
|
|
|
((returned-via? addr bindings) =>
|
|
|
|
(lambda (string)
|
|
|
|
(format #f "returned via annotated string ~s" string)))
|
|
|
|
(else
|
2003-07-08 17:22:06 -04:00
|
|
|
(set-text-field-value! text text-entered)
|
2003-04-16 08:32:24 -04:00
|
|
|
(only-select-selected! select selected (cdr selections))
|
|
|
|
(only-select-selected! select2 (list selected2) (car selections))
|
|
|
|
(if number-entered
|
2003-07-08 17:22:06 -04:00
|
|
|
(set-number-field-value! number number-entered))
|
|
|
|
(set-hidden-field-value!
|
2003-04-16 08:32:24 -04:00
|
|
|
hidden
|
|
|
|
(string-append "value" (number->string global)))
|
2003-07-08 17:22:06 -04:00
|
|
|
(set-password-field-value! password password-text)
|
|
|
|
(set-textarea-value! textarea textarea-text)
|
2003-04-16 08:32:24 -04:00
|
|
|
(if radio-result
|
|
|
|
(begin
|
2003-07-08 17:22:06 -04:00
|
|
|
(map uncheck-radio! radios)
|
|
|
|
(check-radio!
|
2003-04-16 08:32:24 -04:00
|
|
|
(list-ref radios
|
|
|
|
(list-index (lambda (a) (equal? a radio-result))
|
|
|
|
radio-elements)))))
|
|
|
|
(if checkbox-result
|
2003-07-08 17:22:06 -04:00
|
|
|
(check-checkbox! checkbox)
|
|
|
|
(uncheck-checkbox! checkbox))
|
2003-05-22 09:32:49 -04:00
|
|
|
`(p ,(cond
|
|
|
|
(image-result (format #f "Returned via image ~s" image-result))
|
|
|
|
(submit-result "Returned via submit")
|
|
|
|
(else "Don't know how you did return.")) (br)
|
2003-04-16 08:32:24 -04:00
|
|
|
"Bindings were: " ,(format #f "~s" bindings) (br)
|
|
|
|
(table
|
|
|
|
(@ (valign "top"))
|
|
|
|
(tr (td "Selected: ") (td ,(format #f "~s" selected)))
|
|
|
|
(tr (td "Selected2:") (td ,(format #f "~s" selected2)))
|
|
|
|
(tr (td "Text entered:") (td ,(format #f "~s" text-entered)))
|
|
|
|
(tr (td "Number entered:")
|
|
|
|
(td ,(if number-entered
|
|
|
|
number-entered
|
|
|
|
"no valid number")))
|
|
|
|
(tr (td "Hidden:") (td ,hidden-value))
|
|
|
|
(tr (td "Plain password:") (td ,password-text ))
|
|
|
|
(tr (td "Textarea:")
|
|
|
|
(td #\" ,@(translate-line-breaks textarea-text) #\"))
|
|
|
|
(tr (td "Radio:") (td ,(format #f "~s" radio-result)))
|
|
|
|
(tr (td "Checkbox:") (td ,(format #f "~s" checkbox-result)))))
|
|
|
|
))))
|
|
|
|
(set! global (+ 1 global))
|
|
|
|
(send-html/suspend
|
|
|
|
(lambda (continue)
|
|
|
|
`(html (body (h1 "Result")
|
|
|
|
(p "called " ,global " times")
|
|
|
|
,result (br)
|
|
|
|
(url ,continue "show results again") (br)
|
|
|
|
(url ,(make-callback main) "continue testing")
|
|
|
|
(font (@ (size "small"))
|
|
|
|
"(Note: This is not a browser history link)")
|
|
|
|
(hr)
|
|
|
|
(p (url "test.scm" "Test again.") (br)
|
|
|
|
(url "/" "Return to main menu."))))))
|
2002-12-02 03:39:10 -05:00
|
|
|
|
2003-04-16 08:32:24 -04:00
|
|
|
(send-html/finish
|
|
|
|
`(html (body (h1 "Result 2")
|
|
|
|
(p "called " ,global " times")
|
|
|
|
,(format #f "~s" (get-bindings req))
|
|
|
|
(hr)
|
|
|
|
(p (url "test.scm" "Test again.") (br)
|
|
|
|
(url "/" "Return to main menu.")))))))
|
2002-10-26 11:40:26 -04:00
|
|
|
|
2003-04-16 08:32:24 -04:00
|
|
|
(define (only-select-selected! sel-if selected indices)
|
|
|
|
(for-each (lambda (index)
|
2003-07-08 17:22:06 -04:00
|
|
|
(unselect-select-option! index sel-if))
|
2003-04-16 08:32:24 -04:00
|
|
|
(iota (length (cdr selections))))
|
|
|
|
(for-each (lambda (selected)
|
2003-07-08 17:22:06 -04:00
|
|
|
(select-select-option!
|
2003-04-16 08:32:24 -04:00
|
|
|
(list-index (lambda (s) (string=? s selected))
|
|
|
|
indices)
|
|
|
|
sel-if))
|
|
|
|
selected))
|
2002-10-26 11:40:26 -04:00
|
|
|
|
2002-10-04 09:56:46 -04:00
|
|
|
))
|