Illiad implementation of Reef search example

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Illiad implementation of Reef search example

tfleig
Here is an implementation of the Reef search example that I created for comparison purposes.

One problem I had was that the argument passed to the block that is the parameter of the onKeyPress: method does not include the last character entered -- the one for which the key press event is being triggered. I used the keyUp event instead, which does include the just-entered character. A drawback to that is that the event is fired for keyUp events of the Shift key and the AJAX callback is then invoked unnecessarily.


ILWidget subclass: #ILSearchPart
        instanceVariableNames: ''
        classVariableNames: ''
        poolDictionaries: ''
        category: 'TF-Iliad'!

!ILSearchPart methodsFor: 'building' stamp: 'TonyFleig 12/1/2010 20:52'!
contents
        ^ [ :e | | results  searchText |
                e form build: [ :form |
                        form text: 'Search: '.
                        form input
                                beSubmitOnEvent: 'keyup';
                                action: [ :v |
                                        searchText:= v.
                                        results markDirty ].
                        form build: (results := self widgetFor: [ :w |
                                (self search: searchText) do: [ :each |
                                        w div text: each ]])]]
! !


!ILSearchPart methodsFor: 'private' stamp: 'TonyFleig 12/1/2010 20:55'!
search: text
        ^ (text isNil or: [ text isEmpty ])
                ifTrue: [ #() ]
                ifFalse: [
                        Smalltalk classNames select: [ :each |
                                each beginsWith: text ]].
               
                       
! !


ILApplication subclass: #ILWebApplication
        instanceVariableNames: 'searchPart'
        classVariableNames: ''
        poolDictionaries: ''
        category: 'TF-Iliad'!

!ILWebApplication methodsFor: 'controllers' stamp: 'TonyFleig 12/1/2010 19:04'!
index
        ^ [: e | e
                build: self searchPart ]! !


!ILWebApplication methodsFor: 'accessing' stamp: 'TonyFleig 12/1/2010 18:07'!
searchPart
        ^ searchPart ifNil: [ searchPart := ILSearchPart new ]! !

"-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "!

ILWebApplication class
        instanceVariableNames: ''!

!ILWebApplication class methodsFor: 'class initialization' stamp: 'TonyFleig 12/1/2010 17:52'!
path
        ^'search'! !
Reply | Threaded
Open this post in threaded view
|

Re: Illiad implementation of Reef search example

sebastien audier
Hi tony, it's very interesting, and I try it immediately.

--
Sébastien AUDIER

ObjectFusion S.A.R.L.
Applications web, consulting, design
http://www.objectfusion.fr
Reply | Threaded
Open this post in threaded view
|

Re: Illiad implementation of Reef search example

Nicolas Petton
In reply to this post by tfleig
I don't know if it makes sense for your example, but do you know that
you can trigger smalltalk blocks on DOM events:

e form input onKeyDown: '//some javascript code'.
e form input onKeyDownDo: ["some smalltalk code"].

this will work for all kinds of DOM events: #onClickDo:, etc.

Nico


Le jeudi 02 décembre 2010 à 12:20 -0800, tfleig a écrit :

> Here is an implementation of the Reef search example that I created for
> comparison purposes.
>
> One problem I had was that the argument passed to the block that is the
> parameter of the onKeyPress: method does not include the last character
> entered -- the one for which the key press event is being triggered. I used
> the keyUp event instead, which does include the just-entered character. A
> drawback to that is that the event is fired for keyUp events of the Shift
> key and the AJAX callback is then invoked unnecessarily.
>
>
> ILWidget subclass: #ILSearchPart
> instanceVariableNames: ''
> classVariableNames: ''
> poolDictionaries: ''
> category: 'TF-Iliad'!
>
> !ILSearchPart methodsFor: 'building' stamp: 'TonyFleig 12/1/2010 20:52'!
> contents
> ^ [ :e | | results  searchText |
> e form build: [ :form |
> form text: 'Search: '.
> form input
> beSubmitOnEvent: 'keyup';
> action: [ :v |
> searchText:= v.
> results markDirty ].
> form build: (results := self widgetFor: [ :w |
> (self search: searchText) do: [ :each |
> w div text: each ]])]]
> ! !
>
>
> !ILSearchPart methodsFor: 'private' stamp: 'TonyFleig 12/1/2010 20:55'!
> search: text
> ^ (text isNil or: [ text isEmpty ])
> ifTrue: [ #() ]
> ifFalse: [
> Smalltalk classNames select: [ :each |
> each beginsWith: text ]].
>
>
> ! !
>
>
> ILApplication subclass: #ILWebApplication
> instanceVariableNames: 'searchPart'
> classVariableNames: ''
> poolDictionaries: ''
> category: 'TF-Iliad'!
>
> !ILWebApplication methodsFor: 'controllers' stamp: 'TonyFleig 12/1/2010
> 19:04'!
> index
> ^ [: e | e
> build: self searchPart ]! !
>
>
> !ILWebApplication methodsFor: 'accessing' stamp: 'TonyFleig 12/1/2010
> 18:07'!
> searchPart
> ^ searchPart ifNil: [ searchPart := ILSearchPart new ]! !
>
> "-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "!
>
> ILWebApplication class
> instanceVariableNames: ''!
>
> !ILWebApplication class methodsFor: 'class initialization' stamp: 'TonyFleig
> 12/1/2010 17:52'!
> path
> ^'search'! !
>


Reply | Threaded
Open this post in threaded view
|

Re: Illiad implementation of Reef search example

Nicolas Petton
In reply to this post by tfleig
Le jeudi 02 décembre 2010 à 12:20 -0800, tfleig a écrit :
>
> One problem I had was that the argument passed to the block that is
> the
> parameter of the onKeyPress: method does not include the last
> character
> entered

Thanks for reporting this. It is actually quite strange. #onKeyPress: is
just a convenience method for #onEvent:add:, exactly like #onKeyDown:,
#onClick:, etc.

Anyway I'll investigate.

Nico

Reply | Threaded
Open this post in threaded view
|

Re: Illiad implementation of Reef search example

sebastien audier

Well, I tested it, and adapted it for gst namespace.
I added css, div, title...

Would you agree to add it in Iliad examples?
You will be mentionned of course. :)


--
Sébastien AUDIER

ObjectFusion S.A.R.L.
Applications web, consulting, design
http://www.objectfusion.fr
Reply | Threaded
Open this post in threaded view
|

Re: Illiad implementation of Reef search example

tfleig
In reply to this post by Nicolas Petton
I did not know that the DOM events were available like this. Excellent!

(I am assuming that the "Do" suffix after the event name is a convention that I can rely on to mean that the method expects a Smalltalk code block.)

TF
Reply | Threaded
Open this post in threaded view
|

Re: Illiad implementation of Reef search example

tfleig
In reply to this post by sebastien audier
Of course you may use it in examples. I'm flattered.

TF