Début ajout de l'autocomplétion ajax sur la liste déroulante des pays

This commit is contained in:
Regis Houssin 2007-02-08 11:00:18 +00:00
parent 603bf98509
commit 2ca1d314d5
3 changed files with 87 additions and 45 deletions

View File

@ -1,5 +1,6 @@
<?php <?php
/* Copyright (C) 2006 Andre Cianfarani <acianfa@free.fr> /* 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 * 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 * it under the terms of the GNU General Public License as published by
@ -21,7 +22,7 @@
/** /**
\file htdocs/ajaxresponse.php \file htdocs/ajaxresponse.php
\brief Fichier de reponse sur evenement ajax pour generation liste produits \brief Fichier de reponse sur evenement Ajax
\version $Revision$ \version $Revision$
*/ */
@ -36,8 +37,33 @@ print '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://ww
print "\n<html>"; print "\n<html>";
print "\n<body>"; print "\n<body>";
// Generation liste de produits
if(isset($_GET['keyref']) && !empty($_GET['keyref']) || isset($_GET['keylabel']) && !empty($_GET['keylabel']))
{
$form = new Form($db); $form = new Form($db);
$form->select_produits_do("",$_GET["htmlname"],"","",$_GET["price_level"],$_GET["keyref"],$_GET["keylabel"]); $form->select_produits_do("",$_GET["htmlname"],"","",$_GET["price_level"],$_GET["keyref"],$_GET["keylabel"]);
}
if(isset($_POST['search']) && !empty($_POST['search']))
{
print 'hello world';
$sql = "SELECT rowid, code, libelle, active";
$sql.= " FROM ".MAIN_DB_PREFIX."c_pays";
$sql.= " WHERE active = 1 AND libelle LIKE '%" . $_POST['search'] . "%'";
$sql.= " ORDER BY code ASC;";
$resql=$this->db->query($sql);
if ($resql)
{
print '<ul>';
while($data = mysql_fetch_assoc($resql))
{
print '<li>'.stripslashes($data['libelle']).'</li>';
}
print '</ul>';
}
}
print "</body>"; print "</body>";
print "</html>"; print "</html>";

View File

@ -319,6 +319,18 @@ class Form
$resql=$this->db->query($sql); $resql=$this->db->query($sql);
if ($resql) if ($resql)
{
if ($conf->use_ajax && $conf->global->CODE_DE_TEST == 1)
{
print '<div>';
print '<input type="text" id="search" name="search" />';
print '</div>';
print '<div id="hint"></div>';
print '<script type="text/javascript">';
print 'new Ajax.Autocompleter(\'search\',\'hint\',\''.DOL_URL_ROOT.'/ajaxresponse.php\');';
print '</script>';
}
else
{ {
print '<select class="flat" name="'.$htmlname.'" '.$htmloption.'>'; print '<select class="flat" name="'.$htmlname.'" '.$htmloption.'>';
$num = $this->db->num_rows($resql); $num = $this->db->num_rows($resql);
@ -348,7 +360,9 @@ class Form
print '</select>'; print '</select>';
return 0; return 0;
} }
else { }
else
{
dolibarr_print_error($this->db); dolibarr_print_error($this->db);
return 1; return 1;
} }

View File

@ -524,6 +524,8 @@ function top_htmlhead($head, $title="", $target="")
{ {
print '<script language="javascript" type="text/javascript" src="'.DOL_URL_ROOT.'/includes/scriptaculous/lib/prototype.js"></script>'."\n"; print '<script language="javascript" type="text/javascript" src="'.DOL_URL_ROOT.'/includes/scriptaculous/lib/prototype.js"></script>'."\n";
print '<script language="javascript" type="text/javascript" src="'.DOL_URL_ROOT.'/includes/scriptaculous/src/scriptaculous.js"></script>'."\n"; print '<script language="javascript" type="text/javascript" src="'.DOL_URL_ROOT.'/includes/scriptaculous/src/scriptaculous.js"></script>'."\n";
print '<script language="javascript" type="text/javascript" src="'.DOL_URL_ROOT.'/includes/scriptaculous/src/effects.js"></script>'."\n";
print '<script language="javascript" type="text/javascript" src="'.DOL_URL_ROOT.'/includes/scriptaculous/src/controls.js"></script>'."\n";
} }
print "</head>\n"; print "</head>\n";