Fix: search company with jQuery - ok

This commit is contained in:
Regis Houssin
2010-10-10 17:44:34 +00:00
parent 01a826b2e5
commit 4d4c4a8bed
6 changed files with 17 additions and 53 deletions

View File

@@ -43,12 +43,6 @@ $langs->load("bills");
$langs->load("orders");
$langs->load("agenda");
// If socid provided by ajax company selector
if (GETPOST('socid_id'))
{
$_GET['socid'] = GETPOST('socid_id');
$_POST['socid'] = GETPOST('socid_id');
}
// Security check
$socid = GETPOST('socid');
@@ -480,7 +474,7 @@ if (GETPOST('action') == 'create')
}
else
{
print $html->select_societes('','company','',1,1);
print $html->select_societes('','socid','',1,1);
}
print '</td></tr>';
@@ -668,7 +662,7 @@ if ($id)
// Company
print '<tr><td>'.$langs->trans("Company").'</td>';
print '<td>';
print $html->select_societes($act->societe->id,'company','',1,1);
print $html->select_societes($act->societe->id,'socid','',1,1);
print '</td>';
// Contact

View File

@@ -526,7 +526,7 @@ class Form
* \param showtype Show third party type in combolist (customer, prospect or supplier)
* \param forcecombo Force to use combo box
*/
function select_societes($selected='',$htmlname='company',$filter='',$showempty=0, $showtype=0, $forcecombo=0)
function select_societes($selected='',$htmlname='socid',$filter='',$showempty=0, $showtype=0, $forcecombo=0)
{
global $conf,$user,$langs;
@@ -558,13 +558,13 @@ class Form
print '<td class="nobordernopadding">';
if ($socid == 0)
{
print '<input type="text" size="30" id="'.$htmlname.'" name="'.$htmlname.'" value="" />';
print '<input type="text" size="30" id="search_'.$htmlname.'" name="search_'.$htmlname.'" value="" />';
}
else
{
print '<input type="text" size="30" id="'.$htmlname.'" name="'.$htmlname.'" value="'.$obj->nom.'" />';
print '<input type="text" size="30" id="search_'.$htmlname.'" name="search_'.$htmlname.'" value="'.$obj->nom.'" />';
}
print ajax_autocompleter(($socid?$socid:-1),$htmlname,'socid',DOL_URL_ROOT.'/societe/ajaxcompanies.php?filter='.urlencode($filter), '');
print ajax_autocompleter(($socid?$socid:-1),$htmlname,'socname',DOL_URL_ROOT.'/societe/ajaxcompanies.php?filter='.urlencode($filter), '');
print '</td>';
print '</tr>';
print '</table>';

View File

@@ -529,7 +529,7 @@ class FormCompany
}
// We call a page after a small delay when a new input has been selected
$javaScript = "window.location=\'./contact.php?".$var_id."=".$object->id."&amp;".$htmlname."=\' + document.getElementById(\'".$htmlname."_id\').value;";
$javaScript = "window.location=\'./contact.php?".$var_id."=".$object->id."&amp;".$htmlname."=\' + document.getElementById(\'".$htmlname."\').value;";
$htmloption = 'onChange="ac_delay(\''.$javaScript.'\',\'500\')"';
print "\n".'<!-- Input text for third party with Ajax.Autocompleter (selectCompaniesForNewContact) -->'."\n";
@@ -539,17 +539,15 @@ class FormCompany
{
//$langs->load("companies");
//print '<input type="text" size="30" id="'.$htmlname.'_label" name="'.$htmlname.'" value="'.$langs->trans("SelectCompany").'" '.$htmloption.' />';
print '<input type="text" size="30" id="'.$htmlname.'" name="'.$htmlname.'" value="" '.$htmloption.' />';
print '<input type="text" size="30" id="search_'.$htmlname.'" name="search_'.$htmlname.'" value="" '.$htmloption.' />';
}
else
{
print '<input type="text" size="30" id="'.$htmlname.'" name="'.$htmlname.'" value="'.$obj->nom.'" '.$htmloption.' />';
print '<input type="text" size="30" id="search_'.$htmlname.'" name="search_'.$htmlname.'" value="'.$obj->nom.'" '.$htmloption.' />';
}
print ajax_autocompleter(($socid?$socid:-1),$htmlname,DOL_URL_ROOT.'/societe/ajaxcompanies.php','');
print ajax_autocompleter(($socid?$socid:-1),$htmlname,'socname',DOL_URL_ROOT.'/societe/ajaxcompanies.php','');
print '</td>';
print '<td class="nobordernopadding" align="left" width="16">';
print ajax_indicator($htmlname,'working');
print '</td></tr>';
print '</tr>';
print '</table>';
print "\n";
return $socid;

View File

@@ -58,14 +58,6 @@ if ($_GET["id"] > 0 || ! empty($_GET["ref"]))
$fichinterid=$fichinter->id;
}
// If socid provided by ajax company selector
if (! empty($_REQUEST['socid_id']))
{
$_GET['socid'] = $_GET['socid_id'];
$_POST['socid'] = $_POST['socid_id'];
$_REQUEST['socid'] = $_REQUEST['socid_id'];
}
// Security check
if ($user->societe_id) $socid=$user->societe_id;
$result = restrictedArea($user, 'ficheinter', $fichinterid, 'fichinter');

View File

@@ -78,31 +78,29 @@ function ajax_updater($htmlname,$keysearch,$url,$option='',$indicator='working')
* \brief Get value of field, do Ajax process and return result
* \param htmlname nom et id du champ
* \param url chemin du fichier de reponse : /chemin/fichier.php
* \param indicator nom de l'image gif sans l'extension
* \return string script complet
*/
function ajax_autocompleter($selected='',$htmlname,$value,$url,$indicator='working')
function ajax_autocompleter($selected='',$htmlname,$valname,$url)
{
$script='';
$script.= '<input type="hidden" name="'.$value.'" id="'.$value.'" value="'.$selected.'" />';
$script.= '<input type="hidden" name="'.$htmlname.'" id="'.$htmlname.'" value="'.$selected.'" />';
//$script.= '<div id="'.$htmlname.'" class="ui-widget"></div>';
$script.= '<script type="text/javascript">';
$script.= 'jQuery(document).ready(function() {
jQuery("input#'.$htmlname.'").autocomplete({
jQuery("input#search_'.$htmlname.'").autocomplete({
source: function( request, response ) {
jQuery.get("'.$url.'", { socid: request.term }, function(data){
response( jQuery.map( data, function( item ) {
return { label: item.socname, value: item.socid }
return { label: item.'.$valname.', value: item.'.$valname.', id: item.'.$htmlname.'}
}));
}, "json");
},
dataType: "json",
minLength: 2,
select: function( event, ui ) {
jQuery("#'.$htmlname.'").val(ui.item.label);
jQuery("#'.$value.'").val(ui.item.value);
jQuery("#'.$htmlname.'").val(ui.item.id);
}
});
});';

View File

@@ -42,15 +42,11 @@ require('../main.inc.php');
// Ajout directives pour resoudre bug IE
//header('Cache-Control: Public, must-revalidate');
//header('Pragma: public');
header("Content-type: text/x-json");
//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 '<body id="mainbody">';
//print '<!-- Ajax page called with url '.$_SERVER["PHP_SELF"].'?'.$_SERVER["QUERY_STRING"].' -->'."\n";
dol_syslog(join(',',$_GET));
@@ -89,18 +85,6 @@ if (! empty($_POST['newcompany']) || ! empty($_GET['socid']) || ! empty($_POST['
array_push($return_arr,$row_array);
}
/*
print '<ul>';
while ($company = $db->fetch_object($resql))
{
print '<li>';
print $company->nom;
// To output content that will not be inserted into selected field, we use span.
print '<span id="object" class="informal" style="display:none">'.$company->rowid.'-idcache</span>';
print '</li>';
}
print '</ul>';
*/
echo json_encode($return_arr);
}
@@ -110,6 +94,4 @@ else
}
//print "</body>";
//print "</html>";
?>