Fix: Ajax use of third party select
This commit is contained in:
parent
980eb1a422
commit
12cf04ba79
@ -28,11 +28,11 @@ require_once(DOL_DOCUMENT_ROOT."/lib/admin.lib.php");
|
|||||||
require_once(DOL_DOCUMENT_ROOT."/html.formproduct.class.php");
|
require_once(DOL_DOCUMENT_ROOT."/html.formproduct.class.php");
|
||||||
|
|
||||||
// If socid provided by ajax company selector
|
// If socid provided by ajax company selector
|
||||||
if (! empty($_REQUEST['socid_id']))
|
if (! empty($_REQUEST['CASHDESK_ID_THIRDPARTY_id']))
|
||||||
{
|
{
|
||||||
$_GET['socid'] = $_GET['socid_id'];
|
$_GET['CASHDESK_ID_THIRDPARTY'] = $_GET['CASHDESK_ID_THIRDPARTY_id'];
|
||||||
$_POST['socid'] = $_POST['socid_id'];
|
$_POST['CASHDESK_ID_THIRDPARTY'] = $_POST['CASHDESK_ID_THIRDPARTY_id'];
|
||||||
$_REQUEST['socid'] = $_REQUEST['socid_id'];
|
$_REQUEST['CASHDESK_ID_THIRDPARTY'] = $_REQUEST['CASHDESK_ID_THIRDPARTY_id'];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Security check
|
// Security check
|
||||||
@ -89,7 +89,7 @@ print "</tr>\n";
|
|||||||
$var=!$var;
|
$var=!$var;
|
||||||
print '<tr '.$bc[$var].'><td width=\"50%\">'.$langs->trans("CashDeskThirdPartyForSell").'</td>';
|
print '<tr '.$bc[$var].'><td width=\"50%\">'.$langs->trans("CashDeskThirdPartyForSell").'</td>';
|
||||||
print '<td colspan="2">';
|
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>';
|
print '</td></tr>';
|
||||||
if ($conf->global->MAIN_MODULE_BANQUE)
|
if ($conf->global->MAIN_MODULE_BANQUE)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -462,8 +462,9 @@ class Form
|
|||||||
* \param filter Optionnal filters criteras
|
* \param filter Optionnal filters criteras
|
||||||
* \param showempty Add an empty field
|
* \param showempty Add an empty field
|
||||||
* \param showtype Show if third party is customer, prospect or supplier
|
* \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;
|
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";
|
if (!$user->rights->societe->client->voir && !$user->societe_id) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
|
||||||
$sql.= " WHERE s.entity = ".$conf->entity;
|
$sql.= " WHERE s.entity = ".$conf->entity;
|
||||||
if ($filter) $sql.= " AND ".$filter;
|
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;
|
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";
|
$sql.= " ORDER BY nom ASC";
|
||||||
|
|
||||||
@ -481,7 +482,7 @@ class Form
|
|||||||
$resql=$this->db->query($sql);
|
$resql=$this->db->query($sql);
|
||||||
if ($resql)
|
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;
|
$socid = 0;
|
||||||
if ($selected)
|
if ($selected)
|
||||||
|
|||||||
@ -133,11 +133,14 @@ function ajax_autocompleter($selected='',$htmlname,$url,$indicator='working')
|
|||||||
$script.= '<script type="text/javascript">';
|
$script.= '<script type="text/javascript">';
|
||||||
$script.= 'new Ajax.Autocompleter(\''.$htmlname.'\',\'result'.$htmlname.'\',\''.$url.'\',{
|
$script.= 'new Ajax.Autocompleter(\''.$htmlname.'\',\'result'.$htmlname.'\',\''.$url.'\',{
|
||||||
method: \'post\',
|
method: \'post\',
|
||||||
paramName: \''.$htmlname.'\',
|
paramName: \'socid\',
|
||||||
minChars: \'1\',
|
minChars: \'1\',
|
||||||
indicator: \'indicator'.$htmlname.'\',
|
indicator: \'indicator'.$htmlname.'\',
|
||||||
afterUpdateElement: ac_return
|
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>';
|
$script.= '</script>';
|
||||||
|
|
||||||
return $script;
|
return $script;
|
||||||
|
|||||||
@ -579,22 +579,22 @@ function newpopup(url,title) {
|
|||||||
|
|
||||||
|
|
||||||
/*=================================================================
|
/*=================================================================
|
||||||
Purpose: Recupere id d'une autcompletion Ajax
|
Purpose: Set value of a field after return of Ajax call
|
||||||
Input: field,item
|
Input: HTML field name, val
|
||||||
Author: Regis Houssin
|
Author: Regis Houssin
|
||||||
Licence: GPL
|
Licence: GPL
|
||||||
==================================================================*/
|
==================================================================*/
|
||||||
function ac_return(field, item){
|
function ac_return(field, val){
|
||||||
/* alert('field.name='+field.name+'-'+item.innerHTML); */
|
/* alert('field.name='+field.name+'-'+val.innerHTML); */
|
||||||
/* on met en place l'expression reguliere */
|
/* on met en place l'expression reguliere */
|
||||||
var regex = new RegExp('[0123456789]*-idcache', 'i');
|
var regex = new RegExp('[0123456789]*-idcache', 'i');
|
||||||
/* on l'applique au contenu */
|
/* on l'applique au contenu */
|
||||||
var idCache = regex.exec(item.innerHTML);
|
var idCache = regex.exec(val.innerHTML);
|
||||||
/* on recupere id */
|
/* on recupere id */
|
||||||
id = idCache[0].replace('-idcache', '');
|
id = idCache[0].replace('-idcache', '');
|
||||||
/* alert('field.name='+field.name+'-'+idCache[0]+'-'+id); */
|
/* alert('field.name='+field.name+'-'+idCache[0]+'-'+id); */
|
||||||
/* et on l'affecte au champ cache */
|
/* 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;
|
$(field.name+'_id').value = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -36,6 +36,8 @@ top_htmlhead("", "", 1, 1);
|
|||||||
|
|
||||||
print '<body id="mainbody">';
|
print '<body id="mainbody">';
|
||||||
|
|
||||||
|
dol_syslog(join(',',$_POST));
|
||||||
|
|
||||||
// Generation liste des societes
|
// Generation liste des societes
|
||||||
if (! empty($_POST['newcompany']) || ! empty($_POST['socid']) || ! empty($_POST['id_fourn']))
|
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>';
|
print '</ul>';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
print "</body>";
|
print "</body>";
|
||||||
print "</html>";
|
print "</html>";
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user