Fix: Ajax use of third party select

This commit is contained in:
Laurent Destailleur 2009-09-11 13:24:47 +00:00
parent 980eb1a422
commit 12cf04ba79
5 changed files with 26 additions and 16 deletions

View File

@ -28,11 +28,11 @@ require_once(DOL_DOCUMENT_ROOT."/lib/admin.lib.php");
require_once(DOL_DOCUMENT_ROOT."/html.formproduct.class.php");
// If socid provided by ajax company selector
if (! empty($_REQUEST['socid_id']))
if (! empty($_REQUEST['CASHDESK_ID_THIRDPARTY_id']))
{
$_GET['socid'] = $_GET['socid_id'];
$_POST['socid'] = $_POST['socid_id'];
$_REQUEST['socid'] = $_REQUEST['socid_id'];
$_GET['CASHDESK_ID_THIRDPARTY'] = $_GET['CASHDESK_ID_THIRDPARTY_id'];
$_POST['CASHDESK_ID_THIRDPARTY'] = $_POST['CASHDESK_ID_THIRDPARTY_id'];
$_REQUEST['CASHDESK_ID_THIRDPARTY'] = $_REQUEST['CASHDESK_ID_THIRDPARTY_id'];
}
// Security check
@ -89,7 +89,7 @@ print "</tr>\n";
$var=!$var;
print '<tr '.$bc[$var].'><td width=\"50%\">'.$langs->trans("CashDeskThirdPartyForSell").'</td>';
print '<td colspan="2">';
print $form->select_societes($conf->global->CASHDESK_ID_THIRDPARTY,'CASHDESK_ID_THIRDPARTY','',1);
print $form->select_societes($conf->global->CASHDESK_ID_THIRDPARTY,'CASHDESK_ID_THIRDPARTY','',1,1);
print '</td></tr>';
if ($conf->global->MAIN_MODULE_BANQUE)
{

View File

@ -462,8 +462,9 @@ class Form
* \param filter Optionnal filters criteras
* \param showempty Add an empty field
* \param showtype Show if third party is customer, prospect or supplier
* \param forcecombo Force to use combo box
*/
function select_societes($selected='',$htmlname='socid',$filter='',$showempty=0, $showtype=0)
function select_societes($selected='',$htmlname='socid',$filter='',$showempty=0, $showtype=0, $forcecombo=0)
{
global $conf,$user,$langs;
@ -473,7 +474,7 @@ class Form
if (!$user->rights->societe->client->voir && !$user->societe_id) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
$sql.= " WHERE s.entity = ".$conf->entity;
if ($filter) $sql.= " AND ".$filter;
if ($selected && $conf->use_javascript_ajax && $conf->global->COMPANY_USE_SEARCH_TO_SELECT) $sql.= " AND rowid = ".$selected;
if (is_numeric($selected) && $conf->use_javascript_ajax && $conf->global->COMPANY_USE_SEARCH_TO_SELECT) $sql.= " AND s.rowid = ".$selected;
if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
$sql.= " ORDER BY nom ASC";
@ -481,7 +482,7 @@ class Form
$resql=$this->db->query($sql);
if ($resql)
{
if ($conf->use_javascript_ajax && $conf->global->COMPANY_USE_SEARCH_TO_SELECT)
if ($conf->use_javascript_ajax && $conf->global->COMPANY_USE_SEARCH_TO_SELECT && ! $forcecombo)
{
$socid = 0;
if ($selected)

View File

@ -133,11 +133,14 @@ function ajax_autocompleter($selected='',$htmlname,$url,$indicator='working')
$script.= '<script type="text/javascript">';
$script.= 'new Ajax.Autocompleter(\''.$htmlname.'\',\'result'.$htmlname.'\',\''.$url.'\',{
method: \'post\',
paramName: \''.$htmlname.'\',
paramName: \'socid\',
minChars: \'1\',
indicator: \'indicator'.$htmlname.'\',
afterUpdateElement: ac_return
});'; // Note: The ac_return will fill value inside the field htmlname (param of Autocompleter constructor) and htmlname_id (function ac_return)
});'; // paramName must be 'socid', as it is the name of POST parameter to send value in htmlname field.
// and it is name of parameter read by ajaxcompanies.php
// Note: The ac_return will fill value inside field htmlname (param of Autocompleter constructor)
// and will also fill value inside field htmlname_id (using function ac_return)
$script.= '</script>';
return $script;

View File

@ -579,22 +579,22 @@ function newpopup(url,title) {
/*=================================================================
Purpose: Recupere id d'une autcompletion Ajax
Input: field,item
Purpose: Set value of a field after return of Ajax call
Input: HTML field name, val
Author: Regis Houssin
Licence: GPL
==================================================================*/
function ac_return(field, item){
/* alert('field.name='+field.name+'-'+item.innerHTML); */
function ac_return(field, val){
/* alert('field.name='+field.name+'-'+val.innerHTML); */
/* on met en place l'expression reguliere */
var regex = new RegExp('[0123456789]*-idcache', 'i');
/* on l'applique au contenu */
var idCache = regex.exec(item.innerHTML);
var idCache = regex.exec(val.innerHTML);
/* on recupere id */
id = idCache[0].replace('-idcache', '');
/* alert('field.name='+field.name+'-'+idCache[0]+'-'+id); */
/* et on l'affecte au champ cache */
/* alert('field.name='+field.name+'-'+item.innerHTML+'-id='+id); */
/* alert('field.name='+field.name+'-'+val.innerHTML+'-id='+id); */
$(field.name+'_id').value = id;
}

View File

@ -36,6 +36,8 @@ top_htmlhead("", "", 1, 1);
print '<body id="mainbody">';
dol_syslog(join(',',$_POST));
// Generation liste des societes
if (! empty($_POST['newcompany']) || ! empty($_POST['socid']) || ! empty($_POST['id_fourn']))
{
@ -66,6 +68,10 @@ if (! empty($_POST['newcompany']) || ! empty($_POST['socid']) || ! empty($_POST[
print '</ul>';
}
}
else
{
}
print "</body>";
print "</html>";