Fix: Use a better way to bold search criteria (no use of javascript regex, but use php regex). Usage of * was making javascript crazy.

Fix: When field is manually cleaned, we must also clean hidden fields.
New: Can define number of char before showing first answer
This commit is contained in:
Laurent Destailleur 2010-10-11 21:32:53 +00:00
parent 60e9afdec9
commit 921aac798e
6 changed files with 52 additions and 26 deletions

View File

@ -63,9 +63,9 @@ if ($_GET["action"] == 'setcodecompta')
} }
} }
if ($_POST["action"] == 'usesearchtoselectcompany') if ($_POST["action"] == 'COMPANY_USE_SEARCH_TO_SELECT')
{ {
if (dolibarr_set_const($db, "COMPANY_USE_SEARCH_TO_SELECT", $_POST["activate_usesearchtoselectcompany"],'chaine',0,'',$conf->entity)) if (dolibarr_set_const($db, "COMPANY_USE_SEARCH_TO_SELECT", $_POST["activate_COMPANY_USE_SEARCH_TO_SELECT"],'chaine',0,'',$conf->entity))
{ {
Header("Location: ".$_SERVER["PHP_SELF"]); Header("Location: ".$_SERVER["PHP_SELF"]);
exit; exit;
@ -452,7 +452,7 @@ print '<td width="80">&nbsp;</td></tr>'."\n";
$var=!$var; $var=!$var;
print '<form method="POST" action="'.$_SERVER['PHP_SELF'].'">'; print '<form method="POST" action="'.$_SERVER['PHP_SELF'].'">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">'; print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="action" value="usesearchtoselectcompany">'; print '<input type="hidden" name="action" value="COMPANY_USE_SEARCH_TO_SELECT">';
print "<tr ".$bc[$var].">"; print "<tr ".$bc[$var].">";
print '<td width="80%">'.$langs->trans("UseSearchToSelectCompany").'</td>'; print '<td width="80%">'.$langs->trans("UseSearchToSelectCompany").'</td>';
if (! $conf->use_javascript_ajax) if (! $conf->use_javascript_ajax)
@ -464,7 +464,7 @@ if (! $conf->use_javascript_ajax)
else else
{ {
print '<td width="60" align="right">'; print '<td width="60" align="right">';
print $html->selectyesno("activate_usesearchtoselectcompany",$conf->global->COMPANY_USE_SEARCH_TO_SELECT,1); print $html->selectyesno("activate_COMPANY_USE_SEARCH_TO_SELECT",$conf->global->COMPANY_USE_SEARCH_TO_SELECT,1);
print '</td><td align="right">'; print '</td><td align="right">';
print '<input type="submit" class="button" value="'.$langs->trans("Modify").'">'; print '<input type="submit" class="button" value="'.$langs->trans("Modify").'">';
print "</td>"; print "</td>";

View File

@ -922,7 +922,7 @@ class Form
} }
if (strval($filtertype) != '') $sql.=" AND p.fk_product_type=".$filtertype; if (strval($filtertype) != '') $sql.=" AND p.fk_product_type=".$filtertype;
// Add criteria on ref/label // Add criteria on ref/label
if (! empty($conf->global->PRODUCT_DONOTSEARCH_ANYWHERE)) if (! empty($conf->global->PRODUCT_DONOTSEARCH_ANYWHERE)) // Can use index
{ {
if ($filterkey && $filterkey != '') if ($filterkey && $filterkey != '')
{ {

View File

@ -45,7 +45,7 @@ ErrorDecimalLargerThanAreForbidden=Error, a precision higher than <b>%s</b> is n
DictionnarySetup=Dictionary setup DictionnarySetup=Dictionary setup
DisableJavascript=Disable JavaScript and Ajax functions DisableJavascript=Disable JavaScript and Ajax functions
ConfirmAjax=Use Ajax confirmation popups ConfirmAjax=Use Ajax confirmation popups
UseSearchToSelectCompany=Use a search form to choose a company (instead of using a list box) UseSearchToSelectCompany=Use a search form to choose a company (instead of using a list box).<br>Also if you have a large number of third parties (> 100 000), you can increase speed by setting constant SOCIETE_DONOTSEARCH_ANYWHERE to 1 in Setup->Other. Search will then be limited to start of string.
ViewFullDateActions=Show full dates actions in the third sheet ViewFullDateActions=Show full dates actions in the third sheet
NotAvailableWhenAjaxDisabled=Not available when Ajax disabled NotAvailableWhenAjaxDisabled=Not available when Ajax disabled
JavascriptDisabled=JavaScript disabled JavascriptDisabled=JavaScript disabled

View File

@ -45,7 +45,7 @@ ErrorDecimalLargerThanAreForbidden= Erreur, les précisions supérieures à <b>%
DictionnarySetup= Dictionnaires DictionnarySetup= Dictionnaires
DisableJavascript= Désactiver les fonctions Javascript et Ajax DisableJavascript= Désactiver les fonctions Javascript et Ajax
ConfirmAjax= Utiliser les popups de confirmation Ajax ConfirmAjax= Utiliser les popups de confirmation Ajax
UseSearchToSelectCompany= Utiliser un formulaire de recherche pour le choix d'un tiers (plutôt qu'une liste déroulante) UseSearchToSelectCompany= Utiliser un formulaire de recherche pour le choix d'un tiers (plutôt qu'une liste déroulante).<br>Notez que si vous avez un nombre important de produits ou services (> 100 000), vous pouvez améliorer les performances en définissant la constante SOCIETE_DONOTSEARCH_ANYWHERE à 1 dans Configuration->Divers. La recherche sera alors limitée au début de la chaine.
ViewFullDateActions= Visualiser les dates des actions en entier dans la fiche tiers ViewFullDateActions= Visualiser les dates des actions en entier dans la fiche tiers
NotAvailableWhenAjaxDisabled= Non disponible quand Ajax désactivé NotAvailableWhenAjaxDisabled= Non disponible quand Ajax désactivé
JavascriptDisabled= Javascript désactivé JavascriptDisabled= Javascript désactivé

View File

@ -82,6 +82,8 @@ function ajax_updater($htmlname,$keysearch,$url,$option='',$indicator='working')
*/ */
function ajax_autocompleter($selected='',$htmlname,$url,$option='') function ajax_autocompleter($selected='',$htmlname,$url,$option='')
{ {
global $conf;
$script=''; $script='';
$script.= '<input type="hidden" name="'.$htmlname.'" id="'.$htmlname.'" value="'.$selected.'" />'; $script.= '<input type="hidden" name="'.$htmlname.'" id="'.$htmlname.'" value="'.$selected.'" />';
@ -89,17 +91,27 @@ function ajax_autocompleter($selected='',$htmlname,$url,$option='')
$script.= '<script type="text/javascript">'; $script.= '<script type="text/javascript">';
$script.= 'jQuery(document).ready(function() { $script.= 'jQuery(document).ready(function() {
var cache = {}; var cache = {};
jQuery("input#search_'.$htmlname.'").blur(function() {
//console.log(this.value.length);
if (this.value.length == 0)
{
jQuery("#search_'.$htmlname.'").val("");
jQuery("#'.$htmlname.'").val("");
}
});
jQuery("input#search_'.$htmlname.'").autocomplete({ jQuery("input#search_'.$htmlname.'").autocomplete({
source: function( request, response ) { source: function( request, response ) {
if (this.length == 0) { jQuery(this).flushCache(); } if (this.length == 0) {
jQuery(this).flushCache();
}
if (cache.term == request.term && cache.content) { if (cache.term == request.term && cache.content) {
response(cache.content); response(cache.content);
return; return;
} }
if (new RegExp(cache.term).test(request.term) && cache.content && cache.content.length < 13) { /*if (new RegExp(cache.term).test(request.term) && cache.content && cache.content.length < 13) {
response($.ui.autocomplete.filter(cache.content, request.term)); response(jQuery.ui.autocomplete.filter(cache.content, request.term));
return; return;
} }*/
jQuery.get("'.$url.($option?'?'.$option:'').'", { '.$htmlname.': request.term }, function(data){ jQuery.get("'.$url.($option?'?'.$option:'').'", { '.$htmlname.': request.term }, function(data){
cache.term = request.term; cache.term = request.term;
cache.content = data; cache.content = data;
@ -108,13 +120,13 @@ function ajax_autocompleter($selected='',$htmlname,$url,$option='')
jQuery("#search_'.$htmlname.'").val(item.value); jQuery("#search_'.$htmlname.'").val(item.value);
jQuery("#'.$htmlname.'").val(item.key); jQuery("#'.$htmlname.'").val(item.key);
} }
var label = item.label.toString().replace(new RegExp("("+request.term+")","i"),"<strong>$1</strong>"); var label = item.label.toString();
return { label: label, value: item.value, id: item.key} return { label: label, value: item.value, id: item.key}
})); }));
}, "json"); }, "json");
}, },
dataType: "json", dataType: "json",
minLength: 2, minLength: '.$conf->global->COMPANY_USE_SEARCH_TO_SELECT.',
select: function( event, ui ) { select: function( event, ui ) {
jQuery("#'.$htmlname.'").val(ui.item.id); jQuery("#'.$htmlname.'").val(ui.item.id);
} }
@ -140,7 +152,7 @@ function ajax_autocompleter($selected='',$htmlname,$url,$option='')
function ajax_dialog($title,$message,$w=350,$h=150) function ajax_dialog($title,$message,$w=350,$h=150)
{ {
global $langs; global $langs;
$msg.= '<div id="dialog-info" title="'.dol_escape_htmltag($title).'">'; $msg.= '<div id="dialog-info" title="'.dol_escape_htmltag($title).'">';
$msg.= $message; $msg.= $message;
$msg.= '</div>'."\n"; $msg.= '</div>'."\n";
@ -159,9 +171,9 @@ function ajax_dialog($title,$message,$w=350,$h=150)
}); });
}); });
</script>'; </script>';
$msg.= "\n"; $msg.= "\n";
return $msg; return $msg;
} }

View File

@ -55,7 +55,7 @@ dol_syslog(join(',',$_GET));
if (! empty($_GET['newcompany']) || ! empty($_GET['socid']) || ! empty($_GET['id_fourn'])) if (! empty($_GET['newcompany']) || ! empty($_GET['socid']) || ! empty($_GET['id_fourn']))
{ {
$return_arr = array(); $return_arr = array();
// Define filter on text typed // Define filter on text typed
$socid = $_GET['newcompany']?$_GET['newcompany']:''; $socid = $_GET['newcompany']?$_GET['newcompany']:'';
if (! $socid) $socid = $_GET['socid']?$_GET['socid']:''; if (! $socid) $socid = $_GET['socid']?$_GET['socid']:'';
@ -66,10 +66,21 @@ if (! empty($_GET['newcompany']) || ! empty($_GET['socid']) || ! empty($_GET['id
$sql.= " WHERE s.entity = ".$conf->entity; $sql.= " WHERE s.entity = ".$conf->entity;
if ($socid) if ($socid)
{ {
$sql.=" AND (nom LIKE '%" . $socid . "%'"; $sql.=" AND (";
$sql.=" OR code_client LIKE '%" . $socid . "%'"; // Add criteria on name/code
$sql.=" OR code_fournisseur LIKE '%" . $socid . "%'"; if (! empty($conf->global->SOCIETE_DONOTSEARCH_ANYWHERE)) // Can use index
if ($conf->global->SOCIETE_ALLOW_SEARCH_ON_ROWID) $sql.=" OR rowid = '" . $socid . "'"; {
$sql.="nom LIKE '" . $db->escape($socid) . "%'";
$sql.=" OR code_client LIKE '" . $db->escape($socid) . "%'";
$sql.=" OR code_fournisseur LIKE '" . $db->escape($socid) . "%'";
}
else
{
$sql.="nom LIKE '%" . $db->escape($socid) . "%'";
$sql.=" OR code_client LIKE '%" . $db->escape($socid) . "%'";
$sql.=" OR code_fournisseur LIKE '%" . $db->escape($socid) . "%'";
}
if ($conf->global->SOCIETE_ALLOW_SEARCH_ON_ROWID) $sql.=" OR rowid = '" . $db->escape($socid) . "'";
$sql.=")"; $sql.=")";
} }
if (! empty($_GET["filter"])) $sql.= " AND ".$_GET["filter"]; // Add other filters if (! empty($_GET["filter"])) $sql.= " AND ".$_GET["filter"]; // Add other filters
@ -79,14 +90,17 @@ if (! empty($_GET['newcompany']) || ! empty($_GET['socid']) || ! empty($_GET['id
$resql=$db->query($sql); $resql=$db->query($sql);
if ($resql) if ($resql)
{ {
while ($row = $db->fetch_array($resql)) { while ($row = $db->fetch_array($resql))
$row_array['label'] = $row['nom']; {
$label=$row['nom'];
if ($socid) $label=preg_replace('/('.preg_quote($socid).')/','<strong>$1</strong>',$label,1);
$row_array['label'] = $label;
$row_array['value'] = $row['nom']; $row_array['value'] = $row['nom'];
$row_array['key'] = $row['rowid']; $row_array['key'] = $row['rowid'];
array_push($return_arr,$row_array); array_push($return_arr,$row_array);
} }
echo json_encode($return_arr); echo json_encode($return_arr);
} }
} }