Usage of autocomplete using jquery now works for products.

This commit is contained in:
Laurent Destailleur 2010-08-22 18:02:32 +00:00
parent 783a66b4fc
commit 629f782f17
8 changed files with 201 additions and 74 deletions

View File

@ -835,13 +835,14 @@ class Form
if ($conf->global->PRODUIT_USE_SEARCH_TO_SELECT)
{
if ($conf->global->MAIN_USE_JQUERY)
if ($conf->global->MAIN_USE_NEW_JQUERY)
{
print ajax_autocompleter2('',$htmlname,DOL_URL_ROOT.'/product/ajaxproducts.php','&price_level='.$price_level.'&type='.$filtertype.'&mode=1&status='.$status.'&finished='.$finished,'');
// mode=1 means customers products
print ajax_autocompleter2('',$htmlname,DOL_URL_ROOT.'/product/ajaxproducts.php','outjson=1&price_level='.$price_level.'&type='.$filtertype.'&mode=1&status='.$status.'&finished='.$finished,'');
print '<div class="ui-widget">';
print '<label for="'.$htmlname.'">'.$langs->trans("RefOrLabel").':</label>';
print '<input id="'.$htmlname.'" />';
print '<label for="'.$htmlname.'free">'.$langs->trans("RefOrLabel").':</label>';
print '<input id="'.$htmlname.'free" />';
print '</div>';
}
else
@ -863,7 +864,7 @@ class Form
}
else
{
$this->select_produits_do($selected,$htmlname,$filtertype,$limit,$price_level,'',$status,$finished);
$this->select_produits_do($selected,$htmlname,$filtertype,$limit,$price_level,'',$status,$finished,0);
}
}
@ -876,8 +877,11 @@ class Form
* \param price_level Level of price to show
* \param filterkey Filter on product
* \param status -1=Return all products, 0=Products not on sell, 1=Products on sell
* \param finished Filter on finished field: 2=No filter
* \param disableout Disable print output
* \return array Array of keys for json
*/
function select_produits_do($selected='',$htmlname='productid',$filtertype='',$limit=20,$price_level=0,$filterkey='',$status=1,$finished=2)
function select_produits_do($selected='',$htmlname='productid',$filtertype='',$limit=20,$price_level=0,$filterkey='',$status=1,$finished=2,$disableout=0)
{
global $langs,$conf,$user,$db;
@ -940,7 +944,7 @@ class Form
// Build output string
$outselect='';
$outjson='';
$outjson=array();
dol_syslog("Form::select_produits_do search product sql=".$sql, LOG_DEBUG);
$result=$this->db->query($sql);
@ -951,7 +955,7 @@ class Form
$outselect.='<select class="flat" name="'.$htmlname.'"';
if ($conf->use_javascript_ajax && $num && $conf->global->PRODUIT_USE_SEARCH_TO_SELECT) $outselect.=' onchange="publish_selvalue(this);"';
$outselect.='>';
if ($conf->use_javascript_ajax)
{
if (! $num)
@ -971,11 +975,18 @@ class Form
$i = 0;
while ($num && $i < $num)
{
$outkey='';
$outval='';
$outref='';
$objp = $this->db->fetch_object($result);
$label=$objp->label;
if (! empty($objp->label_translated)) $label=$objp->label_translated;
$outkey=$objp->rowid;
$outref=$objp->ref;
$opt = '<option value="'.$objp->rowid.'"';
$opt.= ($objp->rowid == $selected)?' selected="true"':'';
if ($conf->stock->enabled && $objp->fk_product_type == 0 && isset($objp->stock))
@ -989,12 +1000,15 @@ class Form
$opt.= ' style="background-color:#FF0000; color:#F5F5F5;"';
}
}
$opt.= '>'.$objp->ref.' - ';
$opt.= dol_trunc($label,32).' - ';
$opt.= '>';
$opt.= $langs->convToOutputCharset($objp->ref).' - '.$langs->convToOutputCharset(dol_trunc($label,32)).' - ';
$outval.=$objp->ref.' - '.dol_trunc($label,32).' - ';
$found=0;
$currencytext=$langs->trans("Currency".$conf->monnaie);
$currencytextnoent=$langs->transnoentities("Currency".$conf->monnaie);
if (strlen($currencytext) > 10) $currencytext=$conf->monnaie; // If text is too long, we use the short code
if (strlen($currencytextnoent) > 10) $currencytextnoent=$conf->monnaie; // If text is too long, we use the short code
// Multiprice
if ($price_level >= 1) // If we need a particular price level (from 1 to 6)
@ -1015,9 +1029,15 @@ class Form
{
$found=1;
if ($objp2->price_base_type == 'HT')
$opt.= price($objp2->price,1).' '.$currencytext.' '.$langs->trans("HT");
{
$opt.= price($objp2->price,1).' '.$currencytext.' '.$langs->trans("HT");
$outval.= price($objp2->price,1).' '.$currencytextnoent.' '.$langs->transnoentities("HT");
}
else
$opt.= price($objp2->price_ttc,1).' '.$currencytext.' '.$langs->trans("TTC");
{
$opt.= price($objp2->price_ttc,1).' '.$currencytext.' '.$langs->trans("TTC");
$outval.= price($objp2->price_ttc,1).' '.$currencytextnoent.' '.$langs->transnoentities("TTC");
}
}
}
else
@ -1030,14 +1050,21 @@ class Form
if (! $found)
{
if ($objp->price_base_type == 'HT')
$opt.= price($objp->price,1).' '.$currencytext.' '.$langs->trans("HT");
{
$opt.= price($objp->price,1).' '.$currencytext.' '.$langs->trans("HT");
$outval.= price($objp->price,1).' '.$currencytextnoent.' '.$langs->transnoentities("HT");
}
else
$opt.= price($objp->price_ttc,1).' '.$currencytext.' '.$langs->trans("TTC");
{
$opt.= price($objp->price_ttc,1).' '.$currencytext.' '.$langs->trans("TTC");
$outval.= price($objp->price_ttc,1).' '.$currencytextnoent.' '.$langs->transnoentities("TTC");
}
}
if ($conf->stock->enabled && isset($objp->stock) && $objp->fk_product_type == 0)
{
$opt.= ' - '.$langs->trans("Stock").':'.$objp->stock;
$outval.=' - '.$langs->transnoentities("Stock").':'.$objp->stock;
}
if ($objp->duration)
@ -1053,10 +1080,17 @@ class Form
$dur=array("h"=>$langs->trans("Hour"),"d"=>$langs->trans("Day"),"w"=>$langs->trans("Week"),"m"=>$langs->trans("Month"),"y"=>$langs->trans("Year"));
}
$opt.= ' - '.$duration_value.' '.$langs->trans($dur[$duration_unit]);
$outval.=' - '.$duration_value.' '.$langs->transnoentities($dur[$duration_unit]);
}
$opt.= "</option>\n";
// Add new entry
// "key" value of json key array is used by jQuery automatically as selected value
// "label" value of json key array is used by jQuery automatically as text for combo box
$outselect.=$opt;
array_push($outjson,array('key'=>$outkey,'value'=>$outref,'label'=>$outval));
$i++;
}
@ -1064,7 +1098,8 @@ class Form
$this->db->free($result);
print $outselect;
if (empty($disableout)) print $outselect;
return $outjson;
}
else
{
@ -1085,12 +1120,25 @@ class Form
global $langs,$conf;
if ($conf->global->PRODUIT_USE_SEARCH_TO_SELECT)
{
print $langs->trans("RefOrLabel").' : <input type="text" size="16" name="keysearch'.$htmlname.'" id="keysearch'.$htmlname.'">';
print ajax_updater($htmlname,'keysearch',DOL_URL_ROOT.'/product/ajaxproducts.php','&socid='.$socid.'&type='.$filtertype.'&mode=2','working');
if ($conf->global->MAIN_USE_NEW_JQUERY)
{
// mode=2 means suppliers products
print ajax_autocompleter2('',$htmlname,DOL_URL_ROOT.'/product/ajaxproducts.php','outjson=1&price_level='.$price_level.'&type='.$filtertype.'&mode=2&status='.$status.'&finished='.$finished,'');
print '<div class="ui-widget">';
print '<label for="'.$htmlname.'free">'.$langs->trans("RefOrLabel").':</label>';
print '<input id="'.$htmlname.'free" />';
print '</div>';
}
else
{
print $langs->trans("RefOrLabel").' : <input type="text" size="16" name="keysearch'.$htmlname.'" id="keysearch'.$htmlname.'">';
print ajax_updater($htmlname,'keysearch',DOL_URL_ROOT.'/product/ajaxproducts.php','&socid='.$socid.'&type='.$filtertype.'&mode=2','working');
}
}
else
{
$this->select_produits_fournisseurs_do($socid,$selected,$htmlname,$filtertype,$filtre,'');
$this->select_produits_fournisseurs_do($socid,$selected,$htmlname,$filtertype,$filtre,'',-1,0);
}
}
@ -1101,9 +1149,12 @@ class Form
* \param htmlname Nom de la zone select
* \param filtertype Filter on product type (''=nofilter, 0=product, 1=service)
* \param filtre Pour filtre sql
* \param filterkey Filtre des produits si ajax est utilise
* \param filterkey Filtre des produits
* \param status -1=Return all products, 0=Products not on sell, 1=Products on sell
* \param disableout Disable print output
* \return array Array of keys for json
*/
function select_produits_fournisseurs_do($socid,$selected='',$htmlname='productid',$filtertype='',$filtre='',$filterkey='')
function select_produits_fournisseurs_do($socid,$selected='',$htmlname='productid',$filtertype='',$filtre='',$filterkey='',$statut=-1,$disableout=0)
{
global $langs,$conf;
@ -1135,7 +1186,7 @@ class Form
// Build output string
$outselect='';
$outjson='';
$outjson=array();
dol_syslog("Form::select_produits_fournisseurs_do sql=".$sql,LOG_DEBUG);
$result=$this->db->query($sql);
@ -1168,44 +1219,72 @@ class Form
$i = 0;
while ($i < $num)
{
$outkey='';
$outval='';
$outref='';
$objp = $this->db->fetch_object($result);
$outkey=$objp->idprodfournprice;
$outref=$objp->ref;
$opt = '<option value="'.$objp->idprodfournprice.'"';
if ($selected == $objp->idprodfournprice) $opt.= ' selected="true"';
if ($objp->fprice == '') $opt.=' disabled="disabled"';
$opt.= '>'.$objp->ref.' ('.$objp->ref_fourn.') - ';
$opt.= dol_trunc($objp->label,18).' - ';
$opt.= '>';
$opt.=$langs->convToOutputCharset($objp->ref).' ('.$langs->convToOutputCharset($objp->ref_fourn).') - ';
$outval.=$objp->ref.' ('.$objp->ref_fourn.') - ';
$opt.=$langs->convToOutputCharset(dol_trunc($objp->label,18)).' - ';
$outval.=dol_trunc($objp->label,18).' - ';
if ($objp->fprice != '') // Keep != ''
{
$currencytext=$langs->trans("Currency".$conf->monnaie);
if (strlen($currencytext) > 10) $currencytext=$conf->monnaie; // If text is too long, we use the short code
$currencytextnoent=$langs->transnoentities("Currency".$conf->monnaie);
if (strlen($currencytext) > 10) $currencytext=$conf->monnaie; // If text is too long, we use the short code
if (strlen($currencytextnoent) > 10) $currencytextnoent=$conf->monnaie; // If text is too long, we use the short code
$opt.= price($objp->fprice);
$opt.= ' '.$currencytext."/".$objp->quantity;
$opt.= price($objp->fprice).' '.$currencytext."/".$objp->quantity;
$outval.= price($objp->fprice).' '.$currencytextnoent."/".$objp->quantity;
if ($objp->quantity == 1)
{
$opt.= strtolower($langs->trans("Unit"));
$outval.=strtolower($langs->transnoentities("Unit"));
}
else
{
$opt.= strtolower($langs->trans("Units"));
$outval.=strtolower($langs->transnoentities("Units"));
}
if ($objp->quantity >= 1)
{
$opt.=" (";
$opt.= price($objp->unitprice).' '.$currencytext."/".strtolower($langs->trans("Unit"));
$opt.=")";
$opt.=" (".price($objp->unitprice).' '.$currencytext."/".strtolower($langs->trans("Unit")).")";
$outval.=" (".price($objp->unitprice).' '.$currencytextnoent."/".strtolower($langs->transnoentities("Unit")).")";
}
if ($objp->duration)
{
$opt .= " - ".$objp->duration;
$outval.=" - ".$objp->duration;
}
if (! $socid)
{
$opt .= " - ".dol_trunc($objp->nom,8);
$outval.=" - ".dol_trunc($objp->nom,8);
}
if ($objp->duration) $opt .= " - ".$objp->duration;
if (! $socid) $opt .= " - ".dol_trunc($objp->nom,8);
}
else
{
$opt.= $langs->trans("NoPriceDefinedForThisSupplier");
$outval.=$langs->transnoentities("NoPriceDefinedForThisSupplier");
}
$opt .= "</option>\n";
// Add new entry
// "key" value of json key array is used by jQuery automatically as selected value
// "label" value of json key array is used by jQuery automatically as text for combo box
$outselect.=$opt;
array_push($outjson,array('key'=>$outkey,'value'=>$outref,'label'=>$outval));
$i++;
}
@ -1213,7 +1292,8 @@ class Form
$this->db->free($result);
print $outselect;
if (empty($disableout)) print $outselect;
return $outjson;
}
else
{

View File

@ -156,23 +156,22 @@ function ajax_autocompleter($selected='',$htmlname,$url,$indicator='working')
*/
function ajax_autocompleter2($selected='', $htmlname, $url, $option='')
{
$script = '<input type="hidden" name="'.$htmlname.'_id" id="'.$htmlname.'_id" value="'.$selected.'" />';
$script = '<input type="hidden" name="'.$htmlname.'" id="'.$htmlname.'" value="'.$selected.'" />';
$script.= '<script type="text/javascript">';
$script.= 'jQuery(function() {
jQuery("input#'.$htmlname.'").autocomplete({
jQuery("input#'.$htmlname.'free").autocomplete({
source: "'.$url.($option?'?'.$option:'').'",
delay: 300,
minLength: 1,
select: function(event, ui) {
alert(\'ee\');
jQuery("#state_id").val(ui.item.id);
}
/* jQuery("#'.$htmlname.'free") is automatically affected with ui.item.key */
/* jQuery("#'.$htmlname.'free").val(ui.item.fulltext); */
jQuery("#'.$htmlname.'").val(ui.item.key);
/* alert(ui.item.key); */
}
});
});';
// source: ["c++", "java", "php", "coldfusion", "javascript", "asp", "ruby"],
$script.= '</script>';
return $script;

View File

@ -777,7 +777,14 @@ function top_htmlhead($head, $title='', $disablejs=0, $disablehead=0, $arrayofjs
else print "<title>".$appli."</title>";
print "\n";
// Output style sheets (optioncss='print' or '')
if (! defined('DISABLE_JQUERY'))
{
print '<!-- Includes for JQuery (Ajax library) -->'."\n";
print '<link rel="stylesheet" href="'.DOL_URL_ROOT.'/includes/jquery/css/smoothness/jquery-ui-1.8.4.custom.css" type="text/css" />'."\n";
}
print '<!-- Includes for Dolibarr, modules or specific pages-->'."\n";
// Output style sheets (optioncss='print' or '')
print '<link rel="stylesheet" type="text/css" title="default" href="'.DOL_URL_ROOT.$conf->css.'?lang='.$langs->defaultlang.(! empty($_GET["optioncss"])?'&optioncss='.$_GET["optioncss"]:'').'">'."\n";
// CSS forced by modules (relative url starting with /)
if (is_array($conf->css_modules))
@ -796,12 +803,6 @@ function top_htmlhead($head, $title='', $disablejs=0, $disablehead=0, $arrayofjs
}
}
if (! defined('DISABLE_JQUERY'))
{
print '<!-- Includes for JQuery (Ajax library) -->'."\n";
print '<link rel="stylesheet" href="'.DOL_URL_ROOT.'/includes/jquery/css/smoothness/jquery-ui-1.8.4.custom.css" type="text/css" />'."\n";
}
if (empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) print '<link rel="top" title="'.$langs->trans("Home").'" href="'.(DOL_URL_ROOT?DOL_URL_ROOT:'/').'">'."\n";
if (empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) print '<link rel="copyright" title="GNU General Public License" href="http://www.gnu.org/copyleft/gpl.html#SEC1">'."\n";
if (empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) print '<link rel="author" title="Dolibarr Development Team" href="http://www.dolibarr.org">'."\n";

View File

@ -55,40 +55,32 @@ $langs->load("main");
dol_syslog(join(',',$_POST));
// Generation liste de produits
if (! empty($_GET['keysearch']) || ! empty($_GET['term']))
if (! isset($_GET['keysearch']) && ! isset($_GET['term'])) return;
// When used from jQuery, the search term is added as GET param "term".
$searchkey=isset($_GET['keysearch'])?$_GET['keysearch']:$_GET['term'];
$outjson=isset($_GET['outjson'])?$_GET['outjson']:0;
// Get list of product.
//var_dump($_GET); exit;
//print $_GET["price_level"]; exit;
$status=-1;
if (isset($_GET['status'])) $status=$_GET['status'];
$form = new Form($db);
if (empty($_GET['mode']) || $_GET['mode'] == 1)
{
//var_dump($_GET); exit;
//print $_GET["price_level"]; exit;
$status=-1;
if (isset($_GET['status'])) $status=$_GET['status'];
$form = new Form($db);
if (empty($_GET['mode']) || $_GET['mode'] == 1)
{
$form->select_produits_do("",$_GET["htmlname"],$_GET["type"],"",$_GET["price_level"],$_GET["keysearch"],$status);
}
if ($_GET['mode'] == 2)
{
$form->select_produits_fournisseurs_do($_GET["socid"],"",$_GET["htmlname"],$_GET["type"],"",$_GET["keysearch"]);
}
$arrayresult=$form->select_produits_do("",$_GET["htmlname"],$_GET["type"],"",$_GET["price_level"],$searchkey,$status,2,$outjson);
}
else if (! empty($_GET['markup']))
if ($_GET['mode'] == 2)
{
print $_GET['markup'];
//print $_GET['count'];
//$field = "<input size='10' type='text' class='flat' id='sellingdata_ht".$_GET['count']."' name='sellingdata_ht".$_GET['count']."' value='".$_GET['markup']."'>";
//print '<input size="10" type="text" class="flat" id="sellingdata_ht'.$_GET['count'].'" name="sellingdata_ht'.$_GET['count'].'" value="'.$field.'">';
//print $field;
}
else if (! empty($_GET['selling']))
{
//print $_GET['markup'];
//print $_GET['count'];
print '<input size="10" type="text" class="flat" name="cashflow'.$_GET['count'].'" value="'.$_GET['selling'].'">';
$arrayresult=$form->select_produits_fournisseurs_do($_GET["socid"],"",$_GET["htmlname"],$_GET["type"],"",$searchkey,$statut,$outjson);
}
$db->close();
if ($outjson) print json_encode($arrayresult);
//print "</body>";
//print "</html>";
?>

View File

@ -1593,3 +1593,16 @@ A.none, A.none:active, A.none:visited, A.none:hover {
padding : 0px;
margin : 0px;
}
/* Style to overwrites JQuery styles */
.ui-menu .ui-menu-item a {
text-decoration:none;
display:block;
padding:.2em .4em;
line-height:1.5;
zoom:1;
font-weight: normal;
font-family:Verdana,Arial,sans-serif;
font-size:1em;
}

View File

@ -1560,3 +1560,18 @@ A.none, A.none:active, A.none:visited, A.none:hover {
padding : 0px;
margin : 0px;
}
/* Style to overwrites JQuery styles */
.ui-menu .ui-menu-item a {
text-decoration:none;
display:block;
padding:.2em .4em;
line-height:1.5;
zoom:1;
font-weight: normal;
font-family:Verdana,Arial,sans-serif;
font-size:1em;
}

View File

@ -1196,3 +1196,16 @@ A.none, A.none:active, A.none:visited, A.none:hover {
margin : 0px;
}
/* Style to overwrites JQuery styles */
.ui-menu .ui-menu-item a {
text-decoration:none;
display:block;
padding:.2em .4em;
line-height:1.5;
zoom:1;
font-weight: normal;
font-family:Verdana,Arial,sans-serif;
font-size:1em;
}

View File

@ -1256,3 +1256,17 @@ A.none, A.none:active, A.none:visited, A.none:hover {
padding : 0px;
margin : 0px;
}
/* Style to overwrites JQuery styles */
.ui-menu .ui-menu-item a {
text-decoration:none;
display:block;
padding:.2em .4em;
line-height:1.5;
zoom:1;
font-weight: normal;
font-family:Verdana,Arial,sans-serif;
font-size:1em;
}