PDA

View Full Version : Conditional loading of items in a viewport



aityahia
13 Nov 2013, 2:14 AM
hello,

hello,
to manage user access,i need to disable loading some items, in a viewport for now i hide them with a the "hidden" property, but I can't prevent the background processing for this items, such as the server request

how can i disable loading for a specific items.

this my viewport code


var notAllowAdmin=true; //init access rule gere for admin panel

Ext.define('eFinances.view.Viewport', {
extend: 'Ext.container.Viewport',
requires: [
'Ext.layout.container.Border'
],

layout: 'border',

items: [
{
xtype: 'eFinancesToolbar',
region: 'north'
},
{

title: 'Navigation',
region: 'west',
collapsible: true,
split: true,
width: 200,
minWidth: 175,
maxWidth: 400,
animCollapse: true,
margins: '0 0 0 5',
layout: 'accordion',
items: [{
xtype:'menuTresorerie',
title: 'Trésoreries',
iconCls: 'balance' // see the HEAD section for style used


},{

xtype:'menuAchat',
title: 'Achat et fournisseurs',
iconCls: 'depense' // see the HEAD section for style used

}, {
xtype:'menuVente',
title: 'Ventes et clients',
iconCls: 'recette'
}, {
xtype:'menuAdmin',
hidden :notAllowAdmin, // hide items if not allowed
title: 'Administration',
iconCls: 'administration'

}]

},
{
region: 'center',
title: 'work area'
}
]

});

for the moment i hide admin panel with notAllowAdmin variable initialized with rules access , but whole background process are executed, some can tell me how to proceed to completly disactivate panel loading or give me best idea to do this (managing users access)

regards

scottmartin
14 Nov 2013, 8:34 PM
Instead of hiding items, only add them if they are allowed?


if (admin) {

container.add({
xtype: 'menuAdmin',
title: 'Administration'
});
container.doLayout();

}

aityahia
17 Nov 2013, 12:22 AM
Thank you for your reply, I will try your solution, it is cleaner than the following, by using a conditional concat.



items: [{
xtype:'menuTresorerie',
title: 'Trésoreries',
iconCls: 'balance' // see the HEAD section for style used


},{

xtype:'menuAchat',
title: 'Achat et fournisseurs',
iconCls: 'depense' // see the HEAD section for style used

}, {
xtype:'menuVente',
title: 'Ventes et clients',
iconCls: 'recette'
}].concat(notAllowAdmin ? [] : [
{
xtype:'menuAdmin',
title: 'Administration',
iconCls: 'administration'
}
])

},
{
region: 'center',
title: 'work area'
}
]

});