(define-structure surflet surflet-interface (open scheme-with-scsh surflets surflets/callbacks ;make-callback surflets/outdaters surflets/error surflet-handler/admin handle-fatal-error let-opt srfi-1 ;filter-map 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 (lambda (_) (make-checkbox)) table-elements)) (action-title "Choose an action") (select (make-select (cons action-title actions) '(@ (size 1)))) (req (send-html/suspend (lambda (new-url) `(html (title ,title) (body ,header (surflet-form ,new-url (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)) (action (input-field-value select bindings))) (if (string=? action action-title) (select-table title header header-row table-elements selector actions footer) (values action (filter-map (lambda (checkbox table-element) (if (input-field-value checkbox bindings) table-element #f)) checkboxes table-elements))))) (define (unload-surflets outdated? surflet-names) (if-outdated outdated? (show-outdated (make-callback surflets)) (for-each unload-surflet surflet-names))) (define (no-surflets) `(p "Currently, there are no SUrflets loaded " (url ,(make-callback surflets) "(reload)."))) (define (surflets req . maybe-update-text) (let* ((update-text (:optional maybe-update-text "")) (loaded-surflets (sort-list! (get-loaded-surflets) string? entry1 entry2) (session-id? entry1 entry2) (session-surflet-name