Best Practice for handling an Alert confirmation dialog in regard to the following ...

rickcr's Avatar

rickcr

18 May, 2010 06:09 PM

Hopefully I describe this situation adequately..

In my view there are several existing button handlers.

Each handler in the view typically grabs some view specific things (like the value of an attribute from an xml object in a DataGrid), and then puts this content into a custom event and then dispatches. eg:

   private function onJobRowDoubleClick(event:ListEvent):void {
        dispatchEvent(new LoadingEvent(LoadingEvent.WHILE_LOADING));
        var report:ReportViewerVO = new ReportViewerVO();
        report.executionID = event.itemRenderer.data.@executionID;
        report.guid = event.itemRenderer.data.@guid;
        report.reportID = event.itemRenderer.data.Report.@reportID;
        dispatchEvent(new ChangeReportEvent(ChangeReportEvent.CHANGE, report.reportID));
        dispatchEvent(new DisplayReportEvent(DisplayReportEvent.DISPLAY_REPORT, report));
    }

eg:

    public function populateReportBuilder(event:MouseEvent):void {
        dispatchEvent(new LoadingEvent(LoadingEvent.WHILE_LOADING));
        var obj:XML = XML(executions.getItemAt(executionGrid.selectedIndex));
        dispatchEvent(new JobExecutionEvent(JobExecutionEvent.RETRIEVE_EXECUTION, obj.@executionID));
        dispatchEvent(new ShowReportBuilderEvent(ShowReportBuilderEvent.DISPLAY));
        dispatchEvent(new ChangeReportEvent(ChangeReportEvent.CHANGE, obj.Report.@reportID));
    }

Several similar type handlers exist on the view. The view's mediator of course has those events registered and then dispatches them..
eg:

eventMap.mapListener(view, ChangeReportEvent.CHANGE, dispatch);

Now the issue is that before any of the view's handlers begin their operations, I need to pop up an Alert confirmation dialog, but ONLY if a certain condition exists on my backing Model.

If the user clicks "Yes" to continue, I need to update a boolean on the Model and then proceed with the typical set of dispatched events that you see in the above handler.

So now, being new to Flex, I have several issues I'm wondering how to tackle:

I don't think I want to attach all the event handlers to the view components in my mediator, but I will if that makes things easier. But even if I do push all my view handling into the mediator, I'm still stuck with understanding how to handle things with the Alert's callback. From my understanding the alert callback accepts a CloseEvent - so I lose my reference to the dispatched Event, unless I store that Event in my mediator as an instance var or start storing the content of that Event as instance vars in my Mediator. All of this seems like such a pain in the arse. What I was thinking about doing was taking this approach, but not sure if it sucks or not:

On view (taking the second method implementation as an example):

    public function populateReportBuilderHandler(event:MouseEvent):void {
        dispatchEvent(new AlertCheckIfCanContinueEvent(AlertCheckIfCanContinueEvent.CAN_CONTINUE));
    }

    //will be called from Mediator
    public function populateReportBuilder():void {
        dispatchEvent(new LoadingEvent(LoadingEvent.WHILE_LOADING));
        var obj:XML = XML(executions.getItemAt(executionGrid.selectedIndex));
        dispatchEvent(new JobExecutionEvent(JobExecutionEvent.RETRIEVE_EXECUTION, obj.@executionID));
        dispatchEvent(new ShowReportBuilderEvent(ShowReportBuilderEvent.DISPLAY));
        dispatchEvent(new ChangeReportEvent(ChangeReportEvent.CHANGE, obj.Report.@reportID));
    }

In mediator:
Handles the Alert and then in the callback

    private function handleAlert(event:CloseEvent):void {
    if (event.detail == Alert.YES) {
        view.populateReportBuilder()            
    }
   }

The above should work ok I think, but it seems sort of odd calling back down to the view. But then again I don't think my mediator should have now about the xml parsing of a datagrid row.

Is the above an ok approach?

  1. Stray closed this discussion on 10 Feb, 2011 05:18 PM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac