Futurescale, Inc. PureMVC Home

The PureMVC Framework Code at the Speed of Thought


Over 10 years of community discussion and knowledge are maintained here as a read-only archive.

New discussions should be taken up in issues on the appropriate projects at https://github.com/PureMVC

Pages: [1]
Print
Author Topic: Open a popup form by MainViewMediator ? is it the good way ?  (Read 7825 times)
fidiman
Full Member
***
Posts: 23


View Profile Email
« on: September 23, 2008, 05:43:39 »

Hi,

I need to open a form with popupmanager.

The form is one of the components view.

So i've added a mediator to the MainView that have the responsability to manage the popup.


:
package com.freddufau.eshop.view
{
import com.freddufau.eshop.ApplicationFacade;

import com.freddufau.eshop.model.vo.*;
import com.freddufau.eshop.view.MainViewMediator;
import com.freddufau.eshop.view.components.*;
import flash.events.Event;
import org.puremvc.as3.interfaces.IMediator;
import org.puremvc.as3.interfaces.INotification;
import org.puremvc.as3.patterns.mediator.Mediator;

import mx.managers.PopUpManager;
import mx.core.IFlexDisplayObject;

public class MainViewMediator extends Mediator implements IMediator
{


public static const NAME:String = 'MainViewMediatorMediator';


public function MainViewMediator(viewComponent:Object=null)
{
super(NAME, viewComponent);
// Add Listeners

}


public function get mainViewMediator():MainViewMediator{
return viewComponent as MainViewMediator;
}



override public function listNotificationInterests():Array
{
return [ ApplicationFacade.SHOW_CREATE_FORM

];
}

override public function handleNotification(notification:INotification):void
{

switch ( notification.getName() )
{
case ApplicationFacade.SHOW_CREATE_FORM:

createPopUpForm();

break;

default : break;
}

}

private function createPopUpForm():void
{
var createProductPopUp : ProductForm = PopUpManager.createPopUp( ApplicationFacade.MAIN_VIEW, ProductForm, false ) as ProductForm;
createProductPopUp.mode = "create";
PopUpManager.centerPopUp( createProductPopUp );
}

}
}

So i've needed to create the static var MAIN_VIEW in the facade to hold the popup on top.

Is this a good way ?

And to close, i will listen the closeNotification ?

Thanks;
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #1 on: September 23, 2008, 08:52:03 »

Although you may overload a Mediator's responsibilities by having it deal additionally with the Popups that its view component invokes, you will find this is really not a good way to go. For apps with popups that are more complex, you generally want a mediator just for the popup. But that means registering and unregistering that popup's Mediator when invoked and is dismissed.

Here is a great solution: http://www.nutrixinteractive.com/blog/?p=76

In this article, Simon creates a simple 'PopManager' class with static functions for showing a popup and registering its Mediator, or dismissing it and removing the Mediator.

-=Cliff>
Logged
fidiman
Full Member
***
Posts: 23


View Profile Email
« Reply #2 on: September 24, 2008, 12:14:05 »

Ok thanks for this helpful link.

I wasn't thinking about removeMediator  :-*
Logged
newtriks
Courseware Beta
Full Member
***
Posts: 23


 - newtriks
View Profile WWW Email
« Reply #3 on: February 08, 2009, 08:58:05 »

Here is an update to that logic:

http://www.nutrixinteractive.com/blog/?p=329
Logged
Pages: [1]
Print