removed the poorly named and poorly located INSTANCE-IS-STORED-P
[clinton/lisp-on-lines.git] / src / lisp-on-lines.lisp
index 8a9a88b..77dab5c 100644 (file)
@@ -10,7 +10,7 @@
 ;;;; ** Initialisation
 ;;;; The following macros are used to initialise a set of database tables as LoL objects.
 (eval-when (:compile-toplevel :load-toplevel :execute)
 ;;;; ** Initialisation
 ;;;; The following macros are used to initialise a set of database tables as LoL objects.
 (eval-when (:compile-toplevel :load-toplevel :execute)
-  (defun generate-initialize-lol-for-table (table)
+  (defun generate-define-view-for-table (table)
     "
 Generates a form that, when evaluated, initialises the given table as an lol object.
 This involves creating a meta-model, a clsql view-class, and the setting up the default attributes for a mewa presentation"
     "
 Generates a form that, when evaluated, initialises the given table as an lol object.
 This involves creating a meta-model, a clsql view-class, and the setting up the default attributes for a mewa presentation"
@@ -19,19 +19,56 @@ This involves creating a meta-model, a clsql view-class, and the setting up the
       (def-view-class-from-table ,table)
       (set-default-attributes (quote ,(meta-model::sql->sym table))))))
     
       (def-view-class-from-table ,table)
       (set-default-attributes (quote ,(meta-model::sql->sym table))))))
     
-(defmacro initialize-lol-for-table (&rest tables)
+(defmacro define-view-for-table (&rest tables)
   " expand to a form which initialises TABLES for use with LOL"
   `(progn
   " expand to a form which initialises TABLES for use with LOL"
   `(progn
-    ,@(loop for tbl in tables collect (generate-initialize-lol-for-table tbl))
+    ,@(loop for tbl in tables collect (generate-define-view-for-table tbl))
     (values)))
 
     (values)))
 
-(defmacro initialize-lol-for-database ()
+(defmacro define-views-for-database ()
   "expands to init-i-f-t using the listing of tables provided by meta-model"
   "expands to init-i-f-t using the listing of tables provided by meta-model"
-  `(initialize-lol-for-table ,@(meta-model::list-tables)))
+  `(define-view-for-table ,@(meta-model::list-tables)))
 
 
-;;;; * AJAX stuff 
+(eval-when (:compile-toplevel :load-toplevel :execute)
+  (defun %make-view (object type attributes args)
+   
+      (when attributes
+       (setf args
+             (cons `(:attributes ,attributes) args)))
+      `(mewa:make-presentation
+       ,object
+       :type ,type
+       ,@(when args
+               `(:initargs
+                 '(,@ (mapcan #'identity args)))))))
+
+(defmethod make-view (object &rest args &key (type :viewer) (attributes nil)
+                     &allow-other-keys )
+  (apply #'make-presentation (cdr (%make-view object type attributes args))))
+
+(defmacro present-view ((object &optional (type :viewer) (parent 'self))
+                       &body attributes-and-args)
+  (arnesi:with-unique-names (view)
+    `(let ((,view (lol:make-view ,object
+                                :type ,type
+                                :attributes ,(car attributes-and-args)
+                                ,@ (cdr attributes-and-args))))
+      (setf (ucw::parent ,view) ,parent)
+      (lol:present ,view))))
+
+
+(defmacro call-view ((object &optional (type :viewer) (component 'self component-supplied-p))
+                    &body attributes-and-args)  
+  `(ucw:call-component
+    ,component
+    ,(%make-view object type (car attributes-and-args) (cdr attributes-and-args))))
+
+(defmethod slot-view ((self mewa) slot-name)
+  (mewa::find-attribute-slot self slot-name))
+
+(defmethod present-slot-view ((self mewa) slot-name &optional (instance (instance self)))
+  (present-slot (slot-view self slot-name) instance))
 
 
-;;;; TODO: This search stuff should probably me refactored elsewhere
 
 (defmethod find-slots-of-type (model &key (type 'string)
                              (types '((string)) types-supplied-p))
 
 (defmethod find-slots-of-type (model &key (type 'string)
                              (types '((string)) types-supplied-p))
@@ -45,6 +82,16 @@ This involves creating a meta-model, a clsql view-class, and the setting up the
             (lisp-on-lines::list-slot-types model)))))
 
 
             (lisp-on-lines::list-slot-types model)))))
 
 
+
+(defun %delete-item (item)
+  (ignore-errors
+    (clsql:delete-instance-records item)))
+
+(defaction delete-item ((self component) instance)
+  (if (%delete-item instance)
+      (answer nil)
+      (call 'info-message :message "Could not remove item. Try removing associated items first.")))
+
 (defmethod word-search (class-name slots search-terms 
                        &key (limit 10) (where (sql-and t)))
   (select class-name 
 (defmethod word-search (class-name slots search-terms 
                        &key (limit 10) (where (sql-and t)))
   (select class-name 
@@ -70,3 +117,5 @@ This involves creating a meta-model, a clsql view-class, and the setting up the
                              slots)))
           search-terms)))
 
                              slots)))
           search-terms)))
 
+
+  
\ No newline at end of file