:accessor attributes-getter
:initform #'get-attributes
:initarg :attributes-getter)
+ (attribute-slot-map
+ :accessor attribute-slot-map
+ :initform nil)
(global-properties
:initarg :global-properties
:accessor global-properties
(meta-model:list-has-many (instance self)))
nil))
-
(defmethod find-instance-classes ((self mewa))
(mapcar #'class-name
(it.bese.arnesi.mopp:compute-class-precedence-list (class-of (instance self)))))
(attributes self)))
all-attributes))))
+(defmethod find-slot-presentation-for-attribute ((self mewa) attribute)
+ (let ((class-name
+ (or (gethash (second attribute) ucw::*slot-type-mapping*)
+ (error "Can't find slot type for ~A" (second attribute)))))
+
+ (cons (first attribute) (apply #'make-instance
+ class-name
+ (append (cddr attribute) (list :parent self :size 30))))))
+
(defmethod find-slot-presentations ((self mewa))
- (mapcar #'(lambda (s)
- (let ((class-name (or (gethash (second s) ucw::*slot-type-mapping*) 'mewa-object-presentation)))
- (apply #'make-instance
- class-name
- (append (cddr s) (list :parent self :size 30)))))
+ (mapcar #'(lambda (a) (find-slot-presentation-for-attribute self a))
(find-applicable-attributes self)))
-
+(defmethod find-attribute-slot ((self mewa) (attribute symbol))
+ (cdr (assoc attribute (attribute-slot-map self))))
(defmethod initialize-slots ((self mewa))
(when (use-instance-class-p self)
(setf (classes self)
(append (find-instance-classes self)
(classes self))))
- (setf (slots self) (find-slot-presentations self)))
+ (setf (attribute-slot-map self) (find-slot-presentations self))
+ (setf (slots self) (mapcar #'(lambda (x)(cdr x)) (attribute-slot-map self ))))
(defmethod make-presentation ((object t) &key (type :viewer) (initargs nil))
(setf (component.place x) place)))
(slots mewa))))
-
-
-
-
-
(defmethod call-component :before ((from standard-component) (to mewa))
(unless (slot-value to 'initializedp)
(initialize-slots to))
(defmethod instance-is-stored-p ((instance clsql:standard-db-object))
- (slot-value instance 'clsql-sys::view-database))
+ (slot-value instance 'clsql-sys::view-database))
+
+(defmethod instance-is-stored-p ((mewa mewa))
+ (instance-is-stored-p (instance mewa)))
(defaction cancel-save-instance ((self mewa))
(cond
(defslot-presentation mewa-relation-slot-presentation (mewa-slot-presentation slot-presentation)
((foreign-instance :accessor foreign-instance)
- (linkedp :accessor linkedp :initarg :linkedp :initform t))
+ (linkedp :accessor linkedp :initarg :linkedp :initform t)
+ (creator :accessor creator :initarg :creator :initform :editor))
(:type-name relation))
(defaction search-records ((slot mewa-relation-slot-presentation) instance)
(setf (slot-value instance (slot-name slot)) (slot-value new-instance foreign-slot-name))
(meta-model:sync-instance instance :fill-gaps-only-p (fill-gaps-only-p self)))))
-(defaction create-record ((slot mewa-relation-slot-presentation) instance)
+(defaction create-record-on-foreign-key ((slot mewa-relation-slot-presentation) instance)
(multiple-value-bindf (finstance foreign-slot-name)
(meta-model:explode-foreign-key instance (slot-name slot))
(let ((new-instance
(call-component
(parent slot)
- (mewa:make-presentation finstance :type :editor))))
+ (mewa:make-presentation finstance :type (creator self)))))
+
+ ;;;; TODO: this next bit is due to a bad design decision.
+ ;;;; Components should always have (ok) return self, but somewhere
+ ;;;; i've made in return (instance self) sometimes, and this
+ ;;;; bahaviour is totatlly fucked.
+
+ (when (typep new-instance 'mewa::mewa)
+ (setf new-instance (instance new-instance)))
+
+ ;;;; sorry about that, and now back t our regular program.
+
+ (meta-model:sync-instance new-instance)
(setf (slot-value instance (slot-name slot)) (slot-value new-instance foreign-slot-name))
(meta-model:sync-instance instance :fill-gaps-only-p (fill-gaps-only-p self)))))
+
(defmethod present-relation ((slot mewa-relation-slot-presentation) instance)
;;;;(<:as-html (slot-name slot) "=> " (foreign-instance slot) " from " instance )
(meta-model:sync-instance (instance (parent self))))
-(defmethod present-slot :around ((slot foreign-key-slot-presentation) instance)
+
+(defmethod present-slot :before ((slot foreign-key-slot-presentation) instance)
+ ())
+
+
+(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 () (when (foreign-instance slot)(call-next-method))))
(if (slot-boundp slot 'place)
(cond
((editablep slot)
(render)
(<ucw:submit :action (search-records slot instance) :value "Search" :style "display:inline")
- (<ucw:submit :action (create-record slot instance) :value "Add New" :style "display:inline"))
+ (<ucw:submit :action (create-record-on-foreign-key slot instance) :value "Add New" :style "display:inline"))
((linkedp slot)
(<ucw:a :action (view-instance slot (foreign-instance slot))
(render)))
(let ((new (make-instance class)))
(setf (slot-value new foreign) (slot-value instance home))
(meta-model:sync-instance new :fill-gaps-only-p (fill-gaps-only-p self))
- (call-component (parent slot) (mewa:make-presentation new :type :editor))
+ (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)