(define-structure surflet surflet-interface (open scheme-with-scsh surflets surflets/callbacks ;make-callback surflets/outdaters surflets/ids surflets/error surflet-handler/admin handle-fatal-error let-opt srfi-1 ;filter-map, last sort ) (begin (define remove-surflet-path (let ((regexp (rx ,(file-name-as-directory (options-surflet-path)) (submatch (* any))))) (lambda (file-name) (let ((match (regexp-search regexp file-name))) (if match (match:substring match 1) file-name))))) ;; returns two values: an action to perform out of ACTIONS and a ;; list of selected elements out of TABLE-ELEMENTS. (define (select-table title header header-row table-elements selector actions footer) (let* ((checkboxes (map make-annotated-checkbox table-elements)) (select (make-annotated-select actions #f '(@ (size 1)))) (req (send-html/suspend (lambda (new-url) `(html (title ,title) (body ,header (surflet-form ,new-url POST (table ,@(cons '(th) header-row) ,@(map (lambda (checkbox table-element) `(tr (td ,checkbox) ,@(selector table-element))) checkboxes table-elements)) (p ,select ,(make-submit-button "Do it"))) ,footer))))) (bindings (get-bindings req)) (selected (filter-map (lambda (checkbox) (input-field-value checkbox bindings)) checkboxes)) (action (input-field-value select bindings))) (action req selected))) (define (unload-surflets outdated?) (lambda (req surflet-names) (if (null? surflet-names) (show-surflets req "You must choose at least one element.") (if-outdated outdated? (show-outdated (make-callback show-surflets)) (begin (for-each unload-surflet surflet-names) (show-surflets req "SUrflets unloaded.")))))) (define (no-surflets callback) `(p "Currently, there are no SUrflets loaded " (url ,(callback show-surflets) "(reload)") ", but there may be " (url ,(callback show-sessions) "sessions") " you want to administer.")) (define (choose-an-action show) (lambda (req _) (show req "Choose an action."))) (define (show-surflets req . maybe-update-text) (let* ((update-text (:optional maybe-update-text "")) (loaded-surflets (sort-list! (get-loaded-surflets) string? session1 session2) (session-surflet-name? session1 session2) (session-id