mirror of
https://github.com/Dolibarr/dolibarr.git
synced 2026-02-08 09:01:40 +01:00
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:
@@ -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"]);
|
||||
exit;
|
||||
@@ -452,7 +452,7 @@ print '<td width="80"> </td></tr>'."\n";
|
||||
$var=!$var;
|
||||
print '<form method="POST" action="'.$_SERVER['PHP_SELF'].'">';
|
||||
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 '<td width="80%">'.$langs->trans("UseSearchToSelectCompany").'</td>';
|
||||
if (! $conf->use_javascript_ajax)
|
||||
@@ -464,7 +464,7 @@ if (! $conf->use_javascript_ajax)
|
||||
else
|
||||
{
|
||||
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 '<input type="submit" class="button" value="'.$langs->trans("Modify").'">';
|
||||
print "</td>";
|
||||
|
||||
@@ -922,7 +922,7 @@ class Form
|
||||
}
|
||||
if (strval($filtertype) != '') $sql.=" AND p.fk_product_type=".$filtertype;
|
||||
// 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 != '')
|
||||
{
|
||||
|
||||
@@ -45,7 +45,7 @@ ErrorDecimalLargerThanAreForbidden=Error, a precision higher than <b>%s</b> is n
|
||||
DictionnarySetup=Dictionary setup
|
||||
DisableJavascript=Disable JavaScript and Ajax functions
|
||||
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
|
||||
NotAvailableWhenAjaxDisabled=Not available when Ajax disabled
|
||||
JavascriptDisabled=JavaScript disabled
|
||||
|
||||
@@ -45,7 +45,7 @@ ErrorDecimalLargerThanAreForbidden= Erreur, les précisions supérieures à <b>%
|
||||
DictionnarySetup= Dictionnaires
|
||||
DisableJavascript= Désactiver les fonctions Javascript et 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
|
||||
NotAvailableWhenAjaxDisabled= Non disponible quand Ajax désactivé
|
||||
JavascriptDisabled= Javascript désactivé
|
||||
|
||||
@@ -82,6 +82,8 @@ function ajax_updater($htmlname,$keysearch,$url,$option='',$indicator='working')
|
||||
*/
|
||||
function ajax_autocompleter($selected='',$htmlname,$url,$option='')
|
||||
{
|
||||
global $conf;
|
||||
|
||||
$script='';
|
||||
|
||||
$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.= 'jQuery(document).ready(function() {
|
||||
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({
|
||||
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) {
|
||||
response(cache.content);
|
||||
return;
|
||||
}
|
||||
if (new RegExp(cache.term).test(request.term) && cache.content && cache.content.length < 13) {
|
||||
response($.ui.autocomplete.filter(cache.content, request.term));
|
||||
/*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;
|
||||
@@ -108,13 +120,13 @@ function ajax_autocompleter($selected='',$htmlname,$url,$option='')
|
||||
jQuery("#search_'.$htmlname.'").val(item.value);
|
||||
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}
|
||||
}));
|
||||
}, "json");
|
||||
},
|
||||
dataType: "json",
|
||||
minLength: 2,
|
||||
dataType: "json",
|
||||
minLength: '.$conf->global->COMPANY_USE_SEARCH_TO_SELECT.',
|
||||
select: function( event, ui ) {
|
||||
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)
|
||||
{
|
||||
global $langs;
|
||||
|
||||
|
||||
$msg.= '<div id="dialog-info" title="'.dol_escape_htmltag($title).'">';
|
||||
$msg.= $message;
|
||||
$msg.= '</div>'."\n";
|
||||
@@ -159,9 +171,9 @@ function ajax_dialog($title,$message,$w=350,$h=150)
|
||||
});
|
||||
});
|
||||
</script>';
|
||||
|
||||
|
||||
$msg.= "\n";
|
||||
|
||||
|
||||
return $msg;
|
||||
}
|
||||
|
||||
|
||||
@@ -55,7 +55,7 @@ dol_syslog(join(',',$_GET));
|
||||
if (! empty($_GET['newcompany']) || ! empty($_GET['socid']) || ! empty($_GET['id_fourn']))
|
||||
{
|
||||
$return_arr = array();
|
||||
|
||||
|
||||
// Define filter on text typed
|
||||
$socid = $_GET['newcompany']?$_GET['newcompany']:'';
|
||||
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;
|
||||
if ($socid)
|
||||
{
|
||||
$sql.=" AND (nom LIKE '%" . $socid . "%'";
|
||||
$sql.=" OR code_client LIKE '%" . $socid . "%'";
|
||||
$sql.=" OR code_fournisseur LIKE '%" . $socid . "%'";
|
||||
if ($conf->global->SOCIETE_ALLOW_SEARCH_ON_ROWID) $sql.=" OR rowid = '" . $socid . "'";
|
||||
$sql.=" AND (";
|
||||
// Add criteria on name/code
|
||||
if (! empty($conf->global->SOCIETE_DONOTSEARCH_ANYWHERE)) // Can use index
|
||||
{
|
||||
$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.=")";
|
||||
}
|
||||
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);
|
||||
if ($resql)
|
||||
{
|
||||
while ($row = $db->fetch_array($resql)) {
|
||||
$row_array['label'] = $row['nom'];
|
||||
while ($row = $db->fetch_array($resql))
|
||||
{
|
||||
$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['key'] = $row['rowid'];
|
||||
|
||||
|
||||
array_push($return_arr,$row_array);
|
||||
}
|
||||
|
||||
|
||||
echo json_encode($return_arr);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user