removed the Undo in ajax fkey
[clinton/lisp-on-lines.git] / src / slot-presentations.lisp
index b90128e..ceb27ab 100644 (file)
 (defslot-presentation text-slot-presentation ()
   ((rows :initarg :rows :accessor rows :initform 5)
    (columns :initarg :columns :accessor columns :initform 40)
-   (escape-html-p :initarg :escape-html-p :accessor escape-html-p :initform nil))
+   (escape-html-p :initarg :escape-html-p :accessor escape-html-p :initform nil)
+   (convert-newlines-p :initarg :convert-newlines-p :accessor convert-newlines-p :initform nil))
   (:type-name text))
 
 (defmethod present-slot ((slot text-slot-presentation) instance)
+  (flet ((maybe-convert-newline-and-escape-html-then-print ()
+          (let ((string (if (convert-newlines-p slot)
+                            (with-output-to-string (new-string)
+                              (with-input-from-string
+                                  (s (presentation-slot-value slot instance))
+                                (loop for line = (read-line s nil)
+                                      while line
+                                      do (format new-string "~A~A" line "<br/>"))))
+                            (presentation-slot-value slot instance))))
+            (if (escape-html-p slot)
+                (<:as-html string)
+                (<:as-is string)))))
+    
     (if (editablep slot)
        (<ucw:textarea
         :accessor (presentation-slot-value slot instance)
@@ -27,9 +41,7 @@
                 "")
         :rows (rows slot)
         :cols (columns slot))
-       (if (escape-html-p slot)
-           (<:as-html (presentation-slot-value slot instance))
-           (<:as-is (presentation-slot-value slot instance)))))
+       (maybe-convert-newline-and-escape-html-then-print))))
 
 
 (defcomponent mewa-slot-presentation ()
@@ -43,7 +55,8 @@
                     :documentation 
                     "When nil, the instance is syncronised with the database. 
 When T, only the default value for primary keys and the joins are updated.")
-   (show-label-p :accessor show-label-p :initarg :show-label-p :initform t))
+   (show-label-p :accessor show-label-p :initarg :show-label-p :initform t)
+   (creatablep :accessor creatablep :initarg :creatablep :initform t))
   (:documentation "The superclass of all Mewa slot presentations"))
 
 ;;;; this has to be in the eval when i would think
@@ -250,7 +263,7 @@ Calendar.setup({
                                          :linkedp t
                                          :editablep nil)))
                (<:as-html string))))
-       (<:table
+       (<:table :cellpadding 10
         (<:tr
          (<:th)                        ;empty col for (view) link
          (dolist (s (slots presentation))
@@ -347,7 +360,8 @@ Calendar.setup({
                           :initargs
                           `(:attributes ,(attributes slot)))
                        ))))
-            (<ucw:submit :action  (create-record-on-foreign-key slot instance) :value "Add New" :style "display:inline")) 
+            (when (creatablep slot)
+              (<ucw:submit :action  (create-record-on-foreign-key slot instance) :value "Add New" :style "display:inline"))) 
       (if (presentation-slot-value slot instance)
          (progn
           (lol:present
@@ -415,6 +429,7 @@ Calendar.setup({
                (<:as-html "(remove) "))
        (present-view ((car i) (list-view slot) (ucw::parent slot)))) ))))
 
+
 (defaction add-to-many-to-many ((slot many-to-many-slot-presentation) instance &optional foreign-instance)
   ;;;; First things first, we sync.
   (sync-instance instance)
@@ -440,11 +455,3 @@ Calendar.setup({
       
       (sync-instance instance)
       c)))
-        
-
-       
-
-
-
-
-