-
Notifications
You must be signed in to change notification settings - Fork 3
/
navbar-selector.lisp
43 lines (38 loc) · 1.81 KB
/
navbar-selector.lisp
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
(in-package :weblocks-twitter-bootstrap-application)
(defwidget bootstrap-navbar-selector (simple-selector)
((selected :accessor bootstrap-navbar-selector-selected)
(titles :initarg :titles)))
(defmethod get-selector-link (widget selected)
; (url-for :navbar.selected j)
(make-action-url
(function-or-action->action
(lambda (&rest args)
(setf (slot-value widget 'selected) selected)
(mark-dirty widget)))))
(defmethod render-widget-body ((obj bootstrap-navbar-selector) &rest args)
(unless (slot-value obj 'selected)
(setf (slot-value obj 'selected) (first (slot-value obj 'names))))
(render-wt
:bootstrap-navbar-menu-wt
(list :widget obj :selected (slot-value obj 'selected))
:menu-id "navbar-nav"
:menu-content (arnesi:join-strings
(loop for i in (slot-value obj 'titles)
for j in (slot-value obj 'names)
for k from 0
collect (render-wt-to-string
:bootstrap-navbar-menu-item-wt
(list :widget obj)
:pane-selected-or-disabled (string= j (slot-value obj 'selected))
:item-href (get-selector-link obj j)
:content i)))))
(defun make-navbar-selector (name &rest args)
(let ((names (mapcar #'third args)))
(when names
(setf (car names) ""))
(make-instance 'bootstrap-navbar-selector
:names names
:titles (mapcar #'first args)
:child-callbacks (mapcar (lambda (item) (lambda () item)) (mapcar #'second args))
:uri-id (alexandria:make-keyword (string-upcase name))
:public-parameters '(:selected))))