views:

30

answers:

2

I'm working in Flex 4.1, and I have a viewstack and tabbar as my main navigation. A user logs into the application and should then only be able to see what tabs are available to his user level.

I am trying to stick with MXML as much as possible, since it works well with the framework. But I'm goin numb thinking about this. What are the common practices for doing this?

FYI: the user level is slightly to complex for states. There are lots of options, way to many to comfortably do w/ states and state groups.

Chimp is a pretty cool library for those interested. It's a little old and there doesn't seem to be much motivation to expand it past UIComponents. So for my purposes it wont do.

Again, what do you do for setting up these systems?

UPDATE: I had to compromise, but it actually worked out pretty well in the end. Instead of destructively laying on permissions (having everything available at first and removing the elements thereafter), the system now works constructively. Here's a sample:

[Bindable]
public var managePage:ManagePage;
[Bindable]
public var reportPage:ReportPage;

    ...

switch(permission)
{
    case "create":
        navigatorContent.label = "Manage";
        navigatorContent.addElement(managePage);
        viewStack.addElementAt(navigatorContent,1);
            break;
    case "read":
        navigatorContent.label = "Report";
        navigatorContent.addElement(reportPage);
        viewStack.addElementAt(navigatorContent,2);
            break;
}

Obviously this is only for adding elements, but removing them is just as easy. This solution leaves me with everything I was looking for, so I'm happy.

+1  A: 

For all intents and purposes you have to build your own framework for handling the permission / security issues of your application. The TabBar component can accept a dataProvider, so just create one based on the user login; and it is an easy way to modify your navigation based on the user.

www.Flextras.com
I think your solution is solid, but it doesn't work very well within the application framework/methodology I'm running with. I did however take half of your advice. I basically have a switchboard adding/removing elements based on permissions passed in. See update.
Noah Smith
Glad you got it working. If you don't feel my answer deserves the "correct" mark; be sure to write up your own answer and select it as the correct one. Questions like this are tough because they are very open ended.
www.Flextras.com
A: 

So a more elaborate final solution:

[Bindable]
protected var managePageView:NavigatorContent;
[Bindable]
protected var managePage:ManagePage;
[Bindable]
protected var reportPageView:NavigatorContent;
[Bindable]
protected var reportPage:ReportPage;

    ...

public function permissionCreate(permission:String):void
{
    switch(permission)
    {
        case "create":
            managePageView.label = "Manage";
            managePageView.addElement(managePage);
            viewStack.addElementAt(managePageView,1);
                break;
        case "read":
            reportPageView.label = "Report";
            reportPageView.addElement(reportPage);
            viewStack.addElementAt(reportPageView,2);
                break;
    }
}
public function permissionRemove(permission:String):void
{
    switch(permission)
    {
        case "create":
            managePageView.removeElement(managePage);
            viewStack.removeElementAt(managePageView,1);
                break;
        case "read":
            reportPageView.removeElement(reportPage);
            viewStack.removeElementAt(reportPageView,2);
                break;
    }
}

I'm going too turn this into a library in the next month or so.

Noah Smith