added edit-instance function
[clinton/lisp-on-lines.git] / src / mewa / presentations.lisp
CommitLineData
687d5f1c 1(in-package :mewa)
2
7f16078d 3(defaction edit-instance ((self mewa))
4 (call-presentation (instance self) :type :editor))
5
687d5f1c 6;;;one-line objects
7(defcomponent mewa-one-line-presentation (mewa one-line-presentation)
8 ()
9 (:default-initargs :attributes-getter #'one-line-attributes-getter))
10
11(defmethod one-line-attributes-getter ((self mewa))
12 (or (meta-model:list-keys (instance self))))
13
14;;;objects
15(defcomponent mewa-object-presentation (mewa ucw:object-presentation) ())
16
6460c439 17(defcomponent two-column-presentation (mewa-object-presentation) ())
18
19(defmethod present ((pres two-column-presentation))
20
21 (<:table :class (css-class pres)
22 (loop for slot on (slots pres) by #'cddr
23 do
24 (<:tr :class "presentation-slot-row"
25 (<:td :class "presentation-slot-label"
26 (<:as-html (label (first slot))))
27 (<:td :class "presentation-slot-value"
28 (present-slot (first slot) (instance pres)))
29 (when (second slot)
30 (<:td :class "presentation-slot-label"
31 (<:as-html (label (second slot))))
32 (<:td :class "presentation-slot-value"
33 (present-slot (second slot) (instance pres))))))
34 (render-options pres (instance pres))))
35
36
687d5f1c 37;;;lists
38(defcomponent mewa-list-presentation (mewa ucw:list-presentation)
31597d71 39 ((ucw::instances :accessor instances :initarg :instances :initform nil)
687d5f1c 40 (instance :accessor instance)
41 (select-label :accessor select-label :initform "select" :initarg :select-label)
42 (selectablep :accessor selectablep :initform t :initarg :selectablep)))
43
44(defaction select-from-listing ((listing mewa-list-presentation) object index)
45 (answer object))
46
47(defmethod render-list-row ((listing mewa-list-presentation) object index)
48 (<:tr :class "item-row"
49 (<:td :align "center" :valign "top"
50 (when (ucw::editablep listing)
51 (let ((object object))
52 (<ucw:input :type "submit"
53 :action (edit-from-listing listing object index)
54 :value (ucw::edit-label listing))))
55 (<:as-is " ")
56 (when (ucw::deleteablep listing)
57 (let ((index index))
58 (<ucw:input :type "submit"
59 :action (delete-from-listing listing object index)
60 :value (ucw::delete-label listing))))
61 (when (selectablep listing)
62 (let ((index index))
63 (<ucw:input :type "submit"
64 :action (select-from-listing listing object index)
65 :value (select-label listing)))))
66 (dolist (slot (slots listing))
67 (<:td :class "data-cell" (present-slot slot object)))
6fc8733b 68 (<:td :class "index-number-cell")
687d5f1c 69 ))
70
71(defmethod get-all-instances ((self mewa-list-presentation))
72 (instances self))
aef3b247 73
74
75;;; searching
76
77(defcomponent mewa-presentation-search (ucw::presentation-search)
78 ((display-results-p :accessor display-results-p :initarg :display-results-p :initform nil)))
79
80(defmethod ok ((self mewa-presentation-search) &optional arg)
81 (declare (ignore arg))
82 (setf (display-results-p self) t))
83
84(defmethod get-all-instances ((self mewa-presentation-search))
85 (clsql:select (class-name (class-of (instance (ucw::search-presentation self)))) :flatp t))
86
87(defmethod render-on ((res response) (self mewa-presentation-search))
88 (ucw::render-criteria res self)
89 (when (display-results-p self)
90 (let ((listing (ucw::list-presentation self)))
91 (setf (instances listing ) (ucw::valid-instances self)
92 (slot-value listing 'ucw::calling-component) (slot-value self 'ucw::calling-component)
93 (slot-value listing 'ucw::place) (slot-value self 'ucw::place)
94 (slot-value listing 'ucw::continuation) (slot-value self 'ucw::continuation))
95
96 (render-on res listing))))