WebCommand - adding a handy callback to a link

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

WebCommand - adding a handy callback to a link

Masashi UMEZAWA-2
Hi all,

I've written a small extension called WebCommand. This is helpful for
creating a link callback in a handy way.

Suppose we display address table and each row has a 'Remove' link.
Before the extension, typically you have to write:

YourApp>>viewAddresses
 (self session lastRequest includesQuery: 'command') ifTrue:[
    [command := (self session lastRequest queryAt: 'command').
    command = 'remove' ifTrue: [self observee removeAddressBy: (self
session lastRequest queryAt: 'uuid')] ].

 elem := WebElement new.
 self observee addresses
    do: [:each |
        elem cell addText: each name.
        elem newCell addLinkTo:self observee text: 'Remove' view: #addresses
            parameter: 'uuid' value: each uuid parameter: 'command'
value: 'remove'.
        elem newRow].
...

By installing this small extension, now you can write shorter code in your app:

YourApp>>viewAddresses
 elem := WebElement new.
 self observee addresses
    do: [:each |
        elem cell addText: each name.
        elem newCell addLinkDo:[self observee addresses remove: each
ifAbsent:[]] text: 'Remove'.
        elem newRow].
...

What do you think? Since I felt some awkwardness in implementing a
'remove' feature in AIDA, I made this small extension. However, I'm
still a novice in AIDA, so I would like to hear your suggestions.

Best regards,
--
[:masashi | ^umezawa]

_______________________________________________
Aida mailing list
[hidden email]
http://lists.aidaweb.si/mailman/listinfo/aida

Aida-Ex-WebCommand.5.cs (4K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: WebCommand - adding a handy callback to a link

Nicolas Petton
Hi,

It looks nice, but I'm not sure what WebCommand really is. Is it a
command pattern for Aida? Can I see the code somewhere ?

Cheers!

Nico
--
Nicolas Petton
http://nico.bioskop.fr
            ___
          ooooooo
         OOOOOOOOO
        |Smalltalk|
         OOOOOOOOO
          ooooooo
           \   /
            [|]
--------------------------------
Ma clé PGP est disponible ici :
http://nico.bioskop.fr/pgp-key.html

_______________________________________________
Aida mailing list
[hidden email]
http://lists.aidaweb.si/mailman/listinfo/aida

signature.asc (196 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: WebCommand - adding a handy callback to a link

Janko Mivšek
In reply to this post by Masashi UMEZAWA-2
Hi Masashi,

I think that having some solution for that pattern is good idea and I
also have many times a need to simplify it.

But first, me must avoid using links but use buttons instead for such
commands . Url links for any actions, that's not web friendly and it can
be even dangerous, just imagine some Google crawler visiting each of
those links. Your content would be unintentionally deleted.

That's why I'm thinking about extending WebButtons first to add
parameter:value: as we have in WebLinks. That way we will solve above
problem, then we can extend this in direction as you proposed.

Is it good to introduce a new class or maybe just extend support in
existing ones, that's a question I currently have...

JAnko


Masashi UMEZAWA wrote:

> Hi all,
>
> I've written a small extension called WebCommand. This is helpful for
> creating a link callback in a handy way.
>
> Suppose we display address table and each row has a 'Remove' link.
> Before the extension, typically you have to write:
>
> YourApp>>viewAddresses
>  (self session lastRequest includesQuery: 'command') ifTrue:[
>     [command := (self session lastRequest queryAt: 'command').
>     command = 'remove' ifTrue: [self observee removeAddressBy: (self
> session lastRequest queryAt: 'uuid')] ].
>
>  elem := WebElement new.
>  self observee addresses
>     do: [:each |
>         elem cell addText: each name.
>         elem newCell addLinkTo:self observee text: 'Remove' view: #addresses
>             parameter: 'uuid' value: each uuid parameter: 'command'
> value: 'remove'.
>         elem newRow].
> ...
>
> By installing this small extension, now you can write shorter code in your app:
>
> YourApp>>viewAddresses
>  elem := WebElement new.
>  self observee addresses
>     do: [:each |
>         elem cell addText: each name.
>         elem newCell addLinkDo:[self observee addresses remove: each
> ifAbsent:[]] text: 'Remove'.
>         elem newRow].
> ...
>
> What do you think? Since I felt some awkwardness in implementing a
> 'remove' feature in AIDA, I made this small extension. However, I'm
> still a novice in AIDA, so I would like to hear your suggestions.
>
> Best regards,
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> Aida mailing list
> [hidden email]
> http://lists.aidaweb.si/mailman/listinfo/aida

--
Janko Mivšek
AIDA/Web
Smalltalk Web Application Server
http://www.aidaweb.si
_______________________________________________
Aida mailing list
[hidden email]
http://lists.aidaweb.si/mailman/listinfo/aida
Reply | Threaded
Open this post in threaded view
|

Re: WebCommand - adding a handy callback to a link

Janko Mivšek
In reply to this post by Masashi UMEZAWA-2
Masashi UMEZAWA wrote:
> YourApp>>viewAddresses
>  elem := WebElement new.
>  self observee addresses
>     do: [:each |
>         elem cell addText: each name.
>         elem newCell addLinkDo:[self observee addresses remove: each
> ifAbsent:[]] text: 'Remove'.
>         elem newRow].
> ...

Ok, let me think about that.

elem newCell
   addLinkDo:
     [self observee addresses remove: each ifAbsent:[]]
   text: 'Remove'.

Let we change link with button

elem newCell
   addButtonDo:
     [self observee addresses remove: each ifAbsent:[]]
   text: 'Remove'.

This can probably be done by extending Aida action (POST) support. On
the first look this approach seems a nice and simple for such remove
pattern. But we mixed actions with a presentation code. Very MVC
unfriendly.

As you know in Aida we have a strict separation, not only a presentation
from model but also views from actions (action = Controller in MVC). You
can normally expect to look at action methods to see what the real
actions on domain model are so that you don't need to worry and check
all view method to find some hidden actions. If you introduce such
callbacks as above, you are introducing such hidden actions all around
the presentation code.

Well, I admit, I use such hidden actions and links for actions by myself
(just look at Admin>Security), but we need to avoid and clean up Aida of
such bad examples ASAP and use buttons and clean MVC instead.

So, Let we try to introduce buttons with parameters first, then look at
how to implement the remove action, but still in MVC manner. It wouldn't
be as simple as callbacks but in the long run more maintainable, more
clean. That's I'm sure.

Janko



>
> What do you think? Since I felt some awkwardness in implementing a
> 'remove' feature in AIDA, I made this small extension. However, I'm
> still a novice in AIDA, so I would like to hear your suggestions.
>
> Best regards,
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> Aida mailing list
> [hidden email]
> http://lists.aidaweb.si/mailman/listinfo/aida

--
Janko Mivšek
AIDA/Web
Smalltalk Web Application Server
http://www.aidaweb.si
_______________________________________________
Aida mailing list
[hidden email]
http://lists.aidaweb.si/mailman/listinfo/aida
Reply | Threaded
Open this post in threaded view
|

Re: WebCommand - adding a handy callback to a link

Nicolas Petton
In reply to this post by Masashi UMEZAWA-2
Masashi,

Even if Janko is right about links and buttons, I still think that your
work is a good idea, and that you pointed something that was missing.

So, I would like to see your code, and maybe you should keep working on
this, improve it to make it work with buttons instead of links.

Why not open a new project on the squeaksource repository so we can all
see the code, and help you :)

Keep your good work!

Nico
--
Nicolas Petton
http://nico.bioskop.fr
            ___
          ooooooo
         OOOOOOOOO
        |Smalltalk|
         OOOOOOOOO
          ooooooo
           \   /
            [|]
--------------------------------
Ma clé PGP est disponible ici :
http://nico.bioskop.fr/pgp-key.html

_______________________________________________
Aida mailing list
[hidden email]
http://lists.aidaweb.si/mailman/listinfo/aida

signature.asc (196 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: WebCommand - adding a handy callback to a link

Masashi UMEZAWA-2
Hi, Nico,

Thank you for your advice. I'll put my work to SqueakSource's AidaContributed.
I still think that callback is not so bad idea (most GUI framework has
the feature for buttons, menus, etc.). I'll refine my work so that it
will be more attractive.

Best regards,

2008/3/11, Nicolas Petton <[hidden email]>:

> Masashi,
>
>  Even if Janko is right about links and buttons, I still think that your
>  work is a good idea, and that you pointed something that was missing.
>
>  So, I would like to see your code, and maybe you should keep working on
>  this, improve it to make it work with buttons instead of links.
>
>  Why not open a new project on the squeaksource repository so we can all
>  see the code, and help you :)
>
>  Keep your good work!
>
>
>  Nico
>  --
>  Nicolas Petton
>  http://nico.bioskop.fr
>             ___
>           ooooooo
>          OOOOOOOOO
>         |Smalltalk|
>          OOOOOOOOO
>           ooooooo
>            \   /
>             [|]
>  --------------------------------
>  Ma clé PGP est disponible ici :
>  http://nico.bioskop.fr/pgp-key.html
>
> _______________________________________________
>  Aida mailing list
>  [hidden email]
>  http://lists.aidaweb.si/mailman/listinfo/aida
>

--
[:masashi | ^umezawa]
_______________________________________________
Aida mailing list
[hidden email]
http://lists.aidaweb.si/mailman/listinfo/aida
Reply | Threaded
Open this post in threaded view
|

Re: WebCommand - adding a handy callback to a link

Janko Mivšek
Hi Masashi,

Ok, let we go experimentally implement your idea, in the meantime I'll
try to extend buttons with parameters, so that your command can be
triggered with button instead of link.

Janko

Masashi UMEZAWA wrote:

> Hi, Nico,
>
> Thank you for your advice. I'll put my work to SqueakSource's AidaContributed.
> I still think that callback is not so bad idea (most GUI framework has
> the feature for buttons, menus, etc.). I'll refine my work so that it
> will be more attractive.
>
> Best regards,
>
> 2008/3/11, Nicolas Petton <[hidden email]>:
>> Masashi,
>>
>>  Even if Janko is right about links and buttons, I still think that your
>>  work is a good idea, and that you pointed something that was missing.
>>
>>  So, I would like to see your code, and maybe you should keep working on
>>  this, improve it to make it work with buttons instead of links.
>>
>>  Why not open a new project on the squeaksource repository so we can all
>>  see the code, and help you :)
>>
>>  Keep your good work!
>>
>>
>>  Nico
>>  --
>>  Nicolas Petton
>>  http://nico.bioskop.fr
>>             ___
>>           ooooooo
>>          OOOOOOOOO
>>         |Smalltalk|
>>          OOOOOOOOO
>>           ooooooo
>>            \   /
>>             [|]
>>  --------------------------------
>>  Ma clé PGP est disponible ici :
>>  http://nico.bioskop.fr/pgp-key.html
>>
>> _______________________________________________
>>  Aida mailing list
>>  [hidden email]
>>  http://lists.aidaweb.si/mailman/listinfo/aida
>>
>

--
Janko Mivšek
AIDA/Web
Smalltalk Web Application Server
http://www.aidaweb.si
_______________________________________________
Aida mailing list
[hidden email]
http://lists.aidaweb.si/mailman/listinfo/aida