factor out creating of input page
This commit is contained in:
parent
b12070e349
commit
4af92bc379
|
@ -1,43 +1,44 @@
|
|||
(define-structure surflet surflet-interface
|
||||
(open surflets
|
||||
url
|
||||
scheme-with-scsh)
|
||||
(begin
|
||||
|
||||
(define number-input-field (make-number-input-field))
|
||||
|
||||
(define (create-input-page title input-text)
|
||||
(lambda (new-url)
|
||||
`(html (title ,title)
|
||||
(body
|
||||
(h2 ,title)
|
||||
(p
|
||||
(surflet-form ,new-url
|
||||
,input-text " "
|
||||
,number-input-field
|
||||
,(make-submit-button)))
|
||||
(hr)
|
||||
(p (URL "/" "Return to main menu.") (br)
|
||||
(URL "add-surflet.scm" "Start new calculation."))))))
|
||||
|
||||
(define (get-number title input-text)
|
||||
(let* ((result
|
||||
(send-html/suspend
|
||||
(lambda (new-url)
|
||||
`(html (title ,title)
|
||||
(body
|
||||
(h2 ,title)
|
||||
(p
|
||||
(surflet-form ,new-url
|
||||
,input-text " "
|
||||
,number-input-field
|
||||
,(make-submit-button)))
|
||||
(hr)
|
||||
(p (URL "/" "Return to main menu.") (br)
|
||||
(URL "add-surflet.scm" "Start new calculation.")))))))
|
||||
(let* ((result (send-html/suspend
|
||||
(create-input-page title input-text)))
|
||||
(bindings (get-bindings result))
|
||||
(number (input-field-value number-input-field bindings)))
|
||||
(if number
|
||||
number
|
||||
(get-number title "Please enter a valid number."))))
|
||||
|
||||
(define (get-number1)
|
||||
(get-number "Calculation - Step one" "First number:"))
|
||||
(define (get-number-1)
|
||||
(get-number "Addition - Step one" "First number:"))
|
||||
|
||||
(define (get-number2)
|
||||
(get-number "Calculation - Step two" "Second number:"))
|
||||
(define (get-number-2)
|
||||
(get-number "Addition - Step two" "Second number:"))
|
||||
|
||||
(define (main req)
|
||||
(send-html
|
||||
`(html (title "Result")
|
||||
(body (h2 "Result")
|
||||
(p ,(number->string (+ (get-number1) (get-number2)))
|
||||
(p ,(+ (get-number-1) (get-number-2))
|
||||
(hr)
|
||||
(p (URL "add-surflet.scm" "Make new calculation.") (br)
|
||||
(URL "javascript:history.go(-2)" "New calculation (same session)")
|
||||
|
|
Loading…
Reference in New Issue