Add: dbut ajout autocompletion ajax sur la liste des socits

This commit is contained in:
Regis Houssin 2007-06-22 18:51:11 +00:00
parent d509a46a32
commit 15de773bc0
2 changed files with 126 additions and 30 deletions

View File

@ -382,45 +382,77 @@ class CommonObject
*/
function selectCompaniesForNewContact($object, $var_id, $selected = '', $htmlname = 'newcompany')
{
global $conf, $langs;
// On recherche les societes
$sql = "SELECT s.rowid, s.nom FROM";
$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";
$resql = $object->db->query($sql);
if ($resql)
{
$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.'">';
$num = $object->db->num_rows($resql);
$i = 0;
if ($num)
if ($conf->use_ajax && $conf->global->CODE_DE_TEST == 1)
{
while ($i < $num)
{
$obj = $object->db->fetch_object($resql);
if ($i == 0) $firstCompany = $obj->rowid;
if ($selected > 0 && $selected == $obj->rowid)
{
print '<option value="'.$obj->rowid.'" selected="true">'.dolibarr_trunc($obj->nom,24).'</option>';
$firstCompany = $obj->rowid;
}
else
{
print '<option value="'.$obj->rowid.'">'.dolibarr_trunc($obj->nom,24).'</option>';
}
$i ++;
}
}
print "</select>\n";
return $firstCompany;
}
else
{
dolibarr_print_error($object->db);
}
}
$langs->load("companies");
$obj = $this->db->fetch_object($resql);
$socid = $obj->rowid?$obj->rowid:'';
$javaScript = "window.location=\'./contact.php?".$var_id."=".$object->id."&amp;".$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."&amp;".$htmlname."=' + form.".$htmlname.".options[form.".$htmlname.".selectedIndex].value;";
print '<select class="flat" name="'.$htmlname.'" onChange="'.$javaScript.'">';
$num = $object->db->num_rows($resql);
$i = 0;
if ($num)
{
while ($i < $num)
{
$obj = $object->db->fetch_object($resql);
if ($i == 0) $firstCompany = $obj->rowid;
if ($selected > 0 && $selected == $obj->rowid)
{
print '<option value="'.$obj->rowid.'" selected="true">'.dolibarr_trunc($obj->nom,24).'</option>';
$firstCompany = $obj->rowid;
}
else
{
print '<option value="'.$obj->rowid.'">'.dolibarr_trunc($obj->nom,24).'</option>';
}
$i ++;
}
}
print "</select>\n";
return $firstCompany;
}
}
else
{
dolibarr_print_error($object->db);
}
}
/**
*

View 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>";
?>