Fix: uniformize json with search company

Fix: search product with jQuery
This commit is contained in:
Regis Houssin 2010-10-11 09:14:21 +00:00
parent cfa3e3c9cf
commit c1b8055538
5 changed files with 15 additions and 14 deletions

View File

@ -564,7 +564,7 @@ class Form
{
print '<input type="text" size="30" id="search_'.$htmlname.'" name="search_'.$htmlname.'" value="'.$obj->nom.'" />';
}
print ajax_autocompleter(($socid?$socid:-1),$htmlname,'socname',DOL_URL_ROOT.'/societe/ajaxcompanies.php?filter='.urlencode($filter), '');
print ajax_autocompleter(($socid?$socid:-1),$htmlname,DOL_URL_ROOT.'/societe/ajaxcompanies.php?filter='.urlencode($filter), '');
print '</td>';
print '</tr>';
print '</table>';
@ -862,11 +862,11 @@ class Form
if ($conf->global->MAIN_USE_NEW_JQUERY)
{
// mode=1 means customers products
print ajax_autocompleter2('',$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 '<div class="ui-widget">';
print '<label for="'.$htmlname.'free">'.$langs->trans("RefOrLabel").':</label>';
print '<input id="'.$htmlname.'free" />';
print '<label for="search_'.$htmlname.'">'.$langs->trans("RefOrLabel").':</label>';
print '<input id="search_'.$htmlname.'" />';
print '</div>';
}
else

View File

@ -545,7 +545,7 @@ class FormCompany
{
print '<input type="text" size="30" id="search_'.$htmlname.'" name="search_'.$htmlname.'" value="'.$obj->nom.'" '.$htmloption.' />';
}
print ajax_autocompleter(($socid?$socid:-1),$htmlname,'socname',DOL_URL_ROOT.'/societe/ajaxcompanies.php','');
print ajax_autocompleter(($socid?$socid:-1),$htmlname,DOL_URL_ROOT.'/societe/ajaxcompanies.php','');
print '</td>';
print '</tr>';
print '</table>';

View File

@ -80,7 +80,7 @@ function ajax_updater($htmlname,$keysearch,$url,$option='',$indicator='working')
* \param url chemin du fichier de reponse : /chemin/fichier.php
* \return string script complet
*/
function ajax_autocompleter($selected='',$htmlname,$valname,$url)
function ajax_autocompleter($selected='',$htmlname,$url,$option='')
{
$script='';
@ -90,10 +90,10 @@ function ajax_autocompleter($selected='',$htmlname,$valname,$url)
$script.= 'jQuery(document).ready(function() {
jQuery("input#search_'.$htmlname.'").autocomplete({
source: function( request, response ) {
jQuery.get("'.$url.'", { '.$htmlname.': request.term }, function(data){
jQuery.get("'.$url.($option?'?'.$option:'').'", { '.$htmlname.': request.term }, function(data){
response( jQuery.map( data, function( item ) {
var label = item.'.$valname.'.toString().replace(new RegExp("("+request.term+")","i"),"<strong>$1</strong>");
return { label: label, value: item.'.$valname.', id: item.'.$htmlname.'}
var label = item.label.toString().replace(new RegExp("("+request.term+")","i"),"<strong>$1</strong>");
return { label: label, value: item.value, id: item.key}
}));
}, "json");
},

View File

@ -50,16 +50,16 @@ $langs->load("main");
//top_htmlhead("", "", 1); // Replaced with top_httphead. An ajax page does not need html header.
top_httphead();
print '<!-- Ajax page called with url '.$_SERVER["PHP_SELF"].'?'.$_SERVER["QUERY_STRING"].' -->'."\n";
//print '<!-- Ajax page called with url '.$_SERVER["PHP_SELF"].'?'.$_SERVER["QUERY_STRING"].' -->'."\n";
//print '<body class="nocellnopadd">'."\n";
dol_syslog(join(',',$_POST));
if (! isset($_GET['keysearch']) && ! isset($_GET['term'])) return;
if (! isset($_GET['keysearch']) && ! isset($_GET['idprod'])) return;
// When used from jQuery, the search term is added as GET param "term".
$searchkey=isset($_GET['keysearch'])?$_GET['keysearch']:$_GET['term'];
$searchkey=isset($_GET['keysearch'])?$_GET['keysearch']:$_GET['idprod'];
$outjson=isset($_GET['outjson'])?$_GET['outjson']:0;
// Get list of product.

View File

@ -80,8 +80,9 @@ if (! empty($_GET['newcompany']) || ! empty($_GET['socid']) || ! empty($_GET['id
if ($resql)
{
while ($row = $db->fetch_array($resql)) {
$row_array['socname'] = $row['nom'];
$row_array['socid'] = $row['rowid'];
$row_array['label'] = $row['nom'];
$row_array['value'] = $row['nom'];
$row_array['key'] = $row['rowid'];
array_push($return_arr,$row_array);
}