Dbut ajout de l'autocompltion ajax sur la liste droulante des pays
This commit is contained in:
parent
673c6a2fda
commit
602473dced
@ -47,22 +47,24 @@ if(isset($_GET['keyref']) && !empty($_GET['keyref']) || isset($_GET['keylabel'])
|
||||
|
||||
|
||||
// Generation liste des pays
|
||||
if(isset($_POST['search']) && !empty($_POST['search']))
|
||||
if(isset($_POST['pays']) && !empty($_POST['pays']))
|
||||
{
|
||||
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);
|
||||
$sql.= " WHERE active = 1 AND libelle LIKE '%" . $_POST['pays'] . "%'";
|
||||
$sql.= " ORDER BY libelle ASC;";
|
||||
|
||||
$resql=$db->query($sql);
|
||||
|
||||
if ($resql)
|
||||
{
|
||||
print '<ul>';
|
||||
while($data = mysql_fetch_assoc($resql))
|
||||
{
|
||||
print '<li>'.stripslashes($data['libelle']).'</li>';
|
||||
print '<li>';
|
||||
print stripslashes($data['libelle']);
|
||||
print '<span class="informal" style="display:none">'.$data['rowid'].'-idcache</span>';
|
||||
print '</li>';
|
||||
}
|
||||
print '</ul>';
|
||||
}
|
||||
|
||||
@ -323,11 +323,12 @@ class Form
|
||||
if ($conf->use_ajax && $conf->global->CODE_DE_TEST == 1)
|
||||
{
|
||||
print '<div>';
|
||||
print '<input type="text" id="search" name="search" />';
|
||||
print '<input type="text" size="45" id="pays" name="pays" />';
|
||||
print '<input type="hidden" name="pays_id" id="pays_id" value="" '.$htmloption.' />';
|
||||
print '</div>';
|
||||
print '<div id="hint"></div>';
|
||||
print '<div id="hint" class="autocomplete"></div>';
|
||||
print '<script type="text/javascript">';
|
||||
print 'new Ajax.Autocompleter(\'search\',\'hint\',\''.DOL_URL_ROOT.'/ajaxresponse.php\');';
|
||||
print 'new Ajax.Autocompleter(\'pays\',\'hint\',\''.DOL_URL_ROOT.'/ajaxresponse.php\',{method: \'post\',paramName: \'pays\',afterUpdateElement: ac_return});';
|
||||
print '</script>';
|
||||
}
|
||||
else
|
||||
|
||||
@ -398,61 +398,61 @@ document.onmousemove=positiontip;
|
||||
|
||||
|
||||
/*=================================================================
|
||||
Function: formatDate (javascript object Date(), format)
|
||||
Function: formatDate (javascript object Date(), format)
|
||||
Purpose: Returns a date in the output format specified.
|
||||
The format string can use the following tags:
|
||||
Field | Tags
|
||||
-------------+-------------------------------
|
||||
Year | yyyy (4 digits), yy (2 digits)
|
||||
Month | MM (2 digits)
|
||||
Day of Month | dd (2 digits)
|
||||
Hour (1-12) | hh (2 digits)
|
||||
Hour (0-23) | HH (2 digits)
|
||||
Minute | mm (2 digits)
|
||||
Second | ss (2 digits)
|
||||
Field | Tags
|
||||
-------------+-------------------------------
|
||||
Year | yyyy (4 digits), yy (2 digits)
|
||||
Month | MM (2 digits)
|
||||
Day of Month | dd (2 digits)
|
||||
Hour (1-12) | hh (2 digits)
|
||||
Hour (0-23) | HH (2 digits)
|
||||
Minute | mm (2 digits)
|
||||
Second | ss (2 digits)
|
||||
Author: Laurent Destailleur
|
||||
Licence: GPL
|
||||
==================================================================*/
|
||||
function formatDate(date,format)
|
||||
{
|
||||
{
|
||||
//alert('formatDate date='+date+' format='+format);
|
||||
|
||||
// Force parametres en chaine
|
||||
format=format+"";
|
||||
format=format+"";
|
||||
|
||||
var result="";
|
||||
|
||||
var year=date.getYear()+""; if (year.length < 4) { year=""+(year-0+1900); }
|
||||
var month=date.getMonth()+1;
|
||||
var day=date.getDate();
|
||||
var hour=date.getHours();
|
||||
var min=date.getMinutes();
|
||||
var seconde=date.getSeconds();
|
||||
var year=date.getYear()+""; if (year.length < 4) { year=""+(year-0+1900); }
|
||||
var month=date.getMonth()+1;
|
||||
var day=date.getDate();
|
||||
var hour=date.getHours();
|
||||
var min=date.getMinutes();
|
||||
var seconde=date.getSeconds();
|
||||
|
||||
var i=0;
|
||||
while (i < format.length)
|
||||
{
|
||||
c=format.charAt(i); // Recupere char du format
|
||||
substr="";
|
||||
{
|
||||
c=format.charAt(i); // Recupere char du format
|
||||
substr="";
|
||||
j=i;
|
||||
while ((format.charAt(j)==c) && (j < format.length)) // Recupere char successif identiques
|
||||
{
|
||||
substr += format.charAt(j++);
|
||||
}
|
||||
{
|
||||
substr += format.charAt(j++);
|
||||
}
|
||||
|
||||
//alert('substr='+substr);
|
||||
if (substr == 'yyyy') { result=result+year; }
|
||||
else if (substr == 'yy') { result=result+year.substring(2,4); }
|
||||
else if (substr == 'MM') { result=result+(month<1||month>9?"":"0")+month; }
|
||||
else if (substr == 'd') { result=result+day; }
|
||||
else if (substr == 'dd') { result=result+(day<1||day>9?"":"0")+day; }
|
||||
else if (substr == 'hh') { if (hour > 12) hour-=12; result=result+(hour<1||hour>9?"":"0")+hour; }
|
||||
else if (substr == 'HH') { result=result+(hour<1||hour>9?"":"0")+hour; }
|
||||
else if (substr == 'mm') { result=result+(minute<1||minute>9?"":"0")+minute; }
|
||||
else if (substr == 'ss') { result=result+(seconde<1||seconde>9?"":"0")+seconde; }
|
||||
if (substr == 'yyyy') { result=result+year; }
|
||||
else if (substr == 'yy') { result=result+year.substring(2,4); }
|
||||
else if (substr == 'MM') { result=result+(month<1||month>9?"":"0")+month; }
|
||||
else if (substr == 'd') { result=result+day; }
|
||||
else if (substr == 'dd') { result=result+(day<1||day>9?"":"0")+day; }
|
||||
else if (substr == 'hh') { if (hour > 12) hour-=12; result=result+(hour<1||hour>9?"":"0")+hour; }
|
||||
else if (substr == 'HH') { result=result+(hour<1||hour>9?"":"0")+hour; }
|
||||
else if (substr == 'mm') { result=result+(minute<1||minute>9?"":"0")+minute; }
|
||||
else if (substr == 'ss') { result=result+(seconde<1||seconde>9?"":"0")+seconde; }
|
||||
else { result=result+substr; }
|
||||
|
||||
i+=substr.length;
|
||||
i+=substr.length;
|
||||
}
|
||||
|
||||
//alert(result);
|
||||
@ -461,50 +461,50 @@ function formatDate(date,format)
|
||||
|
||||
|
||||
/*=================================================================
|
||||
Function: getDateFromFormat(date_string, format_string)
|
||||
Function: getDateFromFormat(date_string, format_string)
|
||||
Purpose: This function takes a date string and a format string.
|
||||
It parses the date string with format and it returns
|
||||
the date as a javascript Date() object.
|
||||
If date does not match format, it returns 0.
|
||||
the date as a javascript Date() object.
|
||||
If date does not match format, it returns 0.
|
||||
The format string can use the following tags:
|
||||
Field | Tags
|
||||
-------------+-------------------------------
|
||||
Year | yyyy (4 digits), yy (2 digits)
|
||||
Month | MM (2 digits)
|
||||
Day of Month | dd (2 digits)
|
||||
Hour (1-12) | hh (2 digits)
|
||||
Hour (0-23) | HH (2 digits)
|
||||
Minute | mm (2 digits)
|
||||
Second | ss (2 digits)
|
||||
Field | Tags
|
||||
-------------+-------------------------------
|
||||
Year | yyyy (4 digits), yy (2 digits)
|
||||
Month | MM (2 digits)
|
||||
Day of Month | dd (2 digits)
|
||||
Hour (1-12) | hh (2 digits)
|
||||
Hour (0-23) | HH (2 digits)
|
||||
Minute | mm (2 digits)
|
||||
Second | ss (2 digits)
|
||||
Author: Laurent Destailleur
|
||||
Licence: GPL
|
||||
==================================================================*/
|
||||
function getDateFromFormat(val,format)
|
||||
{
|
||||
{
|
||||
//alert('getDateFromFormat val='+val+' format='+format);
|
||||
|
||||
// Force parametres en chaine
|
||||
val=val+"";
|
||||
val=val+"";
|
||||
format=format+"";
|
||||
|
||||
var now=new Date();
|
||||
var now=new Date();
|
||||
var year=now.getYear(); if (year.length < 4) { year=""+(year-0+1900); }
|
||||
var month=now.getMonth()+1;
|
||||
var day=now.getDate();
|
||||
var hour=now.getHours();
|
||||
var minute=now.getMinutes();
|
||||
var seconde=now.getSeconds();
|
||||
var month=now.getMonth()+1;
|
||||
var day=now.getDate();
|
||||
var hour=now.getHours();
|
||||
var minute=now.getMinutes();
|
||||
var seconde=now.getSeconds();
|
||||
|
||||
var i=0;
|
||||
while (i < format.length)
|
||||
{
|
||||
c=format.charAt(i); // Recupere char du format
|
||||
{
|
||||
c=format.charAt(i); // Recupere char du format
|
||||
substr="";
|
||||
j=i;
|
||||
j=i;
|
||||
while ((format.charAt(j)==c) && (j < format.length)) // Recupere char successif identiques
|
||||
{
|
||||
substr += format.charAt(j++);
|
||||
}
|
||||
{
|
||||
substr += format.charAt(j++);
|
||||
}
|
||||
|
||||
//alert('substr='+substr);
|
||||
if (substr == "yyyy") year=getIntegerInString(val,i,4,4);
|
||||
@ -521,49 +521,49 @@ function getDateFromFormat(val,format)
|
||||
}
|
||||
|
||||
// Check if format param are ok
|
||||
if (year==null||year<1) { return 0; }
|
||||
if (month==null||(month<1)||(month>12)) { return 0; }
|
||||
if (day==null||(day<1)||(day>31)) { return 0; }
|
||||
if (hour==null||(hour<0)||(hour>24)) { return 0; }
|
||||
if (minute==null||(minute<0)||(minute>60)) { return 0; }
|
||||
if (seconde==null||(seconde<0)||(seconde>60)) { return 0; }
|
||||
if (year==null||year<1) { return 0; }
|
||||
if (month==null||(month<1)||(month>12)) { return 0; }
|
||||
if (day==null||(day<1)||(day>31)) { return 0; }
|
||||
if (hour==null||(hour<0)||(hour>24)) { return 0; }
|
||||
if (minute==null||(minute<0)||(minute>60)) { return 0; }
|
||||
if (seconde==null||(seconde<0)||(seconde>60)) { return 0; }
|
||||
|
||||
//alert(year+' '+month+' '+day+' '+hour+' '+minute+' '+seconde);
|
||||
var newdate=new Date(year,month-1,day,hour,minute,seconde);
|
||||
//alert(year+' '+month+' '+day+' '+hour+' '+minute+' '+seconde);
|
||||
var newdate=new Date(year,month-1,day,hour,minute,seconde);
|
||||
|
||||
return newdate;
|
||||
}
|
||||
|
||||
/*=================================================================
|
||||
Function: stringIsInteger(string)
|
||||
Function: stringIsInteger(string)
|
||||
Purpose: Return true if string is an integer
|
||||
==================================================================*/
|
||||
function stringIsInteger(str)
|
||||
{
|
||||
var digits="1234567890";
|
||||
{
|
||||
var digits="1234567890";
|
||||
for (var i=0; i < str.length; i++)
|
||||
{
|
||||
{
|
||||
if (digits.indexOf(str.charAt(i))==-1)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/*=================================================================
|
||||
Function: getIntegerInString(string,pos,minlength,maxlength)
|
||||
Function: getIntegerInString(string,pos,minlength,maxlength)
|
||||
Purpose: Return part of string from position i that is integer
|
||||
==================================================================*/
|
||||
function getIntegerInString(str,i,minlength,maxlength)
|
||||
{
|
||||
{
|
||||
for (var x=maxlength; x>=minlength; x--)
|
||||
{
|
||||
var substr=str.substring(i,i+x);
|
||||
if (substr.length < minlength) { return null; }
|
||||
if (stringIsInteger(substr)) { return substr; }
|
||||
}
|
||||
return null;
|
||||
{
|
||||
var substr=str.substring(i,i+x);
|
||||
if (substr.length < minlength) { return null; }
|
||||
if (stringIsInteger(substr)) { return substr; }
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@ -592,3 +592,21 @@ function newpopup(url,title) {
|
||||
fen=window.open(tmp,title,wfeatures);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/*=================================================================
|
||||
Purpose: Récupère l'id d'une autcompletion Ajax
|
||||
Input: field,item
|
||||
Author: Regis Houssin
|
||||
Licence: GPL
|
||||
==================================================================*/
|
||||
function ac_return(field, item){
|
||||
// on met en place l'expression régulière
|
||||
var regex = new RegExp('[0123456789]*-idcache', 'i');
|
||||
// on l'applique au contenu
|
||||
var idCache = regex.exec($(item).innerHTML);
|
||||
//on récupère l'id
|
||||
id = idCache[0].replace('-idcache', '');
|
||||
// et on l'affecte au champ caché
|
||||
$(field.name+'_id').value = id;
|
||||
}
|
||||
@ -380,6 +380,7 @@ if ($_POST["getcustomercode"] || $_POST["getsuppliercode"] ||
|
||||
|
||||
print '<tr><td width="25%">'.$langs->trans('Country').'</td><td colspan="3">';
|
||||
$form->select_pays($soc->pays_id,'pays_id',$conf->use_javascript?' onChange="autofilltownfromzip_save_refresh_create()"':'');
|
||||
if ($conf->use_javascript && $conf->use_javascript) print '<div id="hint"></div>';//utile pour afficher la recherche des pays avec ajax
|
||||
print '</td></tr>';
|
||||
|
||||
print '<tr><td>'.$langs->trans('State').'</td><td colspan="3">';
|
||||
|
||||
@ -1044,3 +1044,32 @@ td.hidden {
|
||||
td.alerte {
|
||||
background: #FF99A9;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* ============================================================================== */
|
||||
/* Liste déroulante de l'autocompletion Ajax */
|
||||
/* ============================================================================== */
|
||||
|
||||
div.autocomplete {
|
||||
position:absolute;
|
||||
width:250px;
|
||||
background-color:white;
|
||||
border:1px solid #888;
|
||||
margin:0px;
|
||||
padding:0px;
|
||||
}
|
||||
div.autocomplete ul {
|
||||
list-style-type:none;
|
||||
margin:0px;
|
||||
padding:0px;
|
||||
}
|
||||
div.autocomplete ul li.selected { background-color: #ffb;}
|
||||
div.autocomplete ul li {
|
||||
list-style-type:none;
|
||||
display:block;
|
||||
margin:0;
|
||||
padding:2px;
|
||||
height:16px;
|
||||
cursor:pointer;
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user