PDA

View Full Version : how to enable/disable tabs on conditionality



buntyindia
22 Jan 2009, 10:58 PM
There is window having tabpanel as item and tabpanel have further grid Items.

Now If user logged in as Admin then only show all the three tabs (grid1,grid2,grid3) other wise only show grid1 and grid3


Sample code:


ClientDlg=new Ext.Window({

items:{
xtype:'tabpanel',
deferredRender:false,
layoutOnTabChange:true,
activeTab: 0,
items:[{
grid1,grid2,grid3
}]

}

});

i tried by doing as below throw error no success...Please help


user=="ADMIN"?"grid1,grid3":",grid1,grid2,grid3"

teddyjas
22 Jan 2009, 11:09 PM
probably


ClientDlg=new Ext.Window({

items:{
xtype:'tabpanel',
deferredRender:false,
layoutOnTabChange:true,
activeTab: 0,
items:[((user=="ADMIN") ? {grid1,grid3}: {grid1,grid2,grid3})]
}

});

buntyindia
23 Jan 2009, 3:15 AM
probably


ClientDlg=new Ext.Window({

items:{
xtype:'tabpanel',
deferredRender:false,
layoutOnTabChange:true,
activeTab: 0,
items:[((user=="ADMIN") ? {grid1,grid3}: {grid1,grid2,grid3})]
}

});



But what in case, if I am having


ClientDlg=new Ext.Window({

items:{
xtype:'tabpanel',
deferredRender:false,
layoutOnTabChange:true,
activeTab: 0,
items:[{
--definition of any component instead of component variable like below--
,grid2,grid3
}]

}

});
in this case lot of lines will be duplicate.
Any other way to hide tab if user is not Admin

Remy
23 Jan 2009, 3:39 AM
This may not help but I use the ux RemoteComponent (http://extjs.com/forum/showthread.php?t=18023&highlight=remotecomponent)to generate my components from the server (ASP/VBScript), returning the config in JSON. This way the server determines access and role and returns only the elements/config which applies.

darshanags
23 Jan 2009, 3:56 AM
But what in case, if I am having

in this case lot of lines will be duplicate.
Any other way to hide tab if user is not Admin

why not add the tabs after checking a condition? you can make a ajax call to the backend and get the value for the condition that you are checking.

mjlecomte
23 Jan 2009, 6:48 AM
Sample code:


items:[{
grid1,grid2,grid3
}]i tried by doing as below throw error no success...Please help


user=="ADMIN"?"grid1,grid3":",grid1,grid2,grid3"

Why are you wrapping with object literal? Are grid1, grid2, already references to an object?

As Remy points out, arguably you should never even load code that user doesn't have access to.

You could also do something like:



var myItems = [];
myItems.push(grid1);
if (user=="ADMIN") {
myItems.push(grid2);
}
myItems.push(grid3);

var ClientDlg = new Ext.Window({
...
layout: 'fit',
items: [{
xtype:'tabpanel',
deferredRender:false,
layoutOnTabChange:true,
activeTab: 0,
items: myItems
}]
});

teddyjas
23 Jan 2009, 8:19 AM
keep the js aside, I feel its best you don't do check user security (admin or non admin) on javascripts... avoid it unless you really has no other way :) like you are purely using non server side language together with the js

OTOH if u use server side scripts, you mite probably want to let the server side script generate the javascripts for u...