[Fwd: Re: [Bese-devel] Re: dojo+ucw]

Marco Baringer mb at bese.it
Sat Feb 25 01:10:00 UTC 2006



-------- Original Message --------
Subject: Re: [Bese-devel] Re: dojo+ucw
Date: Sat, 25 Feb 2006 03:38:08 -0500
From: Drew Crampsie <drewc at tech.coop>
To: Marco Baringer <mb at bese.it>
References: <43FDC1AF.3090206 at core.gen.tr> <dtkj3l$7ss$1 at sea.gmane.org>
<43FDD00E.6080206 at core.gen.tr> <dtl40b$dcg$1 at sea.gmane.org>

Marco Baringer wrote:

>
>you can't, atm, use dojo attributes with TAL, but why can't you use
>parenscript? (i'm currently using dojo purely through javascript).
>[snip]
>i think drew's using just javascript, but maybe he'll chime in and speak
>for himself.
>
>  
>
Yeah, i loathe the idea of putting dojo tags in markup.

What i'm doing in entirely within the context of LoL, which is so far
gone from mainstream UCW i can't even use (<UCW:*) tags anymore, but
here is some of the dojo implementation for your viewing pleasure.

(deflayer dojo)

(define-layered-class
   description :in-layer dojo ()
 ((dojo-type :accessor dojo-type :initarg :dojo-type :initform nil
:special t)))

(define-layered-function display-as-dojo-type (type description object
component))

(defdisplay
 :in-layer dojo :after (description object)
(when (dojo-type description)
  (display-as-dojo-type (dojo-type description) description object self)))

All the above says is "When we are in the dojo layer, things can have a
dojo type. If so, after we display the thing we initialize the dojo
widget as well (usually changing the thing into the widget, but a host
of other hacks can be done here)"

Then, i implement a method for the various widgets in different
contexts, which end up getting used something like this :

;;;; An auto-completing search using the dojo combo box
;;;; freehand and completely untested.

(defcomponent my-search ()
((search-term :accessor search-term :initform "")
  (results :accessor results :initform nil)

(defun perform-search (term)
...)



(defmethod render ((self search))
 "Display a search box, and below it a list of results.
  If javascript is available, the search input will be an autocompete
combo-box.

  Each search result will be a link to the default viewer for that object"
(<ucw:form :action (setf (results self) (perform-search (search-term self))
   (display self self                 ;no that's not a typo
                 :type 'editor
                 :layers '(+ dojo)
                 :attributes
                  `((search-term :type string
                                           :label  "Enter  Search Term"
                                           :dojo-type  combo-box
                                           :find-function
                                            ,#'(lambda ()
(perform-search (search-term self))))
                    (results :type list
                                  :title "Search Results:"
                                  :items (:type 'one-line :layers (-
editor + wrap-link)))))
(<:submit :value "Search" :name "Search"))


here an (older) implementation of the remote combo-box for LoL (this one
is very verbose as it was my model for creating shortcuts)

the combo-box callback returns the index of the selected item in the
list in this case:

(defne-layered-method display-as-dojo-type ((type (eql 'combo-box))
attribute object component)

 (let* ((search-function (search-function attribute))
   (select-function (select-function attribute))
   (select-callback (ucw::make-new-callback
             (lambda (x)
               (funcall select-function
                    (parse-integer x))))))
   "The combo box widget"
 (<ucw:script
  `(dojo.require "dojo.*")
  `(dojo.require "dojo.widget.*")
  `(dojo.require "dojo.widget.html.ComboBox")
  (js:with-unique-js-names (element combo-box)

    `(dojo.add-on-load
      (lambda ()
    (setf ,element (dojo.by-id ,(id attribute)))
    (setf ,combo-box
          (dojo.widget.from-script
       "ComboBox"
       (create
        :data-url (+ , (lol::make-action-url
                component
                (call-component
                 (context.window-component *context*)
                 (make-instance 'combo-results
                        :results
                        (funcall search-function
                             (attribute-value object attribute)))))
               "&"
               ,(escape-as-uri (callback attribute))
               "=%{searchString}")
        :mode "remote")
       ,element))
    ((slot-value ,combo-box 'set-value) (slot-value ,element 'value))
    (dojo.event.connect
     ,combo-box "selectOption"
     (lambda ()
       (setf (slot-value ,element 'value)
         (slot-value ,combo-box 'selected-result))
       (dojo.io.bind
        (create
         :url (+ ,(lol::make-action-url
           component
           nil)
             "&"
             ,(escape-as-uri (callback attribute))
             "="
             (slot-value ,combo-box 'selected-result)
             "&"
             ,select-callback
             "="
             (slot-value ,combo-box
'combo-box-selection-value.value))))))))))))


and just for completeness :

(defmethod render ((self combo-results))
 (<:as-is (js:js* `(array
            ,@(loop for r in (results self)
                for n upfrom 0
                collect `(array ,
                      (with-output-to-string (s)
                    (yaclml:with-yaclml-stream s
                      (display self r :type 'as-string)))
                      ,n))))))

>there is no road map. i'd be happy to provide support/code wherever you
>think it'd be usefull but at the moment i don't have any plans for
>exlpclit (or official) ucw support for dojo.
>
>  
>
Lisp on Lines, OTOH, does include dojo functionality batteries included.
I'm planning a public release for April 1. Enterprising hackers can sign
up early ;).

UCW shouldn't IMO have dojo built in. I for one was very happy to see
the form stuff and the presentations dropped from the tree, and i dread
the idea of adding anything more packages! UCW is hard enough to
assemble as it is :)

drewc



-- 
-Marco
Ring the bells that still can ring.
Forget the perfect offering.
There is a crack in everything.
That's how the light gets in.
	-Leonard Cohen



More information about the bese-devel mailing list