PDA

View Full Version : Using MVC for app with multiple user roles



MrRoyce
30 Jan 2012, 10:56 AM
Hi there, I am about to start the design of a large application that needs multiple user roles (manager, administrator, client, customer, executive, etc) from a common backend server.

I am very familiar with the 3.0 design patterns, but I would like to use MVC for this application if possible. My question is for ideas or strategy for a design mechanism that would allow for easy addition and changes to a users 'view' of the application.

My 1st inclination would be towards a switch of some kind that would populate a menu bar with buttons appropriate for that user, but that just seems very procdural and not in the spirit of OO or MVC.

If anyone has any ideas or samples of applications that have a similiar requirement, I would appreciate it.

regards,
Royce

mitchellsimoens
30 Jan 2012, 11:41 AM
This all depends on your application. Mostly, do the role checking in like initComponent to show certain things depending on roles. If the role will change then you will need to add/remove what you need. You could go the route to have a base class and then have the different user roles extend that which makes different classes for each user role.

MrRoyce
30 Jan 2012, 11:46 AM
Hi Mitchell, thanks for your speedy response!

I am of course still looking around for ideas, and I see several examples of dynamically loading controllers which could be helpful. Any comments on this method?

Also, I ran across your ideas for the 'Ext.app.SubApplication' class for a multi-instance application - Did that ever make it into 4.1?

mitchellsimoens
30 Jan 2012, 11:54 AM
No, not sure the business wants this in so it is going to have to remain 3rd party for the foreseeable future.

Izhaki
30 Jan 2012, 7:13 PM
I'm doing something similar.

Have a look at this code:



Ext.define('BS.controller.base.MainMenu',
{
extend: 'Ext.app.Controller',


init: function()
{
this.control(
{
'mainmenu > button': {
click: this.menuBtnClick
},
'mainmenu menuitem': {
click: this.menuItemClick
}
});
},


menuBtnClick: function(button, event, eOpts)
{
if (button.controller)
this.application.loadPage(button.controller);
},

menuItemClick: function (item, event, eOpts)
{
if (item.controller)
this.application.loadPage(item.controller);
},

});


And then for admin:



Ext.define('BS.controller.admin.MainMenu',
{
extend: 'BS.controller.base.MainMenu',


views:
[
'admin.MainMenu'
]
});


You'd only have to load the controllers dynamically based on the user you have. Per dynamic loading in ExtJS 4, the admin views will not be loaded.

I'm still not 100% there, as still need to find a way to have PHP generating the right controller to load (rather than JS code, which is less secure). But should have it all done by friday.