X-Git-Url: https://git.hcoop.net/clinton/lisp-on-lines.git/blobdiff_plain/9d6c69fb50810bef64e6f3357a21b4f4397e2b1b..d25124264c5fc11612eee640a7ef568ed08d7db6:/src/mewa/slot-presentations.lisp diff --git a/src/mewa/slot-presentations.lisp b/src/mewa/slot-presentations.lisp index 26a3332..1454c53 100644 --- a/src/mewa/slot-presentations.lisp +++ b/src/mewa/slot-presentations.lisp @@ -1,34 +1,71 @@ (in-package :it.bese.ucw) (defun multiple-value-funcall->list (function &rest args) + "The function to be called by m-v-bf" (multiple-value-call #'list (apply function args))) (defmacro multiple-value-bindf (vars form &body body) + "Like M-V-B, only it works in actions. form must be a function call" `(destructuring-bind ,vars (multiple-value-funcall->list #',(car form) ,@(cdr form)) ,@body)) -(defslot-presentation mewa-boolean-slot-presentation (boolean-slot-presentation) - ((slot-name :accessor slot-name :initarg :slot-name)) - (:type-name mewa-boolean)) -(defslot-presentation mewa-string-slot-presentation (string-slot-presentation ) +;;;; ** Textarea Slot Presentation +;;;; This should really be in UCW. - ((slot-name :accessor slot-name :initarg :slot-name)) - (:type-name mewa-string)) +(defslot-presentation text-slot-presentation () + ((rows :initarg :rows :accessor rows :initform nil) + (columns :initarg :columns :accessor columns :initform nil) + (html-contentp :initarg :escape-html-p :accessor escape-html-p :initform nil)) + (:type-name text)) -(defslot-presentation mewa-number-slot-presentation (number-slot-presentation) - ((slot-name :accessor slot-name :initarg :slot-name)) - (:type-name mewa-number)) - -(defslot-presentation mewa-integer-slot-presentation (integer-slot-presentation) - ((slot-name :accessor slot-name :initarg :slot-name)) - (:type-name mewa-integer)) - -(defslot-presentation mewa-currency-slot-presentation (currency-slot-presentation) - - ((slot-name :accessor slot-name :initarg :slot-name)) - (:type-name mewa-currency)) +(defmethod present-slot ((slot text-slot-presentation) instance) + (if (editablep slot) + ( " (foreign-instance slot) " from " instance ) (let* ((i (foreign-instance slot)) @@ -119,59 +172,138 @@ (:default-initargs)) (defaction view-instance ((self component) instance &rest initargs) - (call-component (parent self) (apply #'mewa:make-presentation instance initargs))) - - -(defmethod present-slot :around ((slot foreign-key-slot-presentation) instance) - (setf (foreign-instance slot) (when (presentation-slot-value slot instance) (meta-model:explode-foreign-key instance (slot-name slot)))) - (flet ((render () (call-next-method))) - (cond - ((editablep slot) - (render) - ( (length (last-name x)) 0) + (strcat (last-name x) ", ") + " ") + (first-name x)" " (company-name x))) + :as-value (lambda (x) x) + :submit-on-click-p nil))) + (:type-name ajax-foreign-key)) + + +(defmethod shared-initialize :after ((slot ajax-foreign-key-slot-presentation) slots &rest args) + ;; If no search-slots than use the any slots of type string + (unless (search-slots slot) + (setf (search-slots slot) t) + (let ((l (live-search slot))) + (setf (lisp-on-lines::values-generator l) t)))) + + +(defmethod present-slot :around ((slot ajax-foreign-key-slot-presentation) instance) + (setf (foreign-instance slot) + (when (presentation-slot-value slot instance) + (meta-model:explode-foreign-key instance (slot-name slot)))) + (flet ((render () (when (foreign-instance slot)(call-next-method)))) + (if (slot-boundp slot 'place) + (cond + ((editablep slot) + + (list #'meta-model:explode-has-many instance (slot-name slot)) + ;; if the instance is not stored we must make sure to mark it stored now! + (unless (mewa::instance-is-stored-p instance) + (setf (mewa::modifiedp (parent self)) t)) + ;; sync up the instance + (mewa:ensure-instance-sync (parent slot)) + + (multiple-value-bindf (class home foreign) + (meta-model:explode-has-many instance (slot-name slot)) (let ((new (make-instance class))) (setf (slot-value new foreign) (slot-value instance home)) - (meta-model:sync-instance new :fill-gaps-only t) - (call-component (parent slot) (mewa:make-presentation new :type :editor))))) + (meta-model:sync-instance new :fill-gaps-only-p (fill-gaps-only-p self)) + (call-component (parent slot) (mewa:make-presentation new :type (creator slot))) + (meta-model:sync-instance instance)))) (defmethod present-slot ((slot has-many-slot-presentation) instance) - (>")) - (call-next-method) - (<:as-html "total :" (len slot))) + (if (slot-boundp slot 'place) + (progn + (>")) + (call-next-method) + (<:as-html "total :" (len slot))) + (call-next-method))) (defmethod get-foreign-instances :around ((slot has-very-many-slot-presentation) instance) (let ((f (call-next-method))) @@ -230,4 +365,11 @@ (progn (setf (instance (presentation slot)) (presentation-slot-value slot instance)) (present (presentation slot))) - (<:as-html "--")))) \ No newline at end of file + (<:as-html "--")))) + + + + + + +