From 301f28fd7c8390159aec06d93f815e8d02095fcc Mon Sep 17 00:00:00 2001 From: drewc Date: Thu, 5 Oct 2006 13:48:43 -0700 Subject: [PATCH] Added 'CRUD' component example darcs-hash:20061005204843-39164-885111c01b3bb2600668d53b5d517665805d4244.gz --- src/components/crud.lisp | 314 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 314 insertions(+) create mode 100644 src/components/crud.lisp diff --git a/src/components/crud.lisp b/src/components/crud.lisp new file mode 100644 index 0000000..7b72ca8 --- /dev/null +++ b/src/components/crud.lisp @@ -0,0 +1,314 @@ +(in-package :lisp-on-lines) + +(defaction read-instance ((self component) instance) + "View an existing instance" + (call 'crud-viewer :instance instance)) + +(defaction update-instance ((self component) instance) + "Edit an instance, possibly a newly created one" + (call 'crud-editor :instance instance)) + +(defaction create-instance ((self component) class &rest initargs) + "Create a new instance and edit it." + (update-instance self (apply #'make-instance class initargs))) + +(defun %delete-instance-and-return-nil (instance) + "returns nil on success" + (handler-case (clsql:delete-instance-records instance) + (error (x) + (return-from %delete-instance-and-return-nil x))) + nil) + +(defun display-as-string (instance) + (with-output-to-string (s) + (yaclml:with-yaclml-stream s + (display (make-instance 'component) instance + :layers '(+ as-string))))) + +(defaction delete-instance ((self component) instance) + (when (call 'option-dialog + :message (format nil "Really Delete ~A" (display-as-string instance)) + :options '((t "Yes, really delete it,") + (nil "No, i'll hold on to this one."))) + (let ((delete-failed (%delete-instance-and-return-nil instance))) + (if (not delete-failed) + (answer t) + (progn + (call 'info-message :message delete-failed) + (answer t)))))) + + +(defmethod breadcrumb-name (component) + (string-downcase (string (class-name (class-of component))))) + +(defun render-breadcrumb (self) + (<:p :class "breadcrumb" + (let ((count 0) + (trail-length 3)) + (labels ((find-call-stack-for-crumbs (component list-of-parents) + (cond ((and (not (null component)) + (> trail-length count)) + (incf count) + (find-call-stack-for-crumbs + (when (slot-boundp component 'ucw::calling-component) + (slot-value component 'ucw::calling-component)) + (cons component list-of-parents))) + (t + list-of-parents)))) + (loop + :for c + :on (find-call-stack-for-crumbs self nil) + :do (let ((c c)) + (<:as-html " / ") + (if (cdr c) + (