issue #0001218 : Redesign completely autocomplete fields

This commit is contained in:
Michael RICOIS 2012-07-30 07:50:37 +00:00
parent a1ba1ac947
commit e59403cf84
12 changed files with 381 additions and 171 deletions

View File

@ -1,22 +0,0 @@
<?php
class EntrepriseController extends Zend_Controller_Action
{
public function init()
{
/* Initialize action controller here */
}
public function indexAction()
{
$field = new Scores_Fields();
$this->view->fields = $field;
}
public function resetAction()
{
$this->_helper->layout()->disableLayout();
$this->_helper->viewRenderer->setNoRender();
$fields = new Scores_Fields();
$fields->resetFamille('entreprise');
}
}

View File

@ -0,0 +1,207 @@
<?php
class FieldsController extends Zend_Controller_Action
{
/**
* Display fields
*/
public function indexAction()
{
$this->view->headScript()
->appendFile('/themes/default/scripts/jquery.jstree.js', 'text/javascript')
->appendFile('/themes/default/scripts/fields.js', 'text/javascript');
$field = new Scores_Fields();
$this->view->fields = $field;
}
/**
* Reset criteres by family
*/
public function resetAction()
{
$this->_helper->layout()->disableLayout();
$this->_helper->viewRenderer->setNoRender();
$request = $this->getRequest();
$family = $request->getParam('family');
if (!empty($family) )
{
$fields = new Scores_Fields();
$fields->resetFamille($family);
}
}
/**
* Manage autocomplete
*/
public function autocompleteAction()
{
$this->_helper->layout()->disableLayout();
$request = $this->getRequest();
$name = $request->getParam('name');
$q = strtolower($request->getParam('q'));
$output = array();
switch ($name) {
case 'ape_etab':
case 'ape_entrep':
$separator = ' , ';
$table = new Application_Model_Naf();
$sql = $table->select();
$sql->where('LOWER(lib) LIKE "%'.$q.'%"');
$sql->where('niveau = 5');
$result = $table->fetchAll($sql);
foreach ($result as $item) {
$output[] = array(
'label' => $item->lib . $separator . $item->code,
'value' => $item->code
);
}
break;
case 'geo':
//Replace characters ' and - in space
$q = preg_replace("/['-]/", ' ', $q);
//Remove characters
$q = preg_replace("/^[a-z0-9]\s/i", '', $q);
//Detect if we have string
if ( preg_match("/[a-zA-Z]+/", $q) )
{
$queries = explode(' ', $q);
Zend_Registry::get('firebug')->info($queries);
//Région
$table = new Application_Model_Regions();
$sql = $table->select();
if (count($queries)>0) {
$where = '';
$i = 0;
foreach ($queries as $item) {
if (strlen($item)>2) {
$where = 'LIKE "%'.strtolower($item).'%"';
}
$i++;
if (count($queries) < $i){
$where.= ' OR ';
}
}
$sql->where("LOWER(NC) ".$where);
}
$result = $table->fetchAll($sql);
foreach ($result as $item) {
$output[] = array(
'label' => $item->NCCENR . ' (Région)',
'value' => 'R'.$item->REGION
);
}
//Département
$table = new Application_Model_Departements();
$sql = $table->select();
if (count($queries)>0) {
$where = '';
$i = 0;
foreach ($queries as $item) {
if (strlen($item)>2) {
$where = 'LIKE "%'.strtolower($item).'%"';
}
$i++;
if (count($queries) < $i){
$where.= ' OR ';
}
}
$sql->where("LOWER(libdep) ".$where);
}
$result = $table->fetchAll($sql);
foreach ($result as $item) {
$output[] = array(
'label' => $item->libdep . ' (Dépatement)',
'value' => 'D'.$item->numdep
);
}
//Ville
$table = new Application_Model_CodePostaux();
$sql = $table->select();
if (count($queries)>0) {
$where = '';
$i = 0;
foreach ($queries as $item) {
if (strlen($item)>2) {
$where = 'LIKE "'.strtolower($item).'"';
}
$i++;
if (count($queries) < $i){
$where.= ' OR ';
}
}
$sql->where("LOWER(Commune) ".$where);
}
$result = $table->fetchAll($sql);
foreach ($result as $item) {
$output[] = array(
'label' => $item->Commune . ', '. $item->Codepos .' (Ville)',
'value' => 'C'.$item->INSEE
);
}
} elseif ( preg_match('/[0-9]{1,5}/', $q) ) {
//Code Postal
$table = new Application_Model_CodePostaux();
$sql = $table->select()->where('Codepos LIKE "'.$q.'%"');
$result = $table->fetchAll($sql);
foreach ($result as $item) {
$output[] = array(
'label' => $item->Codepos . ' ( Code postal )',
'value' => $item->Codepos
);
}
}
break;
case 'cj':
$table = new Application_Model_FormeJuridique();
$separator = ' , ';
$sql = $table->select();
$queries = explode(' ', $q);
if (count($queries)>0) {
$where = '';
$i = 0;
foreach ($queries as $item) {
if (strlen($item)>3) {
$where = 'LIKE "%'.$item.'%"';
}
$i++;
if (count($queries) < $i){
$where.= ' OR ';
}
}
$sql->where('LOWER(fjLibelle) '.$where);
}
$sql->where('LENGTH(fjCode) = 4');
$result = $table->fetchAll($sql);
foreach ($result as $item) {
$output[] = array(
'label' => $item->fjLibelle . $separator . $item->fjCode,
'value' => $item->fjCode
);
}
break;
}
//No results
if (count($output) == 0) {
$output[] = array('label' => 'Aucun résultat.', 'value' => '');
}
$this->view->assign('output', $output);
}
public function checkvalue(){}
}

View File

@ -1,26 +0,0 @@
<?php
class FinancierController extends Zend_Controller_Action
{
public function init()
{
/* Initialize action controller here */
}
public function indexAction()
{
$auth = Zend_Auth::getInstance();
$user = $auth->getIdentity();
$field = new Scores_Fields();
$this->view->fields = $field;
}
public function resetAction()
{
$this->_helper->layout()->disableLayout();
$this->_helper->viewRenderer->setNoRender();
$fields = new Scores_Fields();
$fields->resetFamille('financier');
}
}

View File

@ -1,14 +1,6 @@
<?php
class IndexController extends Zend_Controller_Action
{
public function init()
{
$this->view->headScript()
->appendFile('/themes/default/scripts/jquery.jstree.js', 'text/javascript')
->appendFile('/themes/default/scripts/fields.js', 'text/javascript');
}
public function indexAction()
{
$auth = Zend_Auth::getInstance();

View File

@ -403,8 +403,9 @@ class Zend_View_Helper_Field extends Zend_View_Helper_Abstract
break;
}
$return = '<input type="text" class="criteres autocomplete" name="'.$name.'" />';
$return .= '<a href="#" class="autocomplete">Sélectionner</a>';
$return .= '&nbsp;<a href="#" class="autocompleteEx">Exclure</a>';
$return.= '<ul id="selectqueries"></ul>';
$return.= '<a href="#" class="autocomplete">Sélectionner</a>';
$return.= '&nbsp;<a href="#" class="autocompleteEx">Exclure</a>';
return $return;
}

View File

@ -1,24 +0,0 @@
<div id="entreprise">
<ul id="fieldsblock">
<li><?=$this->Field('siege')?></li>
<li><?=$this->Field('groupe')?></li>
<li><?=$this->Field('tel')?></li>
<li><?=$this->Field('fax')?></li>
<li><?=$this->Field('web')?></li>
<li><?=$this->Field('mail')?></li>
<li><?=$this->Field('presentRcs')?></li>
<li><?=$this->Field('adrDom')?></li>
<li><?=$this->Field('dirNom')?></li>
<li><?=$this->Field('dateCrea_etab')?></li>
<li><?=$this->Field('participation')?></li>
<li class="advanced"><?=$this->Field('nbMPubli')?></li>
<li class="advanced"><?=$this->Field('dateCrea_ent')?></li>
<li class="advanced"><?=$this->Field('action')?></li>
<li class="advanced"><?=$this->Field('nbActio')?></li>
<li class="advanced"><?=$this->Field('nbPart')?></li>
<li class="mode"><img src="/themes/default/images/fleche-bas.gif" /></li>
</ul>
</div>
<div id="link">
<a class="resetFamille" id="entreprise">Réinitialiser les critères entreprises</a>
</div>

View File

@ -0,0 +1 @@
<?=json_encode($this->output)?>

View File

@ -0,0 +1,118 @@
<ul>
<li><a href="#tabs-1">Critères Entreprise</a></li>
<li><a href="#tabs-2">Situation économique</a></li>
<li><a href="#tabs-3">Secteur géographique</a></li>
<li><a href="#tabs-4">Situation juridique</a></li>
<li><a href="#tabs-5">Situation financière</a></li>
</ul>
<div id="tabs-1">
<div id="entreprise">
<ul id="fieldsblock">
<li><?=$this->Field('siege')?></li>
<li><?=$this->Field('groupe')?></li>
<li><?=$this->Field('tel')?></li>
<li><?=$this->Field('fax')?></li>
<li><?=$this->Field('web')?></li>
<li><?=$this->Field('mail')?></li>
<li><?=$this->Field('presentRcs')?></li>
<li><?=$this->Field('adrDom')?></li>
<li><?=$this->Field('dirNom')?></li>
<li><?=$this->Field('dateCrea_etab')?></li>
<li><?=$this->Field('participation')?></li>
<li class="advanced"><?=$this->Field('nbMPubli')?></li>
<li class="advanced"><?=$this->Field('dateCrea_ent')?></li>
<li class="advanced"><?=$this->Field('action')?></li>
<li class="advanced"><?=$this->Field('nbActio')?></li>
<li class="advanced"><?=$this->Field('nbPart')?></li>
<li class="mode"><img src="/themes/default/images/fleche-bas.gif" /></li>
</ul>
</div>
<div id="link">
<a class="resetFamille" id="entreprise">Réinitialiser les critères entreprises</a>
</div>
</div>
<div id="tabs-2">
<div id="economique">
<ul id="fieldsblock">
<li><?=$this->Field('capital')?></li>
<li><?=$this->Field('ape_entrep')?></li>
<li class="advanced"><?=$this->Field('ape_etab')?></li>
<li><?=$this->Field('age_entrep')?></li>
<li class="advanced"><?=$this->Field('age_etab')?></li>
<li><?=$this->Field('teff_entrep')?></li>
<li class="advanced"><?=$this->Field('teff_etab')?></li>
<li><?=$this->Field('eff_entrep')?></li>
<li class="advanced"><?=$this->Field('eff_etab')?></li>
<li class="advanced"><?=$this->Field('nbEtab')?></li>
<li class="mode"><img src="/themes/default/images/fleche-bas.gif" /></li>
</ul>
</div>
<div style="text-align:right;margin-top:20px;">
<a class="resetFamille" id="economique">Réinitialiser les critères economiques</a>
</div>
</div>
<div id="tabs-3">
<div id="geographique">
<ul id="fieldsblock">
<li>
<?=$this->Field('geo')?>
<?=$this->Field('geo_domtom')?>
<?=$this->Field('geo_etranger')?>
<?=$this->Field('geo_corse')?>
</li>
<li><?=$this->Field('zus')?></li>
<li><?=$this->Field('zru')?></li>
<li><?=$this->Field('zfu')?></li>
<li><?=$this->Field('cucs')?></li>
<li><?=$this->Field('zrr')?></li>
<li><?=$this->Field('zafr')?></li>
</ul>
</div>
<div style="text-align:right;margin-top:20px;">
<a class="resetFamille" id="econmique">Réinitialiser les critères geographiques</a>
</div>
</div>
<div id="tabs-4">
<div id="juridique">
<ul id="fieldsblock">
<li><?=$this->Field('cj')?></li>
<li><?=$this->Field('actifEco')?></li>
<li><?=$this->Field('procolHisto')?></li>
<li><?=$this->Field('dateImmat')?></li>
<li class="advanced"><?=$this->Field('tvaIntraValide')?></li>
<li class="mode"><img src="/themes/default/images/fleche-bas.gif" /></li>
</ul>
</div>
<div style="text-align:right;margin-top:20px;">
<a class="resetFamille" id="econmique">Réinitialiser les critères juridique</a>
</div>
</div>
<div id="tabs-5">
<div id="financiere">
<ul id="fieldsblock">
<li><?=$this->Field('bilType')?></li>
<li><?=$this->Field('avisCs')?></li>
<li><?=$this->Field('bilAnnee')?></li>
<li><?=$this->Field('bilCloture')?></li>
<li><?=$this->Field('bilDuree')?></li>
<li><?=$this->Field('bilTca')?></li>
<li><?=$this->Field('bilFL')?></li>
<li class="advanced"><?=$this->Field('bilEE')?></li>
<li class="advanced"><?=$this->Field('bilFK')?></li>
<li class="advanced"><?=$this->Field('bilFR')?></li>
<li class="advanced"><?=$this->Field('bilGF')?></li>
<li class="advanced"><?=$this->Field('bilGP')?></li>
<li class="advanced"><?=$this->Field('bilGW')?></li>
<li class="advanced"><?=$this->Field('bilHD')?></li>
<li class="advanced"><?=$this->Field('bilHH')?></li>
<li class="advanced"><?=$this->Field('bilHL')?></li>
<li class="advanced"><?=$this->Field('bilHM')?></li>
<li class="advanced"><?=$this->Field('bilHN')?></li>
<li class="advanced"><?=$this->Field('bilYP')?></li>
<li class="mode"><img src="/themes/default/images/fleche-bas.gif" /></li>
</ul>
</div>
<div style="text-align:right;margin-top:20px;">
<a class="resetFamille" id="financier">Réinitialiser les critères financiers</a>
</div>
</div>

View File

@ -1,27 +0,0 @@
<div id="financiere">
<ul id="fieldsblock">
<li><?=$this->Field('bilType')?></li>
<li><?=$this->Field('avisCs')?></li>
<li><?=$this->Field('bilAnnee')?></li>
<li><?=$this->Field('bilCloture')?></li>
<li><?=$this->Field('bilDuree')?></li>
<li><?=$this->Field('bilTca')?></li>
<li><?=$this->Field('bilFL')?></li>
<li class="advanced"><?=$this->Field('bilEE')?></li>
<li class="advanced"><?=$this->Field('bilFK')?></li>
<li class="advanced"><?=$this->Field('bilFR')?></li>
<li class="advanced"><?=$this->Field('bilGF')?></li>
<li class="advanced"><?=$this->Field('bilGP')?></li>
<li class="advanced"><?=$this->Field('bilGW')?></li>
<li class="advanced"><?=$this->Field('bilHD')?></li>
<li class="advanced"><?=$this->Field('bilHH')?></li>
<li class="advanced"><?=$this->Field('bilHL')?></li>
<li class="advanced"><?=$this->Field('bilHM')?></li>
<li class="advanced"><?=$this->Field('bilHN')?></li>
<li class="advanced"><?=$this->Field('bilYP')?></li>
<li class="mode"><img src="/themes/default/images/fleche-bas.gif" /></li>
</ul>
</div>
<div style="text-align:right;margin-top:20px;">
<a class="resetFamille" id="financier">Réinitialiser les critères financiers</a>
</div>

View File

@ -7,18 +7,5 @@ Erreur ! Le moteur de ciblage n'est pas disponible !
<?php } else {?>
<div id="actionMessage"></div>
<div id="panel"><?=$this->action('criteres', 'index')?></div>
<div id="tabs">
<ul>
<li><a href="#tabs-1">Critères Entreprise</a></li>
<li><a href="#tabs-2">Situation économique</a></li>
<li><a href="#tabs-3">Secteur géographique</a></li>
<li><a href="#tabs-4">Situation juridique</a></li>
<li><a href="#tabs-5">Situation financière</a></li>
</ul>
<div id="tabs-1"><?=$this->action('index', 'entreprise')?></div>
<div id="tabs-2"><?=$this->action('index', 'economique')?></div>
<div id="tabs-3"><?=$this->action('index', 'geographique')?></div>
<div id="tabs-4"><?=$this->action('index', 'juridique')?></div>
<div id="tabs-5"><?=$this->action('index', 'financier')?></div>
</div>
<div id="tabs"><?=$this->action('index', 'fields')?></div>
<?php }?>

View File

@ -747,8 +747,8 @@ Les zones urbaines sensibles constituent un sous-ensemble de l'ensemble plus lar
* Enregistre un critère et sa valeur en effectuant les controls nécesaire
* @param string $key
* Critere key
* @param mixed $value
* Value(s)
* @param string $value
* Single value or list of values in string separate by a comma
* @param boolean $ex
* true for an exclude value
* @return boolean
@ -767,6 +767,18 @@ Les zones urbaines sensibles constituent un sous-ensemble de l'ensemble plus lar
unset($this->ciblage[$key]);
return true;
}
/**
* single
* multiple
*
*
* date
* min,max
*
*/
//Do some operation on value
$types = array_keys($this->fields[$key]['fields']);
@ -790,7 +802,7 @@ Les zones urbaines sensibles constituent un sous-ensemble de l'ensemble plus lar
}
}
if ($types[0]=='interval') {
if ( in_array($types[0], array('interval')) ) {
$value = explode(',', $value);
}
@ -830,6 +842,10 @@ Les zones urbaines sensibles constituent un sous-ensemble de l'ensemble plus lar
return true;
}
/**
* Définir les critères en une fois
* @param array $criteres Criteres as array with key => val

View File

@ -74,58 +74,50 @@ $(document).ready(function()
}
})
.autocomplete({
minLength:4,
minLength:3,
source: function(request, response) {
var val = extractLast( request.term );
var regex = /[a-z]/i;
if ( regex.test(val[0]) ){
switch ( this.element.attr('name') ) {
case 'ape_etab':
case 'ape_entrep':
var href = '/economique/completed';
break;
case 'cj':
var href = '/juridique/completed';
break;
case 'geo':
var href = '/geographique/completed';
break;
}
if (href) {
$.getJSON( href, { q: val }, function(data) {
response(data);
} );
}
}
$.getJSON( '/fields/autocomplete', { q: val, name: this.element.attr('name') }, function(data) {
response(data);
});
},
focus: function() {
// prevent value inserted on focus
return false;
},
select: function( event, ui ) {
if ( this.name == 'geo') {
this.value = ui.item.value;
} else {
var terms = split( this.value );
terms.pop();
terms.push( ui.item.value );
terms.push( "" );
this.value = terms.join( ", " );
}
focus: function() { return false; },
select: function( event, ui ) {
if (ui.item.value != '') {
var oldhtml = $('ul#selectqueries').html();
var newhtml = '<li name="' + ui.item.value + '">' + ui.item.label + '</li>';
$('ul#selectqueries').html(oldhtml + newhtml);
}
this.value = '';
return false;
},
close: function ( event, ui) { this.value = ''; },
});
$('#tabs').delegate('a.autocomplete', 'click', function(e){
e.stopPropagation();
var obj = $(this).parent().find('input.criteres');
set(obj.attr('name'), obj.val());
var name = $(this).parent().find('input.criteres').attr('name');
var ul = $(this).parent().find('ul#selectqueries');
var values = new Array();
if ($('li', ul).length>0) {
$('li', ul).each(function(){
values.push($(this).attr('name'));
});
set(name, values.join(','));
}
});
$('#tabs').delegate('a.autocompleteEx', 'click', function(e){
e.stopPropagation();
var obj = $(this).parent().find('input.criteres');
set(obj.attr('name'), obj.val(), 1);
var name = $(this).parent().find('input.criteres');
var ul = $(this).parent().find('ul#selectqueries');
var values = new Array();
if ($('li', ul).length>0) {
$('li', ul).each(function(){
values.push($(this).attr('name'));
});
set(name, values.join(','), 1);
}
});
$('#tabs').delegate('a.selectMultiple', 'click', function(e){
@ -163,7 +155,6 @@ $(document).ready(function()
set(key, values);
return false;
});
//@todo : We have two event bind on each element why ?
$('.intervalSelect').change(function(){
@ -183,7 +174,6 @@ $(document).ready(function()
set(key, values);
return false;
});
$('#tabs').delegate('a.arborescence', 'click', function(e) {
e.preventDefault();
@ -267,11 +257,8 @@ function set(key, value, ex)
//
$('#attente').css('display', 'none');
//Resume criteres content
$.get('/index/criteres/ajax/1', function(data){
$('#panel').html(data);
});
$.get('/index/criteres/ajax/1', function(data) { $('#panel').html(data); });
}, 'json').error(function(){ alert('Erreur inconnue'); });
}