tag:robotlegs.tenderapp.com,2009-10-18:/discussions/problems/128-flex-how-would-you-create-a-popup-with-popupmanager-and-react-when-its-closedRobotlegs: Discussion 2018-10-18T16:35:14Ztag:robotlegs.tenderapp.com,2009-10-18:Comment/22128862010-07-09T13:57:43Z2010-07-09T14:01:27ZFlex: How would you create a popup (with PopupManager) and react when it's closed?<div><p>Hi,<br>
I'm new to Robotlegs so my question might be dumb or simple but
I've look around and couldn't find any answer to my specific
needs...</p>
<p>I have a view with a button on it that is supposed to pop a
TitleWindow up (it's an "edit window": you select something on a
list, click edit, and get this window where you can rename the item
you selected). After reading posts and FAQs I decided to do this
with a custom event and mapping a command to it. The event is
fired, the mapping executes the command that adds the popup, the
popup is filled with data bundled in the event's payload... And
that works pretty well!<br>
This TitleWindow has some kind of an OK button in it so I now
wonder how to close the popup when this OK thing is clicked and to
update the selected item (supposed to be renamed). What would be
the right way to do that? Would create another custom event and
another command? And how would you access the popup's data (like
the new name)?</p>
<p>I hope someone out there understands my needs and can help a
bit!<br>
Thanks!</p></div>Quentintag:robotlegs.tenderapp.com,2009-10-18:Comment/22128862010-07-09T18:30:14Z2010-07-09T18:30:14ZFlex: How would you create a popup (with PopupManager) and react when it's closed?<div><p>Hello,</p>
<p>Yes the popup should dispatch another event to save the data to
a model<br>
and/or update the view, you could also close the popup based on
this event.</p>
<p>Thanks</p></div>Jason Diastag:robotlegs.tenderapp.com,2009-10-18:Comment/22128862010-07-12T08:26:06Z2010-07-12T08:32:24ZFlex: How would you create a popup (with PopupManager) and react when it's closed?<div><p>Yes OK, I can do that...<br>
But my main question is: where and when do we save a reference to
the object being edited? In the event, in the popup instance,
somewhere else? And how do we access the popup's data? Does the
event have to carry all this?<br>
That seems OK to me but I'd like to be sure I'm doing things like
they're supposed to be done... Still learning!</p></div>Quentintag:robotlegs.tenderapp.com,2009-10-18:Comment/22128862010-07-12T08:34:24Z2010-07-12T08:34:24ZFlex: How would you create a popup (with PopupManager) and react when it's closed?<div><p>Assuming the object being edited is a VO, then I would pass it
along as the<br>
events payload.</p></div>Jason Diastag:robotlegs.tenderapp.com,2009-10-18:Comment/22128862010-07-12T08:55:09Z2010-07-12T09:15:38ZFlex: How would you create a popup (with PopupManager) and react when it's closed?<div><p>Yes, but would you pass it all the way through?<br>
What bugs me is that there are a lot of steps between the first
action (click to edit) and the last (update selected item)...
Here's what it looks like:</p>
<ol>
<li>Select item+edit click<br></li>
<li>Custom event (mapped to a command)<br></li>
<li>Command execution<br></li>
<li>Creation of an instance of a custom popup (mapped to a
mediator)<br></li>
<li>The mediator adds event listeners to the popup's UI<br></li>
<li>User fills the edit (rename) form<br></li>
<li>OK clicked (new event mapped to a command)<br></li>
<li>Command executed to update the item.</li>
</ol>
<p>I don't really understand how my data (the VO and the new name)
can travel all the way through and end up together in the last
command...</p>
<p>How do we pass the VO from the Command (step 3) to the popup
instance (step 4)? Should I create a variable in it to receive
that? That's what I'd do at first but that seems odd... Wouldn't
that be redundant? Is there another way to do so?</p></div>Quentintag:robotlegs.tenderapp.com,2009-10-18:Comment/22128862010-07-12T09:37:44Z2010-07-12T09:37:44ZFlex: How would you create a popup (with PopupManager) and react when it's closed?<div><p>The short answer is Yes you would pass it all the way through.
Here is a diagram outlining similar flow to what you have
described. <a href=
"http://www.robotlegs.org/diagram/">http://www.robotlegs.org/diagram/</a></p>
<p>Here is an example</p>
<ol>
<li>
<p>In my view I would create an instance of this event and assign
the item I want to install, then this event is dispatched to the
mediator, and the mediator passes it along to the event bus.</p>
<p>package com.example.events {</p>
<pre>
<code>public class UserEvent extends Event
{
public static const INSTALL_ITEM:String = "UserEvent.INSTALL_ITEM";
public static const ITEM_INSTALLED:String = "UserEvent.ITEM_INSTALLED";
public var item:IInstallable;
public function UserEvent( type:String, bubbles:Boolean = false, cancelable:Boolean = false )
{
super( type, bubbles, cancelable );
}
public override function clone():Event
{
var myEvent:UserEvent = new UserEvent( type, bubbles, cancelable );
myEvent.item = item;
return myEvent;
}
public override function toString():String
{
return formatToString( "UserEvent", "type", "bubbles", "cancelable", "eventPhase" );
}
}</code>
</pre>
<p>}</p>
</li>
<li>
<p>I have a command named "InstallItemCommand" which has the
UserEvent injected into it, this command also has my Service
injected. I pass the item into the service, and the service
processes that.</p>
<p>package com.example.remote.requests {</p>
<pre>
<code>import com.jd.remoting.core.IRemotingService;
import org.robotlegs.mvcs.Command;
public class InstallItemRequestCommand extends Command
{
[Inject]
public var event:UserEvent;
[Inject]
public var service:IRemotingService;
override public function execute():void
{
service.request(new InstallItemRequest(event.item));
}
}</code>
</pre>
<p>}</p>
</li>
<li>
<p>Once the service has completed it's operation it creates another
UserEvent instance, assigns the item that was installed to the
event, and dispatches that into the event bus.</p>
</li>
<li>
<p>If needed I would have another command mapped to the Installed
event here to update the UserModel.</p>
</li>
<li>
<p>My views mediator is also listening for the installed event, so
once received it passes the installed item into the view to be
displayed in the installed list.</p>
</li>
</ol>
<p>However it sounds like you might be trying to use RobotLegs MVCS
implementation to do low level application logic. You might be
better off putting the edit functionality into your view. Then you
would only be sending the save through the event bus.</p>
<p>disclaimer:<br>
It's really late here, and I may not be thinking clearly, if I am
off please feel free to explain your situation further.</p></div>Jason Diastag:robotlegs.tenderapp.com,2009-10-18:Comment/22128862010-07-12T10:00:57Z2010-07-12T10:00:57ZFlex: How would you create a popup (with PopupManager) and react when it's closed?<div><p>You're right this is probably too low-level to be handled this
way, it was looking to huge to be good (at least for this
purpose)!</p>
<p>I will try to have something simpler, I wanted to use all those
events+commands+mediators that are new to me but I guess it's not
really worth it here... At least I now understand how all this
works!</p>
<p>Thanks for all that, you made things a lot clearer.</p></div>Quentintag:robotlegs.tenderapp.com,2009-10-18:Comment/22128862010-07-12T10:04:12Z2010-07-12T10:04:12ZFlex: How would you create a popup (with PopupManager) and react when it's closed?<div><p>No problem, Glad I could help.</p></div>Jason Dias