(
{
name = "Root";
children = ("Home", "Patients", "Reports / letters", "Families", "Biobank", "Messages", "My profile", "Admin", "Logout");
},
{
name = "Home";
directActionClass = DirectAction;
directActionName = "default";
},
{
name = "Patients";
children = ("All patients", "Add patient", "Recent patients");
directActionClass = Patients;
directActionName = "listPatients";
},
{
name = "Admin";
children = session.authenticatedUser.role.name;
childrenChoices = {
"Inactive" = ();
"Normal user" = ();
"Power user" = ("Users", "News", "Roles");
"System" = ("Users", "News", "Roles", "Centres", "Projects", "Templates", "Form types", "Encounter templates", "Import data", "View data");
};
directActionClass = Users;
directActionName = "listUsers";
},
Well, that's just a fragment. The children choices are determined at runtime using the keypath and the lookup as above.
You'll see I'm simply linking to different DAs in different classes.
All my DA classes are subclasses of a SecureDirectAction class which includes the code:
/**
* Check that user is logged in prior to executing any direct actions.
*/
@Override public WOActionResults performActionNamed(String actionName) {
if (isLoggedIn()==true) {
return super.performActionNamed(actionName);
}
return redirectToLoginPage(this.context());
}
/**
* Do we have a current and valid logged in user?
* This method is careful not to create a session if one does not exist.
* @return
*/
public boolean isLoggedIn() {
Session session = (Session) existingSession();
if (session!=null) {
if (session.authenticatedUser()==null) return false;
if (session.authenticatedUser().role()==null) return false;
return checkAccessForUser(session.authenticatedUser());
}
return false;
}
/**
* Can the given user access this page?
* Designed to be overridden by subclasses to add additional checks if necessary.
*/
protected boolean checkAccessForUser(User u) {
return u.role().canLogin();
}
My admin DA class overrides this method:
/* (non-Javadoc)
* @see com.eldrix.news.app.SecureDirectAction#checkAccessForUser(com.eldrix.rsdb.model.User)
*/
@Override
protected boolean checkAccessForUser(User u) {
return u.role().isSystem();
}
public WOActionResults listTemplatesAction() {
return listAdminData(Template.ENTITY_NAME, new String[]{"Admin","Templates", "List templates"});
}
public WOActionResults listSurgeriesAction() {
return listAdminData(Surgery.ENTITY_NAME, new String[]{"Admin","View data","SURG"});
}
public WOActionResults listConceptsAction() {
return listAdminData(Concept.ENTITY_NAME, new String[]{"Admin", "View data", "Concepts"});
}
public WOActionResults listDescriptionsAction() {
return listAdminData(Description.ENTITY_NAME, new String[]{"Admin", "View data", "Descriptions"});
}
public WOActionResults listRelationshipsAction() {
return listAdminData(Relationship.ENTITY_NAME, new String[]{"Admin","View data", "Relationships"});
}
protected WOActionResults listAdminData(String entityName, String[] navigation) {
ListPageInterface nextPage = D2W.factory().listPageForEntityNamed(entityName, session());
EODatabaseDataSource ds = new EODatabaseDataSource(ERXEC.newEditingContext(), entityName);
nextPage.setDataSource(ds);
session().navigationState().setState(new NSArray<String>(navigation));
return (WOActionResults) nextPage;
}
Hope this helps. Not entirely sure this is the *best* way of handling this stuff, but it seems to be working...
Best wishes,
Mark
On 27 September 2010 18:42, Tim Worman <
email@hidden> wrote:
> Mark:
>
> Thanks for the response. Time permitting, could you expand on what you said about "different classes reflecting different submenus?"
>
> So, I take it that the solution you're using incorporates a single NavigationMenu.plist. I was wondering about this since it only seems to be possible to point to one plist in the properties.
>
> My current navigation is a custom drop-down list using a <ul> structure and of course, it is simple for me to exclude menu items based on membership in a certain role. Since ERXNavigation is described in a plist, I've been having a hard time figuring out how you exclude items in code.
>
> Tim
>
> On Sep 26, 2010, at 11:58 PM, Mark Wardle wrote:
>
>> Hi Tim.
>>
>> I use ERXNavigation and have a large number if D2W generated pages. I
>> took the decision early on to use custom Direct Actions for these
>> menus - with different classes reflecting different submenus. I also
>> use some conventional non-D2W components manually crafted (eg the home
>> page) and so those DAs simply do a pageWithName call.
>>
>> As such you could use a custom navigation menu in a dedicated pagewrapper.
>>
>> In addition, one can change the menu at run time based on some
>> condition. My rule is session.authenticatedUser.role.isSystem for
>> example for my admin related submenus.
>>
>> Mark
>>
>> On Monday, September 27, 2010, Tim Worman <
email@hidden> wrote:
>>> All:
>>>
>>> I've set up an admin section of an existing app to use ERModernD2W. Clicking a link for admins forces the D2W stuff to load - it uses a separate page wrapper and at that point obviously also loads the ERModern entity nav. I have a tab there that takes you back to the "other" part of the app with my legacy nav. I would like to do one of two things.
>>>
>>> 1. use the ERModernD2W nav to incorporate tabs representing my legacy non-D2W navigation. I started to try and go down this road and had a lot of difficulty incorporating tabs representing my legacy functions.
>>>
>>> 2. have 2 ERXNavigation systems. Could I have another ERNavigation implementation in my app and have it load a separate NavigationMenu.plist without it interfering with the ERModernD2W nav bar?
>>>
>>> Tim Worman
>>> UCLA GSE&IS
>>>
>>>
>>>
>>>
>>> ------------------------------------------------------------------------------
>>> Start uncovering the many advantages of virtual appliances
>>> and start using them to simplify application deployment and
>>> accelerate your shift to cloud computing.
>>>
http://p.sf.net/sfu/novell-sfdev2dev
>>> _______________________________________________
>>> Wonder-disc mailing list
>>>
email@hidden>>>
https://lists.sourceforge.net/lists/listinfo/wonder-disc
>>>
>>
>> --
>> Dr. Mark Wardle
>> Specialist registrar, Neurology
>> Cardiff, UK
>
>
--
Dr. Mark Wardle
Specialist registrar, Neurology
Cardiff, UK