Magritte seaside save

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

Magritte seaside save

Vitor Medina Cruz
Hello,

So:

MyObject new asComponent addValidatedForm

How do I define save callBack?

I tried:

MyObject new asComponent addValidatedForm : {#save -> 'save'. #cancel -> 'cancel'}.

and defined save in both instance or class side of MyObject, but that didn't work.

Regards,
Vitor.

Livre de vírus. www.avg.com.
Reply | Threaded
Open this post in threaded view
|

Re: Magritte seaside save

DiegoLont
Hi Vitor,

It has been a while that I really used Magritte, but basically the problem that you encounter is that the save is not called on MyObject, but on the component that is created from MyObject (in the method asComponent). The save method calls the save on the component, and in Magritte that is implemented, so without doing much it should perform the following code:

MAContainerComponent >> save
self validate ifFalse: [ ^ self ].
self commit; answer: self model

The validate calls the validation rules on the magritteDescription, the commit stores the changes the user made in the object, and answer allows the container to do further actions for the same event (as the button is actually created in the decoration, and not in the container itself).

So when you want to intercept the save method, you could use a block instead of a simple symbol:

MyObject new asComponent addValidatedForm : { [ :container |
| myObject |
“ do something you want to do before the save takes place “
container save.
myObject := container model.
“ when it reaches here, the save was successful and you can send a message to myObject, i.e. “
myObject save ] -> 'save'. #cancel -> 'cancel'}.

Another approach is to change the component that is created by overriding the componentClass of MyObject, and implementing the save in the new subclass you created.

Regards,
Diego

On 29 Dec 2018, at 17:14, Vitor Medina Cruz <[hidden email]> wrote:

Hello,

So:

MyObject new asComponent addValidatedForm

How do I define save callBack?

I tried:

MyObject new asComponent addValidatedForm : {#save -> 'save'. #cancel -> 'cancel'}.

and defined save in both instance or class side of MyObject, but that didn't work.

Regards,
Vitor.

Livre de vírus. www.avg.com.
<a href="x-msg://13/#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2" width="1" height="1" class="">

Reply | Threaded
Open this post in threaded view
|

Re: Magritte seaside save

Vitor Medina Cruz
OMG Thank You! I figure the first part, but I went crazy here debugging, and I probably would never ever figure the second part, a list with a block... Is there documentation for that somewhere? In https://github.com/magritte-metamodel/magritte most of docs links are broken.... :´(

Livre de vírus. www.avg.com.

On Sun, Dec 30, 2018 at 4:51 PM Diego Lont <[hidden email]> wrote:
Hi Vitor,

It has been a while that I really used Magritte, but basically the problem that you encounter is that the save is not called on MyObject, but on the component that is created from MyObject (in the method asComponent). The save method calls the save on the component, and in Magritte that is implemented, so without doing much it should perform the following code:

MAContainerComponent >> save
self validate ifFalse: [ ^ self ].
self commit; answer: self model

The validate calls the validation rules on the magritteDescription, the commit stores the changes the user made in the object, and answer allows the container to do further actions for the same event (as the button is actually created in the decoration, and not in the container itself).

So when you want to intercept the save method, you could use a block instead of a simple symbol:

MyObject new asComponent addValidatedForm : { [ :container |
| myObject |
“ do something you want to do before the save takes place “
container save.
myObject := container model.
“ when it reaches here, the save was successful and you can send a message to myObject, i.e. “
myObject save ] -> 'save'. #cancel -> 'cancel'}.

Another approach is to change the component that is created by overriding the componentClass of MyObject, and implementing the save in the new subclass you created.

Regards,
Diego

On 29 Dec 2018, at 17:14, Vitor Medina Cruz <[hidden email]> wrote:

Hello,

So:

MyObject new asComponent addValidatedForm

How do I define save callBack?

I tried:

MyObject new asComponent addValidatedForm : {#save -> 'save'. #cancel -> 'cancel'}.

and defined save in both instance or class side of MyObject, but that didn't work.

Regards,
Vitor.

Livre de vírus. www.avg.com.