aboutsummaryrefslogtreecommitdiff
path: root/module/calp/html/view/search.scm
blob: 7b991104d2cd8f07bb2a0446ee0f9f1c013a5559 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
(define-module (calp html view search)
  :use-module (hnh util)
  :use-module (vcomponent)
  :use-module (vcomponent util search)
  :use-module ((ice-9 pretty-print) :select (pretty-print))
  :use-module ((web uri-query) :select (encode-query-parameters))
  :use-module ((calp html components)
               :select (xhtml-doc include-css))
  :use-module ((calp html vcomponent)
               :select (compact-event-list))
  :use-module (calp translation)
  :export (search-result-page)
  )

;; Display the result of a search term, but doesn't do any searching
;; on its own.
;; 
;; @var{errors} : #f or SXML object to display instead of search result
;; @var{has-query?} : Does search-term actually contain anything, or should
;;         it be handled as a blank query?
;; @var{search-term} : What was searched, as an SEXP
;; @var{search-result} : The list of matched events
;; @var{page} : Which page we are on
;; @var{paginator} : A paginator object
(define (search-result-page
         errors has-query? search-term search-result page paginator)
  (xhtml-doc
   (@ (lang sv))
   (head (title ,(G_ "Search results"))
         ,(include-css "/static/style.css"))
   (body
    (a (@ (href ("/today"))) ,(G_ "Show today"))
    (h2 ,(G_ "Search term"))
    (form
     (pre (textarea (@ (name "q") (rows 5) (spellcheck false)
                       (style "width:100%"))
                    ,(when has-query?
                       (with-output-to-string
                         (lambda () (pretty-print search-term))))))
     (label (@ (for "onlyfuture")) ,(G_ "limit to future occurences"))
     (input (@ (name "onlyfuture") (id "onlyfuture") (type checkbox)))
     (input (@ (type submit))))
    ,@(if errors
          `((h2 ,(G_ "Error searching"))
            (div (@ (class "error"))
                 (pre ,errors)))
          `((h2 ,(format #f (G_ "Result (page ~a)") page))
            (ul ,@(compact-event-list search-result))
            (div (@ (class "paginator"))
                 ,@(paginator->list
                    paginator
                    (lambda (p) (if (= p page)
                               `(span ,p)
                               `(a (@ (href
                                       "?"
                                       ,(encode-query-parameters
                                         `((p . ,p)
                                           (q . ,search-term)))))
                                   ,p)))
                    (lambda (p) `(a (@ (href
                                   "?"
                                   ,(encode-query-parameters
                                     `((p . ,p)
                                       (q . ,search-term)))))
                               "»")))))))))