fixed autocomplete to be more specific
[clinton/lisp-on-lines.git] / src / slot-presentations.lisp
index 7827c37..c92fa4b 100644 (file)
@@ -1,5 +1,8 @@
+(declaim (optimize (speed 0) (space 3) (safety 0)))
 (in-package :lisp-on-lines)
 
+
+;;;; I dont think i'm using these anymore.
 (defun multiple-value-funcall->list (function &rest args)
   "The function to be called by m-v-bf"
                   (multiple-value-call #'list (apply function args)))
 (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)
                 "")
         :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)))))
+       (when (presentation-slot-value slot instance)
+         (maybe-convert-newline-and-escape-html-then-print)))))
 
 
 (defcomponent mewa-slot-presentation ()
-  ((slot-name :accessor slot-name 
+  ((validate-functions :accessor validate-functions :initform (list (constantly t)))
+   (slot-name :accessor slot-name 
              :initarg :slot-name 
              :documentation 
              "The name of the slot being accessed")
                     :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
 (eval-when (:compile-toplevel :load-toplevel :execute)
   (defun generate-slot-presentation-definition-for-type (type)
@@ -71,7 +91,8 @@ When T, only the default value for primary keys and the joins are updated.")
 
 (defslot-presentation clsql-wall-time-slot-presentation (mewa-relation-slot-presentation)
        ((input-id :accessor input-id :initform (arnesi:random-string 10 arnesi:+ascii-alphabet+))
-       (trigger-id :accessor trigger-id :initform (arnesi:random-string 10 arnesi:+ascii-alphabet+)))
+       (trigger-id :accessor trigger-id :initform (arnesi:random-string 10 arnesi:+ascii-alphabet+))
+       (default-to-now-p :accessor default-to-now-p :initarg :default-to-now-p :initform nil))
        (:type-name clsql-sys:wall-time))
 
 (defmethod presentation-slot-value ((slot clsql-wall-time-slot-presentation) instance)
@@ -86,15 +107,20 @@ When T, only the default value for primary keys and the joins are updated.")
     (unless (or (eql old-time new-time)
                (when (and new-time old-time)
                  (equal :equal (clsql:time-compare new-time old-time))))
-    (setf (presentation-slot-value slot instance) new-time ))))
+    (setf (presentation-slot-value slot instance) new-time))))
 
 (defmethod label :around ((slot clsql-wall-time-slot-presentation))
   (concatenate 'string (call-next-method) "  (m/d/y)"))
 
 (defmethod present-slot ((slot clsql-wall-time-slot-presentation) instance)
   (let ((date (presentation-slot-value slot instance)))
+    ;; Default values
+    (when (and (not date) (default-to-now-p slot))
+      (setf (presentation-slot-value slot instance) (clsql:get-time)))
+    ;;simple viewer
     (if (and date (not (editablep slot)))
        (<:as-html date))
+    ;; editor
     (when (editablep slot)
       (<ucw:input :accessor (presentation-slot-value slot instance) :id (input-id slot) :style "display:inline")
       (<:button :id (trigger-id slot) (<:as-html "[...]"))
@@ -250,7 +276,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 +373,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
@@ -356,7 +383,7 @@ Calendar.setup({
                           :initargs
                           `(:attributes ,(attributes slot)))
                           ))
-         (<:as-html "--"))))
+          (<:as-html "--"))))
 
 (defslot-presentation many-to-many-slot-presentation (mewa-relation-slot-presentation)
   ((list-view :accessor list-view :initarg :list-view :initform :one-line)
@@ -398,8 +425,8 @@ Calendar.setup({
   (let ((instances (slot-value instance (slot-name slot)))
        new-instance)
     (<:ul
-     (<:li (<ucw:a :action (add-to-many-to-many slot instance)
-                  (<:as-html "Add New")))
+     (<:li (<ucw:button :action (add-to-many-to-many slot instance)
+                        (<:as-html "Add New")))
      (<:li  (<ucw:button :action (add-to-many-to-many slot instance new-instance)
                         (<:as-html "Add:"))
            (<ucw:select :accessor new-instance
@@ -415,6 +442,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 +468,3 @@ Calendar.setup({
       
       (sync-instance instance)
       c)))
-        
-
-       
-
-
-
-
-