Retour de l'ajax pour les performances

This commit is contained in:
Michael RICOIS 2012-01-16 20:07:43 +00:00
parent 324864b4e8
commit 14c68377fe
4 changed files with 26 additions and 24 deletions

View File

@ -9,15 +9,12 @@ class ArborescenceController extends Zend_Controller_Action
{
$this->_helper->layout()->disableLayout();
$this->view->inlineScript()->appendFile('/themes/default/scripts/jquery.jstree.js');
$request = $this->getRequest();
$key = $request->getParam('key');
$this->view->assign('key', $key);
$niveau = 1;
$niveau = $request->getParam('niveau', 1);
$nafM = new Application_Model_Naf();
//Niveau 1
$sql = $nafM->select()->where('niveau = ?', $niveau)->order('code ASC');
$result = $nafM->fetchAll($sql)->toArray();
$tabNaf = array();
@ -26,14 +23,21 @@ class ArborescenceController extends Zend_Controller_Action
'data' => $item['code'].' - '.$item['lib'],
'attr' => array('id' => $item['code'], 'niveau' => $item['niveau']),
'state' => 'closed',
'children' => $this->getNaf(2, $item['code']),
);
'children' => array(),
);
}
$this->view->assign('naf', json_encode($tabNaf));
}
protected function getNaf($niveau, $parent = '')
public function nafajaxAction()
{
$this->_helper->layout()->disableLayout();
$this->_helper->viewRenderer->setNoRender();
$request = $this->getRequest();
$niveau = $request->getParam('niveau', 1);
$niveau++;
$parent = $request->getParam('parent', '');
$nafM = new Application_Model_Naf();
$sql = $nafM->select();
if (!empty($parent) && $niveau==2) {
@ -41,25 +45,24 @@ class ArborescenceController extends Zend_Controller_Action
} elseif (!empty($parent) && $niveau>2) {
$sql->where("code LIKE '".$parent."%'");
}
$sql->where('niveau = ?', $niveau)->order('code ASC');
$sql->where('niveau = ?', $niveau)->order('code ASC');
$result = $nafM->fetchAll($sql)->toArray();
$tabNaf = array();
foreach($result as $item){
$naf = array(
'data' => $item['code'].' - '.$item['lib'],
'attr' => array('id' => $item['code'], 'niveau' => $item['niveau']),
);
);
if ($niveau<5){
$niveau++;
$naf['state'] = 'closed';
$naf['children'] = $this->getNaf($niveau, $item['code']);
$naf['children'] = array();
}
$tabNaf[] = $naf;
}
return $tabNaf;
echo json_encode($tabNaf);
}
/**
*
* Enter description here ...

View File

@ -9,6 +9,7 @@ class CriteresController extends Zend_Controller_Action
$user = $auth->getIdentity();
$field = new Fields($user->username);
$this->view->fields = $field;
$this->view->headScript()->appendFile('/themes/default/scripts/jquery.jstree.js', 'text/javascript');
}
public function indexAction(){}
@ -19,9 +20,7 @@ class CriteresController extends Zend_Controller_Action
public function economiqueAction(){}
public function geographiqueAction(){
$this->view->inlineScript()->appendFile('/themes/default/scripts/jquery.jstree.js');
}
public function geographiqueAction(){}
public function juridiqueAction(){}

View File

@ -1,8 +1,4 @@
<p>Liste des NAF</p>
<div id="<?=$this->key?>" class="jstree jstree-default" style="height:300px;width:680px;overflow:auto;">
</div>
<?=$this->inlineScript()?>
<div id="<?=$this->key?>" class="jstree jstree-default" style="overflow:auto;"></div>
<script>
$("#<?=$this->key?>").jstree({
"themes" : {
@ -14,7 +10,11 @@ $("#<?=$this->key?>").jstree({
"plugins" : ["themes", "json_data", "checkbox", "ui"],
"json_data" : {
"data" : <?=$this->naf?>,
"ajax" : {
"url" : '<?=$this->url(array('controller'=>'arborescence', 'action'=>'nafajax'))?>',
"data" : function(n) { return { parent: n.attr ? n.attr("id") : '' , niveau : n.attr ? n.attr("niveau") : 1 }; },
"cache" : true,
}
}
});
</script>

View File

@ -119,8 +119,8 @@ $(document).ready(function(){
var dialogOpts = {
bgiframe: true,
title: title,
width: 800,
height: 600,
width: 900,
height: 500,
modal: true,
open: function(event, ui) {
$(this).html('Chargement...');