Add: début ajout autocompletion ajax sur la liste des sociétés
This commit is contained in:
parent
d509a46a32
commit
15de773bc0
@ -382,14 +382,44 @@ class CommonObject
|
|||||||
*/
|
*/
|
||||||
function selectCompaniesForNewContact($object, $var_id, $selected = '', $htmlname = 'newcompany')
|
function selectCompaniesForNewContact($object, $var_id, $selected = '', $htmlname = 'newcompany')
|
||||||
{
|
{
|
||||||
|
global $conf, $langs;
|
||||||
|
|
||||||
// On recherche les societes
|
// On recherche les societes
|
||||||
$sql = "SELECT s.rowid, s.nom FROM";
|
$sql = "SELECT s.rowid, s.nom FROM";
|
||||||
$sql .= " ".MAIN_DB_PREFIX."societe as s";
|
$sql .= " ".MAIN_DB_PREFIX."societe as s";
|
||||||
//if ($filter) $sql .= " WHERE $filter";
|
if ($conf->use_ajax && $conf->global->CODE_DE_TEST == 1)
|
||||||
|
{
|
||||||
|
$sql.= " WHERE rowid = ".$selected;
|
||||||
|
}
|
||||||
$sql .= " ORDER BY nom ASC";
|
$sql .= " ORDER BY nom ASC";
|
||||||
|
|
||||||
$resql = $object->db->query($sql);
|
$resql = $object->db->query($sql);
|
||||||
if ($resql)
|
if ($resql)
|
||||||
|
{
|
||||||
|
if ($conf->use_ajax && $conf->global->CODE_DE_TEST == 1)
|
||||||
|
{
|
||||||
|
$langs->load("companies");
|
||||||
|
$obj = $this->db->fetch_object($resql);
|
||||||
|
$socid = $obj->rowid?$obj->rowid:'';
|
||||||
|
$javaScript = "window.location=\'./contact.php?".$var_id."=".$object->id."&".$htmlname."=\' + document.getElementById(\'newcompany_id\').value;";
|
||||||
|
|
||||||
|
// On applique un delai d'execution pour le bon fonctionnement
|
||||||
|
$htmloption = 'onChange="ac_delay(\''.$javaScript.'\',\'500\')"';
|
||||||
|
|
||||||
|
print '<div>';
|
||||||
|
if ($obj->rowid == 0)
|
||||||
|
{
|
||||||
|
print '<input type="text" size="30" id="newcompany" name="newcompany" value="'.$langs->trans("SelectCompany").'" '.$htmloption.' />';
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
print '<input type="text" size="30" id="newcompany" name="newcompany" value="'.$obj->nom.'" '.$htmloption.' />';
|
||||||
|
}
|
||||||
|
|
||||||
|
print ajax_autocompleter($socid,'newcompany','/societe/ajaxcompanies.php','working');
|
||||||
|
return $socid;
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
$javaScript = "window.location='./contact.php?".$var_id."=".$object->id."&".$htmlname."=' + form.".$htmlname.".options[form.".$htmlname.".selectedIndex].value;";
|
$javaScript = "window.location='./contact.php?".$var_id."=".$object->id."&".$htmlname."=' + form.".$htmlname.".options[form.".$htmlname.".selectedIndex].value;";
|
||||||
print '<select class="flat" name="'.$htmlname.'" onChange="'.$javaScript.'">';
|
print '<select class="flat" name="'.$htmlname.'" onChange="'.$javaScript.'">';
|
||||||
@ -416,12 +446,14 @@ class CommonObject
|
|||||||
print "</select>\n";
|
print "</select>\n";
|
||||||
return $firstCompany;
|
return $firstCompany;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
dolibarr_print_error($object->db);
|
dolibarr_print_error($object->db);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|||||||
64
htdocs/societe/ajaxcompanies.php
Normal file
64
htdocs/societe/ajaxcompanies.php
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
<?php
|
||||||
|
/* Copyright (C) 2006 Andre Cianfarani <acianfa@free.fr>
|
||||||
|
* Copyright (C) 2005-2007 Regis Houssin <regis.houssin@cap-networks.com>
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
|
*
|
||||||
|
* $Id$
|
||||||
|
* $Source$
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
\file htdocs/societe/ajaxcountries.php
|
||||||
|
\brief Fichier de reponse sur evenement Ajax
|
||||||
|
\version $Revision$
|
||||||
|
*/
|
||||||
|
|
||||||
|
require('../main.inc.php');
|
||||||
|
|
||||||
|
top_htmlhead("", "", 1, 1);
|
||||||
|
|
||||||
|
print '<body id="mainbody">';
|
||||||
|
|
||||||
|
// Generation liste des sociétés
|
||||||
|
if(isset($_POST['newcompany']) && !empty($_POST['newcompany']))
|
||||||
|
{
|
||||||
|
global $langs;
|
||||||
|
$langs->load("dict");
|
||||||
|
|
||||||
|
$sql = "SELECT rowid, nom";
|
||||||
|
$sql.= " FROM ".MAIN_DB_PREFIX."societe";
|
||||||
|
$sql.= " WHERE nom LIKE '%" . utf8_decode($_POST['newcompany']) . "%'";
|
||||||
|
$sql.= " ORDER BY nom ASC;";
|
||||||
|
|
||||||
|
$resql=$db->query($sql);
|
||||||
|
|
||||||
|
if ($resql)
|
||||||
|
{
|
||||||
|
print '<ul>';
|
||||||
|
while($company = $db->fetch_object($resql))
|
||||||
|
{
|
||||||
|
print '<li>';
|
||||||
|
print $company->nom;
|
||||||
|
print '<span id="socid" class="informal" style="display:none">'.$company->rowid.'-idcache</span>';
|
||||||
|
print '</li>';
|
||||||
|
}
|
||||||
|
print '</ul>';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
print "</body>";
|
||||||
|
print "</html>";
|
||||||
|
?>
|
||||||
Loading…
Reference in New Issue
Block a user