PureMVC Architects Lounge

Announcements and General Discussion => Getting Started => Topic started by: vladakg85 on July 02, 2009, 01:10:19



Title: popup question
Post by: vladakg85 on July 02, 2009, 01:10:19
How to register mediator for popup? I dont know what parameter to pass in:
:
facade.registerMediator(new DetailsPopupMediaotr(???));

I use the following popup class, I wonder is this one http://www.nutrixinteractive.com/blog/?p=329 better, somehow?

:
package util.popup
{
import flash.display.DisplayObject;
import flash.display.Sprite;

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

import org.puremvc.as3.multicore.patterns.facade.Facade;

/**
* Used to handle popup opening controling registering and unregistering mediators
*
* @author
*/

public class PopManager extends PopUpManager
{
private static var popupList:Array=new Array();

/**
* Opens a popup window. Window component is crated and mediator is assigned to it.
* Targeted for PureMVC multicore so method requires moduleId to be passed
*/
public static function openPopUpWindow(ComponentClass:Class, MediatorClass:Class, moduleUid:String, modal:Boolean=true, parent:DisplayObject=null):IFlexDisplayObject
{
if (parent == null)
{
parent=Application.application as DisplayObject;
}
var window:IFlexDisplayObject=PopUpManager.createPopUp(parent, ComponentClass, modal);
var obj:Facade=Facade.getInstance(moduleUid)as Facade;

obj.registerMediator(new MediatorClass(window));
PopUpManager.centerPopUp(window);
return window;
}

/**
*  Removes PopUp window and unregisteres associated mediator
*/
public static function closePopUpWindow(window:IFlexDisplayObject, mediatorName:String, moduleUid:String):void
{
PopUpManager.removePopUp(window);
Facade.getInstance(moduleUid).removeMediator(mediatorName);
}

/**
*
* Tries to retrieve popup window from the list of popups already opened. If there is no window opened with
* provided mediator name associated with it, a new one is created and displayed.
*/
public static function retrievePopUp(ComponentClass:Class, MediatorClass:Class, mediatorName:String, moduleUid:String, modal:Boolean=true):IFlexDisplayObject
{
if (popupList[mediatorName])
{
PopUpManager.addPopUp(popupList[mediatorName]as IFlexDisplayObject, Application.application as Sprite, modal);
PopUpManager.bringToFront(popupList[mediatorName]);
}
else
{
popupList[mediatorName]=openPopUpWindow(ComponentClass, MediatorClass, moduleUid, modal)
}
return popupList[mediatorName];
}

/**
*  Removes popup from display list. The actual popup object still exists in the list and can be retrieved
*/
public static function hidePopUp(window:IFlexDisplayObject, mediatorName:String):void
{
PopUpManager.removePopUp(window);
}

/**
* Removes the popup completle. Also unregisters mediator.
*/
public static function destroyPopUp(window:IFlexDisplayObject, mediatorName:String, moduleUid:String):void
{
closePopUpWindow(window, mediatorName, moduleUid);

if (popupList[mediatorName])
{
popupList[mediatorName]=null;
}
}
}


}


Title: Re: popup question
Post by: puremvc on July 02, 2009, 03:16:57
You can create the popup component and then pass it to its mediator constructor, or you can have the mediator take no argument and create the popup itself in its constructor.


-=Cliff>


Title: Re: popup question
Post by: xAvIxXxXx on July 15, 2009, 07:51:03
You use the Multicore or the standard version ?


Title: Re: popup question
Post by: puremvc on July 15, 2009, 09:46:18
Me? MultiCore, even if I only have one Core. This lets me break it into a modular app quickly and easily at anytime. And unit testing things is easier since you can get a new facade for each test, and don't have to do much teardown/setup.

-=Cliff>


Title: Re: popup question
Post by: xAvIxXxXx on July 22, 2009, 08:06:35
It was to understand the post but your answer is interesting and I have understand vladak problem now.
In my view the class (PopManager) is very useful because it is generic and well adapted to the multicore.