Created
February 23, 2009 15:25
-
-
Save aggieben/68989 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defclass cons-presentation-mixin () | |
((car-type :accessor cons-presentation-car-type | |
:initarg :car-type) | |
(cdr-type :accessor cons-presentation-cdr-type | |
:initarg :cdr-type)) | |
(:documentation "A presentation for conses.")) | |
(defclass cons-presentation (presentation cons-presentation-mixin) | |
() | |
) | |
(defmethod render-view-field-value (value (presentation cons-presentation) | |
field view widget obj &rest args | |
&key highlight &allow-other-keys) | |
(let ((printed-value (apply #'print-view-field-value | |
value presentation field view widget | |
obj args))) | |
(with-html | |
(:span :class "value" | |
(str (escape-for-html printed-value)))))) | |
(defmethod print-view-field-value (value (presentation cons-presentation) | |
field view widget obj &rest args) | |
(declare (ignore args presentation field view widget obj)) | |
(if (null value) | |
"()" | |
(with-output-to-string (stream) | |
(if (consp value) | |
(progn | |
(format stream "(") | |
(dotimes (n 3) | |
(format stream "~A~A" (nth n value) (if (< n 2) " " ""))) | |
(when (> (length value) 3) | |
(format stream " ...")) | |
(princ ")" stream)) | |
(princ "NOTALIST" stream))))) | |
(defclass complex-edit-mixin () | |
((data :accessor complex-edit-data)) | |
(:documentation "A helper class for widgets that are used to edit | |
complex types.")) | |
(defclass dialog-input-presentation (form-presentation) | |
((input-widget :initarg :input-widget | |
:accessor dialog-input-widget | |
:type complex-edit-mixin)) | |
(:documentation "An input presentation to facilitate pop-up or js | |
dialogs for nonprimitive type input.")) | |
(defmethod initialize-instance :after ((instance dialog-input-presentation) | |
&rest initargs &key input-widget) | |
(declare (ignore initargs)) | |
(unless (null input-widget) | |
(setf (dialog-input-widget instance) | |
(make-instance input-widget)))) | |
(defmethod render-view-field-value (value (presentation dialog-input-presentation) | |
field view widget obj &rest args &key) | |
(declare (ignore args)) | |
;; set the data for the complex-edit-mixin | |
(hunchentoot:log-message :debug "dialog-input-presentation, value: ~A~%" value) | |
(setf (complex-edit-data (dialog-input-widget presentation)) | |
value) | |
;; render a link here that will open a dialog that can accept complex input | |
(render-link (lambda (&rest args) | |
(declare (ignore args)) | |
(do-dialog "Complex Edit" (dialog-input-widget presentation))) | |
"object")) | |
(defwidget listedit (dataform complex-edit-mixin) | |
() | |
(:documentation "A widget based on dataform that modifies the | |
rendered interface to facilitate the input of a list of objects of | |
drilldown-type.")) | |
(defmethod initialize-instance :after ((w listedit) &rest args) | |
(declare (ignore args)) | |
(setf (dataform-ui-state w) :form)) | |
(defmethod render-widget-body ((w listedit) &rest args &key) | |
(declare (ignore args)) | |
;; use the selecttion list tag <select> | |
(with-html | |
(:select :size "5" | |
(hunchentoot:log-message :debug "object to edit: ~a~%" | |
(complex-edit-data w)) | |
(dolist (item (complex-edit-data w)) | |
(htm (:option :value (str (format nil "~A" item)) | |
(princ item))))))) | |
(defclass mydata () | |
((id) | |
(text :accessor mydata-text | |
:initarg :text | |
:initform "" | |
:type string) | |
(list :accessor mydata-list | |
:initarg :list | |
:initform '(a b c d)))) | |
(defview mydata-table-view (:type table :inherit-from '(:scaffold mydata)) | |
(list :present-as (cons))) | |
(defview mydata-data-view (:type data :inherit-from '(:scaffold mydata)) | |
(list :present-as (cons))) | |
(defview mydata-form-view (:type form :inherit-from '(:scaffold mydata)) | |
(list :present-as (dialog-input :input-widget 'listedit))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment