Fix: search company with jQuery - ok
This commit is contained in:
parent
01a826b2e5
commit
4d4c4a8bed
@ -43,12 +43,6 @@ $langs->load("bills");
|
|||||||
$langs->load("orders");
|
$langs->load("orders");
|
||||||
$langs->load("agenda");
|
$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
|
// Security check
|
||||||
$socid = GETPOST('socid');
|
$socid = GETPOST('socid');
|
||||||
@ -480,7 +474,7 @@ if (GETPOST('action') == 'create')
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
print $html->select_societes('','company','',1,1);
|
print $html->select_societes('','socid','',1,1);
|
||||||
}
|
}
|
||||||
print '</td></tr>';
|
print '</td></tr>';
|
||||||
|
|
||||||
@ -668,7 +662,7 @@ if ($id)
|
|||||||
// Company
|
// Company
|
||||||
print '<tr><td>'.$langs->trans("Company").'</td>';
|
print '<tr><td>'.$langs->trans("Company").'</td>';
|
||||||
print '<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>';
|
print '</td>';
|
||||||
|
|
||||||
// Contact
|
// Contact
|
||||||
|
|||||||
@ -526,7 +526,7 @@ class Form
|
|||||||
* \param showtype Show third party type in combolist (customer, prospect or supplier)
|
* \param showtype Show third party type in combolist (customer, prospect or supplier)
|
||||||
* \param forcecombo Force to use combo box
|
* \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;
|
global $conf,$user,$langs;
|
||||||
|
|
||||||
@ -558,13 +558,13 @@ class Form
|
|||||||
print '<td class="nobordernopadding">';
|
print '<td class="nobordernopadding">';
|
||||||
if ($socid == 0)
|
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
|
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 '</td>';
|
||||||
print '</tr>';
|
print '</tr>';
|
||||||
print '</table>';
|
print '</table>';
|
||||||
|
|||||||
@ -529,7 +529,7 @@ class FormCompany
|
|||||||
}
|
}
|
||||||
|
|
||||||
// We call a page after a small delay when a new input has been selected
|
// We call a page after a small delay when a new input has been selected
|
||||||
$javaScript = "window.location=\'./contact.php?".$var_id."=".$object->id."&".$htmlname."=\' + document.getElementById(\'".$htmlname."_id\').value;";
|
$javaScript = "window.location=\'./contact.php?".$var_id."=".$object->id."&".$htmlname."=\' + document.getElementById(\'".$htmlname."\').value;";
|
||||||
$htmloption = 'onChange="ac_delay(\''.$javaScript.'\',\'500\')"';
|
$htmloption = 'onChange="ac_delay(\''.$javaScript.'\',\'500\')"';
|
||||||
|
|
||||||
print "\n".'<!-- Input text for third party with Ajax.Autocompleter (selectCompaniesForNewContact) -->'."\n";
|
print "\n".'<!-- Input text for third party with Ajax.Autocompleter (selectCompaniesForNewContact) -->'."\n";
|
||||||
@ -539,17 +539,15 @@ class FormCompany
|
|||||||
{
|
{
|
||||||
//$langs->load("companies");
|
//$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.'_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
|
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>';
|
||||||
print '<td class="nobordernopadding" align="left" width="16">';
|
print '</tr>';
|
||||||
print ajax_indicator($htmlname,'working');
|
|
||||||
print '</td></tr>';
|
|
||||||
print '</table>';
|
print '</table>';
|
||||||
print "\n";
|
print "\n";
|
||||||
return $socid;
|
return $socid;
|
||||||
|
|||||||
@ -58,14 +58,6 @@ if ($_GET["id"] > 0 || ! empty($_GET["ref"]))
|
|||||||
$fichinterid=$fichinter->id;
|
$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
|
// Security check
|
||||||
if ($user->societe_id) $socid=$user->societe_id;
|
if ($user->societe_id) $socid=$user->societe_id;
|
||||||
$result = restrictedArea($user, 'ficheinter', $fichinterid, 'fichinter');
|
$result = restrictedArea($user, 'ficheinter', $fichinterid, 'fichinter');
|
||||||
|
|||||||
@ -78,31 +78,29 @@ function ajax_updater($htmlname,$keysearch,$url,$option='',$indicator='working')
|
|||||||
* \brief Get value of field, do Ajax process and return result
|
* \brief Get value of field, do Ajax process and return result
|
||||||
* \param htmlname nom et id du champ
|
* \param htmlname nom et id du champ
|
||||||
* \param url chemin du fichier de reponse : /chemin/fichier.php
|
* \param url chemin du fichier de reponse : /chemin/fichier.php
|
||||||
* \param indicator nom de l'image gif sans l'extension
|
|
||||||
* \return string script complet
|
* \return string script complet
|
||||||
*/
|
*/
|
||||||
function ajax_autocompleter($selected='',$htmlname,$value,$url,$indicator='working')
|
function ajax_autocompleter($selected='',$htmlname,$valname,$url)
|
||||||
{
|
{
|
||||||
$script='';
|
$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.= '<div id="'.$htmlname.'" class="ui-widget"></div>';
|
||||||
$script.= '<script type="text/javascript">';
|
$script.= '<script type="text/javascript">';
|
||||||
$script.= 'jQuery(document).ready(function() {
|
$script.= 'jQuery(document).ready(function() {
|
||||||
jQuery("input#'.$htmlname.'").autocomplete({
|
jQuery("input#search_'.$htmlname.'").autocomplete({
|
||||||
source: function( request, response ) {
|
source: function( request, response ) {
|
||||||
jQuery.get("'.$url.'", { socid: request.term }, function(data){
|
jQuery.get("'.$url.'", { socid: request.term }, function(data){
|
||||||
response( jQuery.map( data, function( item ) {
|
response( jQuery.map( data, function( item ) {
|
||||||
return { label: item.socname, value: item.socid }
|
return { label: item.'.$valname.', value: item.'.$valname.', id: item.'.$htmlname.'}
|
||||||
}));
|
}));
|
||||||
}, "json");
|
}, "json");
|
||||||
},
|
},
|
||||||
dataType: "json",
|
dataType: "json",
|
||||||
minLength: 2,
|
minLength: 2,
|
||||||
select: function( event, ui ) {
|
select: function( event, ui ) {
|
||||||
jQuery("#'.$htmlname.'").val(ui.item.label);
|
jQuery("#'.$htmlname.'").val(ui.item.id);
|
||||||
jQuery("#'.$value.'").val(ui.item.value);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});';
|
});';
|
||||||
|
|||||||
@ -42,15 +42,11 @@ require('../main.inc.php');
|
|||||||
// Ajout directives pour resoudre bug IE
|
// Ajout directives pour resoudre bug IE
|
||||||
//header('Cache-Control: Public, must-revalidate');
|
//header('Cache-Control: Public, must-revalidate');
|
||||||
//header('Pragma: public');
|
//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_htmlhead("", "", 1); // Replaced with top_httphead. An ajax page does not need html header.
|
||||||
top_httphead();
|
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 id="mainbody">';
|
|
||||||
|
|
||||||
dol_syslog(join(',',$_GET));
|
dol_syslog(join(',',$_GET));
|
||||||
|
|
||||||
@ -89,18 +85,6 @@ if (! empty($_POST['newcompany']) || ! empty($_GET['socid']) || ! empty($_POST['
|
|||||||
|
|
||||||
array_push($return_arr,$row_array);
|
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);
|
echo json_encode($return_arr);
|
||||||
}
|
}
|
||||||
@ -110,6 +94,4 @@ else
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//print "</body>";
|
|
||||||
//print "</html>";
|
|
||||||
?>
|
?>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user