| 1 | (in-package :it.bese.ucw) |
| 2 | |
| 3 | |
| 4 | (defslot-presentation clsql-wall-time-slot-presentation () |
| 5 | () |
| 6 | (:type-name clsql-sys:wall-time)) |
| 7 | |
| 8 | (defmethod presentation-slot-value ((slot clsql-wall-time-slot-presentation) instance) |
| 9 | (let ((date (call-next-method))) |
| 10 | (when date (multiple-value-bind (y m d) (clsql:time-ymd date) |
| 11 | (format nil "~a/~a/~a" m d y))))) |
| 12 | |
| 13 | (defmethod (setf presentation-slot-value) ((value string) (slot clsql-wall-time-slot-presentation) instance) |
| 14 | (setf (presentation-slot-value slot instance) (clsql:parse-date-time (remove #\Space value)))) |
| 15 | |
| 16 | (defmethod present-slot ((slot clsql-wall-time-slot-presentation) instance) |
| 17 | (let ((date (presentation-slot-value slot instance)) |
| 18 | (input-id (string (gensym)))) |
| 19 | (if (and date (not (editablep slot))) |
| 20 | (<:span (<:as-html date))) |
| 21 | (when (editablep slot) |
| 22 | (<ucw:input :accessor (presentation-slot-value slot instance) :id input-id) |
| 23 | (<:script :type "text/javascript" |
| 24 | (<:as-is (format nil " |
| 25 | Calendar.setup({ |
| 26 | inputField : \"~a\", |
| 27 | ifFormat : \"%m/%d/%Y\", |
| 28 | });" input-id)))))) |
| 29 | |
| 30 | (defslot-presentation mewa-relation-slot-presentation () |
| 31 | ((slot-name :accessor slot-name :initarg :slot-name) |
| 32 | (foreign-instance :accessor foreign-instance) |
| 33 | (linkedp :accessor linkedp :initarg :linkedp :initform t)) |
| 34 | (:type-name relation)) |
| 35 | |
| 36 | (defmethod present-relation ((slot mewa-relation-slot-presentation) instance) |
| 37 | ;;;;(<:as-html (slot-name slot) "=> " (foreign-instance slot) " from " instance ) |
| 38 | (let* ((e (getf (mewa::global-properties (parent slot)) :editablep)) |
| 39 | (i (foreign-instance slot)) |
| 40 | (pres (mewa::make-presentation |
| 41 | i |
| 42 | :type :one-line |
| 43 | :initargs (list |
| 44 | :global-properties |
| 45 | (list :editablep nil :linkedp (linkedp slot)))))) |
| 46 | (when (ucw::parent slot) (setf (component.place pres) (component.place (ucw::parent slot)))) |
| 47 | (flet ((render () (when i (<ucw:render-component :component pres)))) |
| 48 | (cond |
| 49 | ((editablep slot) |
| 50 | (render) |
| 51 | (<ucw:a :action (search-records slot i) (<:as-html " (search)")) |
| 52 | (<ucw:a :action (create-record slot i) (<:as-html " (new)"))) |
| 53 | ((linkedp slot) |
| 54 | (<ucw:a :action (view-instance slot i) |
| 55 | (render))) |
| 56 | (t |
| 57 | (render)))))) |
| 58 | |
| 59 | (defmethod present-slot ((slot mewa-relation-slot-presentation) instance) |
| 60 | (present-relation slot instance)) |
| 61 | |
| 62 | (defslot-presentation foreign-key-slot-presentation (mewa-relation-slot-presentation) |
| 63 | () |
| 64 | (:type-name foreign-key) |
| 65 | (:default-initargs)) |
| 66 | |
| 67 | (defaction view-instance ((self component) instance &rest initargs) |
| 68 | (call-component (parent self) (apply #'mewa:make-presentation instance initargs))) |
| 69 | |
| 70 | (defmethod present-slot :before ((slot foreign-key-slot-presentation) instance) |
| 71 | (setf (foreign-instance slot) (meta-model:explode-foreign-key instance (slot-name slot)))) |
| 72 | |
| 73 | ;;;; HAS MANY |
| 74 | (defslot-presentation has-many-slot-presentation (mewa-relation-slot-presentation) |
| 75 | () |
| 76 | (:type-name has-many)) |
| 77 | |
| 78 | (defmethod present-slot ((slot has-many-slot-presentation) instance) |
| 79 | (let ((i (get-foreign-instances slot instance)) |
| 80 | (linkedp (linkedp slot))) |
| 81 | (<:ul |
| 82 | (dolist (s i) |
| 83 | (let ((s s)) |
| 84 | (setf (foreign-instance slot) s) |
| 85 | (<ucw:a :action (view-instance slot s :initargs `(:global-properties ,(list :linkedp t :editablep nil))) |
| 86 | (<:li (setf (linkedp slot) nil) |
| 87 | (present-relation slot instance)))))))) |
| 88 | |
| 89 | |
| 90 | (defmethod get-foreign-instances ((slot has-many-slot-presentation) instance) |
| 91 | (slot-value instance (slot-name slot))) |
| 92 | |
| 93 | (defslot-presentation has-very-many-slot-presentation (has-many-slot-presentation) |
| 94 | ((number-to-display :accessor number-to-display :initarg :number-to-display :initform 10) |
| 95 | (current :accessor current :initform 0) |
| 96 | (len :accessor len ) |
| 97 | (instances :accessor instances)) |
| 98 | |
| 99 | (:type-name has-very-many)) |
| 100 | |
| 101 | (defmethod list-next ((slot has-very-many-slot-presentation)) |
| 102 | (setf (current slot) (incf (current slot) (number-to-display slot))) |
| 103 | (when (< (len slot) (current slot)) |
| 104 | (setf (current slot) (- (number-to-display slot) (len slot))))) |
| 105 | |
| 106 | (defmethod list-prev ((slot has-very-many-slot-presentation)) |
| 107 | (setf (current slot) (decf (current slot) (number-to-display slot))) |
| 108 | (when (> 0 (current slot)) |
| 109 | ;;what to do here is open to debate |
| 110 | (setf (current slot) (- (len slot)(number-to-display slot) )))) |
| 111 | |
| 112 | |
| 113 | (defmethod present-slot ((slot has-very-many-slot-presentation) instance) |
| 114 | ;;(<:as-html "isance: " instance) |
| 115 | (<ucw:a :action (list-prev slot) (<:as-html "<<")) |
| 116 | (let ((self (parent slot))) |
| 117 | (<ucw:a :action (call-component self (mewa:make-presentation (car (slot-value instance (slot-name slot))) :type :listing :initargs (list :instances (instances slot)))) |
| 118 | (<:as-html (label slot) (format nil " ~a-~a " (current slot) (+ (current slot) (number-to-display slot)))))) |
| 119 | (<ucw:a :action (list-next slot) (<:as-html ">>")) |
| 120 | (call-next-method) |
| 121 | (<:as-html "total :" (len slot))) |
| 122 | |
| 123 | (defmethod get-foreign-instances :around ((slot has-very-many-slot-presentation) instance) |
| 124 | (let ((f (call-next-method))) |
| 125 | (setf (len slot) (length f)) |
| 126 | (setf (instances slot) f) |
| 127 | (loop for cons on (nthcdr (current slot) f) |
| 128 | for i from 0 upto (number-to-display slot) |
| 129 | collect (car cons)))) |
| 130 | |
| 131 | (defslot-presentation has-a-slot-presentation (one-of-presentation) |
| 132 | ((key :initarg :key :accessor key)) |
| 133 | (:type-name has-a)) |
| 134 | |
| 135 | (defmethod get-foreign-slot-value ((slot has-a-slot-presentation) (object t) (slot-name t)) |
| 136 | (slot-value object slot-name)) |
| 137 | |
| 138 | (defmethod present-slot ((slot has-a-slot-presentation) instance) |
| 139 | (<:as-html (presentation-slot-value slot instance)) |
| 140 | (if (editablep slot) |
| 141 | (<ucw:select :accessor (presentation-slot-value slot instance) :test #'equalp |
| 142 | (when (allow-nil-p slot) |
| 143 | (<ucw:option :value nil (<:as-html (none-label slot)))) |
| 144 | (dolist (option (get-foreign-instances (presentation slot) instance)) |
| 145 | (setf (instance (presentation slot)) option) |
| 146 | (<ucw:option :value (get-foreign-slot-value slot option (key slot)) (present (presentation slot))))) |
| 147 | (if (presentation-slot-value slot instance) |
| 148 | (progn |
| 149 | (setf (instance (presentation slot)) (presentation-slot-value slot instance)) |
| 150 | (present (presentation slot))) |
| 151 | (<:as-html "--")))) |