(in-package :lisp-on-lines) (defmethod/cc read-instance ((self component) instance) "View an existing instance" (call 'crud-viewer :instance instance)) (defmethod/cc update-instance ((self component) instance) "Edit an instance, possibly a newly created one" (call 'crud-editor :instance instance)) (defmethod/cc 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))))) (defmethod/cc 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) (