PDA

View Full Version : Manage of creating buttons



Ilay
12 Aug 2013, 5:45 AM
Hi.
I want to manage permissions for showing button e.g "delete" button for user with admin role.
For now i see 2 ways to realize it,
first:


{
xtype:"button",
permisionID:"deleteButton",
text:"Delete",
visible:checkPermision()//return true if user can delete
}

this way is not good because we creating a button.
Another way:


initComponent:->
{
deleteButton= {
xtype: "button",
permissionID: "deleteButton",
text:"Delete"
}
if (checkPermision()) {
deleteButton= {};
}
}
.......
Ext.applyIf(me, {
items:[deleteButton]
}
)

this way looks better but for each button i should support a lot of "if statement". I want put check in one place and manage it in general.


Maybe exists a common approach to realize it?
Thanks.

IvanJouikov
14 Aug 2013, 12:50 PM
Hi Ilay,

I have personally used both approaches that you described (except "hidden" attribute instead of "visible" in the first case).

There is no out-of-the-box framework to help you achieve what you're looking for, but due to the flexibility of the framework (even as demonstrated in the two approaches you described), it would be real easy to streamline it. This can be a very fun and creative aspect of building an application.

I made an example that demonstrates what I'm talking about; I enjoyed writing it because there's a thousand different ways to do something like this.

Note how I'm utilizing my "security model" via a simple panel configuration property "securityRequirement":



Ext.onReady(function() {
Ext.create('MyApp.panel.Secure', {
renderTo: Ext.getBody(),
margin: 20,
bodyPadding: 20,
title: 'User Panel',
html: 'For Users Only!',
securityRequirement: 'user'
});
Ext.create('MyApp.panel.Secure', {
renderTo: Ext.getBody(),
margin: 20,
bodyPadding: 20,
title: 'Admin Panel',
html: 'For Admins Only!',
securityRequirement: 'admin'
});
});


8q

I hope this helps!

Ilay
14 Aug 2013, 11:43 PM
Thank you IvanJouikov (http://www.sencha.com/forum/member.php?551356-IvanJouikov) for your replying.
My solution very similar to yours.

Ilay
14 Aug 2013, 11:47 PM
IvanNikov can you add another way to solve it. Something different about current solution. Thanks.

IvanJouikov
15 Aug 2013, 9:03 AM
Can you clarify different in what way?