Fix: remove cache and regex
This commit is contained in:
parent
1aead23242
commit
66c3bcd403
@ -860,7 +860,7 @@ class Form
|
||||
if ($conf->global->PRODUIT_USE_SEARCH_TO_SELECT)
|
||||
{
|
||||
// mode=1 means customers products
|
||||
print ajax_autocompleter('',$htmlname,DOL_URL_ROOT.'/product/ajaxproducts.php','outjson=1&price_level='.$price_level.'&type='.$filtertype.'&mode=1&status='.$status.'&finished='.$finished,'');
|
||||
print ajax_autocompleter('',$htmlname,DOL_URL_ROOT.'/product/ajaxproducts.php','outjson=1&price_level='.$price_level.'&type='.$filtertype.'&mode=1&status='.$status.'&finished='.$finished);
|
||||
print $langs->trans("RefOrLabel").' : <input type="text" size="20" name="search_'.$htmlname.'" id="search_'.$htmlname.'">';
|
||||
print '<br>';
|
||||
}
|
||||
@ -985,6 +985,7 @@ class Form
|
||||
|
||||
$label=$objp->label;
|
||||
if (! empty($objp->label_translated)) $label=$objp->label_translated;
|
||||
if ($filterkey && $filterkey != '') $label=preg_replace('/('.preg_quote($filterkey).')/i','<strong>$1</strong>',$label,1);
|
||||
|
||||
$outkey=$objp->rowid;
|
||||
$outref=$objp->ref;
|
||||
@ -1004,7 +1005,10 @@ class Form
|
||||
}
|
||||
$opt.= '>';
|
||||
$opt.= $langs->convToOutputCharset($objp->ref).' - '.$langs->convToOutputCharset(dol_trunc($label,32)).' - ';
|
||||
$outval.=$objp->ref.' - '.dol_trunc($label,32).' - ';
|
||||
|
||||
$objRef = $objp->ref;
|
||||
if ($filterkey && $filterkey != '') $objRef=preg_replace('/('.preg_quote($filterkey).')/i','<strong>$1</strong>',$objRef,1);
|
||||
$outval.=$objRef.' - '.dol_trunc($label,32).' - ';
|
||||
|
||||
$found=0;
|
||||
$currencytext=$langs->trans("Currency".$conf->monnaie);
|
||||
@ -1123,7 +1127,7 @@ class Form
|
||||
if ($conf->global->PRODUIT_USE_SEARCH_TO_SELECT)
|
||||
{
|
||||
// mode=2 means suppliers products
|
||||
print ajax_autocompleter('',$htmlname,DOL_URL_ROOT.'/product/ajaxproducts.php','outjson=1&price_level='.$price_level.'&type='.$filtertype.'&mode=2&status='.$status.'&finished='.$finished,'');
|
||||
print ajax_autocompleter('',$htmlname,DOL_URL_ROOT.'/product/ajaxproducts.php','outjson=1&price_level='.$price_level.'&type='.$filtertype.'&mode=2&status='.$status.'&finished='.$finished);
|
||||
print $langs->trans("RefOrLabel").' : <input type="text" size="16" name="search_'.$htmlname.'" id="search_'.$htmlname.'">';
|
||||
print '<br>';
|
||||
}
|
||||
@ -1223,11 +1227,18 @@ class Form
|
||||
if ($selected == $objp->idprodfournprice) $opt.= ' selected="true"';
|
||||
if ($objp->fprice == '') $opt.=' disabled="disabled"';
|
||||
$opt.= '>';
|
||||
|
||||
$objRef = $objp->ref;
|
||||
if ($filterkey && $filterkey != '') $objRef=preg_replace('/('.preg_quote($filterkey).')/i','<strong>$1</strong>',$objRef,1);
|
||||
$objRefFourn = $objp->ref_fourn;
|
||||
if ($filterkey && $filterkey != '') $objRefFourn=preg_replace('/('.preg_quote($filterkey).')/i','<strong>$1</strong>',$objRefFourn,1);
|
||||
$label = $objp->label;
|
||||
if ($filterkey && $filterkey != '') $label=preg_replace('/('.preg_quote($filterkey).')/i','<strong>$1</strong>',$label,1);
|
||||
|
||||
$opt.=$langs->convToOutputCharset($objp->ref).' ('.$langs->convToOutputCharset($objp->ref_fourn).') - ';
|
||||
$outval.=$objp->ref.' ('.$objp->ref_fourn.') - ';
|
||||
$outval.=$objRef.' ('.$objRefFourn.') - ';
|
||||
$opt.=$langs->convToOutputCharset(dol_trunc($objp->label,18)).' - ';
|
||||
$outval.=dol_trunc($objp->label,18).' - ';
|
||||
$outval.=dol_trunc($label,18).' - ';
|
||||
|
||||
if ($objp->fprice != '') // Keep != ''
|
||||
{
|
||||
|
||||
@ -606,7 +606,24 @@ class FormCompany
|
||||
}
|
||||
print "</select>\n";
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Retourne la liste deroulante des codes postaux et des villes associées
|
||||
*/
|
||||
function select_zipcode($selected='',$htmlname='zipcode')
|
||||
{
|
||||
print ajax_autocompleter('',$htmlname,DOL_URL_ROOT.'/societe/ajaxziptown.php','',0)."\n";
|
||||
print '<input id="'.$htmlname.'" type="text" name="'.$htmlname.'" size="6" value="'.$selected.'">'."\n";
|
||||
}
|
||||
|
||||
/**
|
||||
* Retourne la liste deroulante des villes et des codes postaux associés
|
||||
*/
|
||||
function select_town($selected='',$htmlname='town')
|
||||
{
|
||||
print ajax_autocompleter('',$htmlname,DOL_URL_ROOT.'/societe/ajaxziptown.php','',0)."\n";
|
||||
print '<input id="'.$htmlname.'" type="text" name="'.$htmlname.'" value="'.$selected.'">'."\n";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -90,7 +90,6 @@ function ajax_autocompleter($selected='',$htmlname,$url,$option='')
|
||||
|
||||
$script.= '<script type="text/javascript">';
|
||||
$script.= 'jQuery(document).ready(function() {
|
||||
var cache = {};
|
||||
jQuery("input#search_'.$htmlname.'").blur(function() {
|
||||
//console.log(this.value.length);
|
||||
if (this.value.length == 0)
|
||||
@ -101,33 +100,19 @@ function ajax_autocompleter($selected='',$htmlname,$url,$option='')
|
||||
});
|
||||
jQuery("input#search_'.$htmlname.'").autocomplete({
|
||||
source: function( request, response ) {
|
||||
if (this.length == 0) {
|
||||
jQuery(this).flushCache();
|
||||
}
|
||||
if (cache.term == request.term && cache.content) {
|
||||
response(cache.content);
|
||||
return;
|
||||
}
|
||||
/*if (new RegExp(cache.term).test(request.term) && cache.content && cache.content.length < 13) {
|
||||
response(jQuery.ui.autocomplete.filter(cache.content, request.term));
|
||||
return;
|
||||
}*/
|
||||
jQuery.get("'.$url.($option?'?'.$option:'').'", { '.$htmlname.': request.term }, function(data){
|
||||
cache.term = request.term;
|
||||
cache.content = data;
|
||||
response( jQuery.map( data, function( item ) {
|
||||
if (data.length == 1) {
|
||||
jQuery("#search_'.$htmlname.'").val(item.value);
|
||||
jQuery("#'.$htmlname.'").val(item.key);
|
||||
}
|
||||
var label = item.label.toString();
|
||||
//label = label.replace(new RegExp("("+request.term+")","i"),"<strong>$1</strong>");
|
||||
return { label: label, value: item.value, id: item.key}
|
||||
}));
|
||||
}, "json");
|
||||
},
|
||||
dataType: "json",
|
||||
minLength: '.$conf->global->COMPANY_USE_SEARCH_TO_SELECT.',
|
||||
minLength: 2,
|
||||
select: function( event, ui ) {
|
||||
jQuery("#'.$htmlname.'").val(ui.item.id);
|
||||
}
|
||||
|
||||
@ -93,7 +93,7 @@ if (! empty($_GET['newcompany']) || ! empty($_GET['socid']) || ! empty($_GET['id
|
||||
while ($row = $db->fetch_array($resql))
|
||||
{
|
||||
$label=$row['nom'];
|
||||
if ($socid) $label=preg_replace('/('.preg_quote($socid).')/','<strong>$1</strong>',$label,1);
|
||||
if ($socid) $label=preg_replace('/('.preg_quote($socid).')/i','<strong>$1</strong>',$label,1);
|
||||
$row_array['label'] = $label;
|
||||
$row_array['value'] = $row['nom'];
|
||||
$row_array['key'] = $row['rowid'];
|
||||
|
||||
Loading…
Reference in New Issue
Block a user