autocomplete
This commit is contained in:
parent
5196da2329
commit
cf528a531a
@ -26,10 +26,16 @@ class EconomiqueController extends Zend_Controller_Action
|
||||
$this->_helper->layout()->disableLayout();
|
||||
$this->_helper->viewRenderer->setNoRender();
|
||||
$request = $this->getRequest();
|
||||
|
||||
$q = strtolower($request->getParam('q'));
|
||||
|
||||
$separator = ' , ';
|
||||
|
||||
$table = new Application_Model_Naf();
|
||||
|
||||
$sql = $table->select()
|
||||
->where('lib LIKE "%'.$this->getRequest()->getParam('q').'%"');
|
||||
->where('LOWER(lib) LIKE "%'.$q.'%"')
|
||||
->where('niveau = 5');
|
||||
$result = $table->fetchAll($sql);
|
||||
foreach ($result as $item) {
|
||||
$output[] = array(
|
||||
|
@ -46,6 +46,8 @@ class GeographiqueController extends Zend_Controller_Action
|
||||
|
||||
protected function completedDep($q)
|
||||
{
|
||||
$separator = ' , ';
|
||||
|
||||
$table = new Application_Model_Departements();
|
||||
$sql = $table->select()
|
||||
->where('libdep LIKE "'.$q.'%"');
|
||||
@ -61,6 +63,8 @@ class GeographiqueController extends Zend_Controller_Action
|
||||
|
||||
protected function completedVil($q)
|
||||
{
|
||||
$separator = ' , ';
|
||||
|
||||
$table = new Application_Model_CodePostaux();
|
||||
$separator = ' ';
|
||||
|
||||
@ -77,6 +81,8 @@ class GeographiqueController extends Zend_Controller_Action
|
||||
|
||||
protected function getDeptFromReg($dep)
|
||||
{
|
||||
$separator = ' , ';
|
||||
|
||||
$table = new Application_Model_Departements();
|
||||
$sql = $table->select()
|
||||
->where('codeRegionInsee = '.$dep);
|
||||
@ -91,6 +97,8 @@ class GeographiqueController extends Zend_Controller_Action
|
||||
|
||||
protected function completedReg($q)
|
||||
{
|
||||
$separator = ' , ';
|
||||
|
||||
$table = new Application_Model_Regions();
|
||||
$separator = ' ';
|
||||
|
||||
|
@ -28,8 +28,13 @@ class JuridiqueController extends Zend_Controller_Action
|
||||
$this->_helper->viewRenderer->setNoRender();
|
||||
$request = $this->getRequest();
|
||||
|
||||
$q = strtolower($request->getParam('q'));
|
||||
|
||||
$separator = ' , ';
|
||||
|
||||
$sql = $table->select()
|
||||
->where('fjLibelle LIKE "'.$request->getParam('q').'%"');
|
||||
->where('LOWER(fjLibelle) LIKE "%'.$q.'%"')
|
||||
->where('LENGTH(fjCode) = 4');
|
||||
$result = $table->fetchAll($sql);
|
||||
foreach ($result as $item) {
|
||||
$output[] = array(
|
||||
|
@ -111,7 +111,8 @@ class Zend_View_Helper_Field extends Zend_View_Helper_Abstract
|
||||
case 'textarea':
|
||||
$html.= $this->structureHTML(
|
||||
$field['label'],
|
||||
$this->textareaHTML($name, $field));
|
||||
$this->textareaHTML($name, $field)
|
||||
);
|
||||
break;
|
||||
case 'radio':
|
||||
$html.= $this->structureHTML(
|
||||
@ -324,9 +325,9 @@ class Zend_View_Helper_Field extends Zend_View_Helper_Abstract
|
||||
$type= $name;
|
||||
break;
|
||||
}
|
||||
$return = '<input type="text" class="criteres complited'.$type.'" id="textarea_'.$name.'" name="'.$name.'" />';
|
||||
$return .= '<a href="" class="autocomplet" textarea="'.$name.'">Sélectionner</a>';
|
||||
$return .= ' <a href="" textarea="'.$name.'">Exclure</a>';
|
||||
$return = '<input type="text" class="criteres autocomplete" name="'.$name.'" />';
|
||||
$return .= '<a href="#" class="autocomplete">Sélectionner</a>';
|
||||
$return .= ' <a href="#" class="autocompleteEx">Exclure</a>';
|
||||
return $return;
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
<div id="<?=$this->key?>_dialog" class="jstree jstree-default" style="overflow:auto;"></div>
|
||||
<script>
|
||||
$("#<?=$this->key?>_dialog").jstree({
|
||||
$("div#<?=$this->key?>").jstree({
|
||||
"themes" : {
|
||||
"theme" : "default",
|
||||
"url" : "/themes/jstree/classic/style.css",
|
||||
|
@ -1,6 +1,6 @@
|
||||
<div id="<?=$this->key?>_dialog" class="jstree jstree-default" style="overflow:auto;"></div>
|
||||
<div id="<?=$this->key?>" class="jstree jstree-default" style="overflow:auto;"></div>
|
||||
<script>
|
||||
$("#<?=$this->key?>_dialog").jstree({
|
||||
$("div#<?=$this->key?>").jstree({
|
||||
"themes" : {
|
||||
"theme" : "default",
|
||||
"url" : "/themes/jstree/classic/style.css",
|
||||
|
@ -1,6 +1,6 @@
|
||||
<div id="<?=$this->key?>_dialog" class="jstree jstree-default" style="overflow:auto;"></div>
|
||||
<div id="<?=$this->key?>" class="jstree jstree-default" style="overflow:auto;"></div>
|
||||
<script>
|
||||
$("#<?=$this->key?>_dialog").jstree({
|
||||
$("div#<?=$this->key?>").jstree({
|
||||
"themes" : {
|
||||
"theme" : "default",
|
||||
"url" : "/themes/jstree/classic/style.css",
|
||||
|
@ -3,6 +3,7 @@
|
||||
<ul id="fieldsblock">
|
||||
<li><?=$this->Field('capital')?></li>
|
||||
<li><?=$this->Field('ape_etab')?></li>
|
||||
<li><?=$this->Field('ape_entrep')?></li>
|
||||
<li><?=$this->Field('age_etab')?></li>
|
||||
<li><?=$this->Field('teff_etab')?></li>
|
||||
<li><?=$this->Field('eff_etab')?></li>
|
||||
|
@ -79,17 +79,10 @@ class Ciblage
|
||||
|
||||
protected function setAlpha($name, $valeur)
|
||||
{
|
||||
if ( $this->alpha!='' ) $this->alpha.= ' ';
|
||||
if ( $this->alpha!='' ) $this->alpha.= ' & ';
|
||||
$this->alpha.= '@'.$name.' '.$valeur;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public function extract()
|
||||
{
|
||||
$resultats = $this->execute(true);
|
||||
@ -538,4 +531,49 @@ class Ciblage
|
||||
}
|
||||
}
|
||||
|
||||
protected function ape_etab($value)
|
||||
{
|
||||
$req = '';
|
||||
if ( array_key_exists('in', $value) && is_array($value['in']) && count($value['in'])>0 ) {
|
||||
$req.= '('.implode('|', $value['in']).')';
|
||||
}
|
||||
if ( array_key_exists('ex', $value) && is_array($value['ex']) && count($value['ex'])>0 ) {
|
||||
if (empty($req)) {
|
||||
//Get all NAFs and remove excluded
|
||||
$nafM = new Application_Model_Naf();
|
||||
$sql = $nafM->select()->columns('code')->where('niveau = 5');
|
||||
$allnaf = $nafM->fetchAll()->toArray();
|
||||
$value = array_diff($allnaf, $value['ex']);
|
||||
$req.= '('.implode('|', $value).')';
|
||||
} else {
|
||||
//Simply exclude
|
||||
$req.= ' -('.implode('|', $value['ex']).')';
|
||||
}
|
||||
}
|
||||
$this->setAlpha('ape_etab', $req);
|
||||
}
|
||||
|
||||
|
||||
protected function ape_entrep($value)
|
||||
{
|
||||
$req = '';
|
||||
if ( array_key_exists('in', $value) && is_array($value['in']) && count($value['in'])>0 ) {
|
||||
$req.= '('.implode('|', $value['in']).')';
|
||||
}
|
||||
if ( array_key_exists('ex', $value) && is_array($value['ex']) && count($value['ex'])>0 ) {
|
||||
if (empty($req)) {
|
||||
//Get all NAFs and remove excluded
|
||||
$nafM = new Application_Model_Naf();
|
||||
$sql = $nafM->select()->columns('code')->where('niveau = 5');
|
||||
$allnaf = $nafM->fetchAll()->toArray();
|
||||
$value = array_diff($allnaf, $value['ex']);
|
||||
$req.= '('.implode('|', $value).')';
|
||||
} else {
|
||||
//Simply exclude
|
||||
$req.= ' -('.implode('|', $value['ex']).')';
|
||||
}
|
||||
}
|
||||
$this->setAlpha('ape_entrep', $req);
|
||||
}
|
||||
|
||||
}
|
@ -182,10 +182,10 @@ class Scores_Fields
|
||||
'activated' => true,
|
||||
),
|
||||
'ape_entrep' => array(
|
||||
'label' => 'Activité de l\'entreprise (Code NAF)',
|
||||
'label' => "Activité de l'entreprise (Code NAF)",
|
||||
'fields' => array(
|
||||
'text' => array('value' => null),
|
||||
'textarea' => array('value' => null)
|
||||
'tree' => array('value' => null, 'action' => 'naf', 'title' => "Arborescence de code NAF entreprise"),
|
||||
'text' => array('value' => null, 'label' => "Recherche de code NAF", 'title'=>"Selection de code NAF entreprise"),
|
||||
),
|
||||
'famille' => 'economique',
|
||||
'activated' => true,
|
||||
@ -708,6 +708,17 @@ class Scores_Fields
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if ( !is_array($value) ) {
|
||||
//Remove all space in string value
|
||||
$value = str_replace(' ', '', $value);
|
||||
//Try to detect separator et transform as array
|
||||
if ( preg_match_all('/([0-9A-Z]*)(,|;)/i', $value, $matches) ){
|
||||
$value = $matches[1];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//Before to save the value
|
||||
$types = array_keys($this->fields[$key]['fields']);
|
||||
switch ( $types[0] ) {
|
||||
@ -725,6 +736,11 @@ class Scores_Fields
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//Save the value
|
||||
if ($ex) {
|
||||
$this->ciblage[$key]['ex'] = $value;
|
||||
|
@ -45,11 +45,63 @@ $(document).ready(function()
|
||||
set($(this).attr('name'), $(this).val());
|
||||
});
|
||||
|
||||
$('#tabs').delegate('input[type=text].criteres', 'blur', function(e){
|
||||
e.stopPropagation();
|
||||
set($(this).attr('name'), $(this).val());
|
||||
$('input[type=text].autocomplete')
|
||||
.bind( "keydown", function( event ) {
|
||||
if ( event.keyCode === $.ui.keyCode.TAB &&
|
||||
$( this ).data( "autocomplete" ).menu.active ) {
|
||||
event.preventDefault();
|
||||
}
|
||||
})
|
||||
.autocomplete({
|
||||
minLength:4,
|
||||
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;
|
||||
}
|
||||
if (href) {
|
||||
$.getJSON( href, { q: val }, function(data) {
|
||||
response(data);
|
||||
} );
|
||||
}
|
||||
}
|
||||
},
|
||||
focus: function() {
|
||||
// prevent value inserted on focus
|
||||
return false;
|
||||
},
|
||||
select: function( event, ui ) {
|
||||
var terms = split( this.value );
|
||||
// remove the current input
|
||||
terms.pop();
|
||||
// add the selected item
|
||||
terms.push( ui.item.value );
|
||||
// add placeholder to get the comma-and-space at the end
|
||||
terms.push( "" );
|
||||
this.value = terms.join( ", " );
|
||||
return false;
|
||||
},
|
||||
});
|
||||
|
||||
$('#tabs').delegate('a.autocomplete', 'click', function(e){
|
||||
e.stopPropagation();
|
||||
var obj = $(this).parent().find('input.criteres');
|
||||
set(obj.attr('name'), obj.val());
|
||||
});
|
||||
|
||||
$('#tabs').delegate('a.autocompleteEx', 'click', function(e){
|
||||
e.stopPropagation();
|
||||
var obj = $(this).parent().find('input.criteres');
|
||||
set(obj.attr('name'), obj.val());
|
||||
});
|
||||
|
||||
$('#tabs').delegate('a.selectMultiple', 'click', function(e){
|
||||
e.stopPropagation();
|
||||
@ -63,13 +115,6 @@ $(document).ready(function()
|
||||
set(obj.attr('name'), obj.val(), 1);
|
||||
});
|
||||
|
||||
$('#tabs').delegate('a.autocomplet', 'click', function(e){
|
||||
e.preventDefault();
|
||||
var key = $(this).attr('textarea');
|
||||
var values = $('#textarea_'+$(this).attr('textarea')).val();
|
||||
set(key, values);
|
||||
return false;
|
||||
});
|
||||
|
||||
$('#tabs').delegate('a.interval', 'click', function(e){
|
||||
e.preventDefault();
|
||||
@ -122,7 +167,7 @@ $(document).ready(function()
|
||||
Valider: function() {
|
||||
var key = $('div.jstree').attr('id');
|
||||
var elements = [];
|
||||
$('#'+key).jstree("get_checked").each(function(){
|
||||
$('div.jstree').jstree("get_checked").each(function(){
|
||||
elements.push(this.id);
|
||||
});
|
||||
set(key, elements.join(","));
|
||||
|
@ -371,3 +371,5 @@ ul#fieldsblock li div.fieldgrp div.field .interval input[type=text] {
|
||||
cursor:pointer;
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
.ui-autocomplete-loading { background: white url('/themes/jqueryui/smoothness/ui-anim_basic_16x16.gif') right center no-repeat; }
|
Loading…
Reference in New Issue
Block a user