Mise en function de ajax.updater et ajax.autocompleter

This commit is contained in:
Regis Houssin 2007-05-07 11:04:45 +00:00
parent a575e81603
commit e406742408
5 changed files with 66 additions and 33 deletions

View File

@ -406,13 +406,9 @@ class Form
{
print '<input type="text" size="45" id="pays" name="pays" value="'.$obj->libelle.'" '.$htmloption.' />';
}
print '<span id="indicator" style="display: none">'.img_gif('Working...','ajaxworking').'</span>';
print '<input type="hidden" name="pays_id" id="pays_id" value="'.$pays_id.'" />';
print '</div>';
print '<div id="hint" class="autocomplete"></div>';
print '<script type="text/javascript">';
print 'new Ajax.Autocompleter(\'pays\',\'hint\',\''.DOL_URL_ROOT.'/societe/ajaxcountries.php\',{method: \'post\',paramName: \'pays\',afterUpdateElement: ac_return});';
print '</script>';
print ajax_autocompleter($pays_id,'pays','/societe/ajaxcountries.php','ajaxworking');
}
else
{
@ -821,14 +817,8 @@ class Form
global $langs,$conf,$user;
if ($conf->global->PRODUIT_USE_SEARCH_TO_SELECT)
{
print $langs->trans("RefOrLabel").' : <input type="text" size="16" name="'.$htmlname.'" id="'.$htmlname.'">';
print '<span id="indicator" style="display: none">'.img_gif('Working...','ajaxworking').'</span>';
print '<input type="hidden" name="'.$htmlname.'" id="'.$htmlname.'" value="">';
print '<script type="text/javascript">';
print 'var url = \''.DOL_URL_ROOT.'/product/ajaxproducts.php\';';
print 'new Form.Element.Observer($("'.$htmlname.'"), 1, function(){var myAjax = new Ajax.Updater( {success: \'ajdynfield'.$htmlname.'\'}, url, {method: \'get\', parameters: "keysearch="+$("'.$htmlname.'").value+"&htmlname='.$htmlname.'&price_level='.$price_level.'"});});';
print '</script>';
print '<div class="notopnoleftnoright" id="ajdynfield'.$htmlname.'"></div>';
print $langs->trans("RefOrLabel").' : <input type="text" size="16" name="keysearch'.$htmlname.'" id="keysearch'.$htmlname.'">';
print ajax_updater($htmlname,'keysearch','/product/ajaxproducts.php','&price_level='.$price_level.'','ajaxworking');
}
else
{

View File

@ -1,15 +0,0 @@
If scriptaculous files are replaced by new version, following changes must be done:
* Edit prototype.js to set:
***************************
Ajax.Responders.register({
onCreate: function() {
$('indicator').show( );
Ajax.activeRequestCount++;
},
onComplete: function() {
$('indicator').hide( );
Ajax.activeRequestCount--;
}
});

View File

@ -793,11 +793,9 @@ Object.extend(Ajax.Responders, Enumerable);
Ajax.Responders.register({
onCreate: function() {
$('indicator').show( );
Ajax.activeRequestCount++;
},
onComplete: function() {
$('indicator').hide( );
Ajax.activeRequestCount--;
}
});

View File

@ -2598,5 +2598,66 @@ function num_open_day($timestampStart, $timestampEnd,$inhour=0,$lastday=0)
return $nbOpenDay;
}
/**
\brief Récupère la valeur d'un champ, effectue un traitement Ajax et affiche le résultat
\param htmlname nom et id du champ
\param keysearch nom et id complémentaire du champ de collecte
\param url chemin du fichier de réponse : /chemin/fichier.php
\param option champ supplémentaire de recherche dans les paramètres
\param indicator nom de l'image gif
\return script script complet
*/
function ajax_updater($htmlname,$keysearch,$url,$option='',$indicator='ajaxworking')
{
$script = '<input type="hidden" name="'.$htmlname.'" id="'.$htmlname.'" value="">';
$script.= '<span id="indicator'.$htmlname.'" style="display: none">'.img_gif('Working...',$indicator).'</span>';
$script.= '<script type="text/javascript">';
$script.= 'Ajax.Responders.register({
onCreate: function() {
$(\'indicator'.$htmlname.'\').show( );
},
onComplete: function() {
$(\'indicator'.$htmlname.'\').hide( );
}
});';
$script.= 'new Form.Element.Observer($("'.$keysearch.$htmlname.'"), 1,
function(){
var myAjax = new Ajax.Updater( {
success: \'ajdynfield'.$htmlname.'\'},
\''.DOL_URL_ROOT.$url.'\', {
method: \'get\',
parameters: "'.$keysearch.'="+$("'.$keysearch.$htmlname.'").value+"&htmlname='.$htmlname.$option.'"
});
});';
$script.= '</script>';
$script.= '<div class="notopnoleftnoright" id="ajdynfield'.$htmlname.'"></div>';
return $script;
}
/**
\brief Récupère la valeur d'un champ, effectue un traitement Ajax et affiche le résultat
\param htmlname nom et id du champ
\param url chemin du fichier de réponse : /chemin/fichier.php
\param indicator nom de l'image gif
\return script script complet
*/
function ajax_autocompleter($selected='',$htmlname,$url,$indicator='ajaxworking')
{
$script.= '<span id="indicator'.$htmlname.'" style="display: none">'.img_gif('Working...',$indicator).'</span>';
$script.= '<input type="hidden" name="'.$htmlname.'_id" id="'.$htmlname.'_id" value="'.$selected.'" />';
$script.= '</div>';
$script.= '<div id="result'.$htmlname.'" class="autocomplete"></div>';
$script.= '<script type="text/javascript">';
$script.= 'new Ajax.Autocompleter(\''.$htmlname.'\',\'result'.$htmlname.'\',\''.DOL_URL_ROOT.$url.'\',{
method: \'post\',
paramName: \''.$htmlname.'\',
indicator: \'indicator'.$htmlname.'\',
afterUpdateElement: ac_return
});';
$script.= '</script>';
return $script;
}
?>

View File

@ -426,7 +426,6 @@ 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_ajax) 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">';