PDA

View Full Version : loading accordion dynamically from database



maren
15 Jul 2009, 3:54 AM
hi,
i'm newbies in extjs and to load my accordion dynamically from a database :-/
Someone have an idea how to do it?
thanks

steffenk
15 Jul 2009, 4:10 AM
what do you mean, the content?

Try to build a simple accordion first to see how it works. You have a normal HTML markup with content and transform it to an accordion.

maren
15 Jul 2009, 10:47 PM
hi,
i mean items of accordion

Stripeman
16 Jul 2009, 2:07 AM
Your question is pretty plain Jane... is your question more like how do I add items to a an accoridan panel dynamically ? if so... this is how i did it...

On your PHP (constant include) page you can do something like this...


<?php

$_SESSION['Roles'] = @str_split($obj->Roles,1); //Permission Array
if (@$_SESSION['Roles']) {

$permarray = $_SESSION['Roles'];

// Run through each permissions (contained in array) and bulid the permission ledgend
$perms='';
for ($i=0; $i <= count($permarray); $i++) {
$eaPerm = $permarray[$i];
switch ($eaPerm) {
case 'A':
$eaPerm = "A: Admin";
?> permsAdmin = true; <?php //set the JS var to unhide menu items
break;
case 'M':
$eaPerm = "M: Member";
?> permsMember = true; <?php //set the JS var to unhide menu items
break;
case 'S':
$eaPerm = "S: Super/DB Admin";
?> permsSuperAdmin = true; <?php //set the JS var to unhide menu items
break;
case 'O':
$eaPerm = "O: Other";
?> permsOther = true; <?php //set the JS var to unhide menu items
break;

}
$perms .= $eaPerm.'<br>';
}
}

?>



Then .. in your JS for your accordion:


if (permsSuperAdmin){ // User is Super/DB Admin
addWestMenuItems.add({
cls: 'west-panel-content',
title:'DB Admin',
autoHeight: true,
id: 'acc_genDBAdmin',
showPin:true,
stateId:'acc_genDBAdmin',
border:false,
iconCls:'settings',
bodyStyle: 'background-color:#FFE680;',
xtype: 'treepanel',
dataUrl: 'get_nav.php?getNav=genDBAdmin',
root: new Ext.tree.AsyncTreeNode({
expanded: true,
text: 'Administrative DB Functions',
id: 'id_siteDBAdmin',
qtip: 'Site DB Administrative Functions'
})
});
} // End Check if user is Super/DB Admin


in my "get_nav.php?getNav=genDBAdmin"

I have this code to actually build the items in the accordian ( i have one for each accordian) and its contents are restrictive based on permissions (from db) - see session loop at top:


if(($getNav == 'genDBAdmin') && (in_array("A",$_SESSION['Roles']))){ //IS "A"dmin function
$string_getNav .= "
{
text: 'New (all)',
url : '?page=adminViewAllUsers',
leaf: true,
qtip: 'View all Users'
},";


$string_getNav .= "
{
id: 'id_jobPositions',
text: 'Positions',
href : '?page=adminPositions',
leaf: true,
qtip: 'Add/Remove positions'
},";
} // END $getNav == 'genDBAdmin'



Hope that helps and is what your looking for... an example with this capability should be added as an Ext sample/example. Not saying that this is good enough to be an example we should use, but something simular