From 629f782f17f6462f27e6c435de1db9332d37a872 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 22 Aug 2010 18:02:32 +0000 Subject: [PATCH] Usage of autocomplete using jquery now works for products. --- htdocs/core/class/html.form.class.php | 144 ++++++++++++++++++++------ htdocs/lib/ajax.lib.php | 15 ++- htdocs/main.inc.php | 15 +-- htdocs/product/ajaxproducts.php | 46 ++++---- htdocs/theme/auguria/style.css.php | 13 +++ htdocs/theme/eldy/style.css.php | 15 +++ htdocs/theme/freelug/style.css.php | 13 +++ htdocs/theme/yellow/style.css.php | 14 +++ 8 files changed, 201 insertions(+), 74 deletions(-) diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index a6147a78791..45c2f47fffc 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -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 '
'; - print ''; - print ''; + print ''; + print ''; print '
'; } 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.=''; - 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 '
'; + print ''; + print ''; + print '
'; + } + else + { + print $langs->trans("RefOrLabel").' : '; + 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 = '\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 { diff --git a/htdocs/lib/ajax.lib.php b/htdocs/lib/ajax.lib.php index 9c8b254bcef..e49af4db173 100644 --- a/htdocs/lib/ajax.lib.php +++ b/htdocs/lib/ajax.lib.php @@ -156,23 +156,22 @@ function ajax_autocompleter($selected='',$htmlname,$url,$indicator='working') */ function ajax_autocompleter2($selected='', $htmlname, $url, $option='') { - $script = ''; + $script = ''; $script.= ''; return $script; diff --git a/htdocs/main.inc.php b/htdocs/main.inc.php index b43baeaa292..f6a11acb930 100644 --- a/htdocs/main.inc.php +++ b/htdocs/main.inc.php @@ -777,7 +777,14 @@ function top_htmlhead($head, $title='', $disablejs=0, $disablehead=0, $arrayofjs else print "".$appli.""; print "\n"; - // Output style sheets (optioncss='print' or '') + if (! defined('DISABLE_JQUERY')) + { + print ''."\n"; + print ''."\n"; + } + + print ''."\n"; + // Output style sheets (optioncss='print' or '') print ''."\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 ''."\n"; - print ''."\n"; - } - if (empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) print ''."\n"; if (empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) print ''."\n"; if (empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) print ''."\n"; diff --git a/htdocs/product/ajaxproducts.php b/htdocs/product/ajaxproducts.php index 937053187c8..db7697c05e2 100644 --- a/htdocs/product/ajaxproducts.php +++ b/htdocs/product/ajaxproducts.php @@ -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 = ""; - //print ''; - //print $field; -} -else if (! empty($_GET['selling'])) -{ - //print $_GET['markup']; - //print $_GET['count']; - print ''; + $arrayresult=$form->select_produits_fournisseurs_do($_GET["socid"],"",$_GET["htmlname"],$_GET["type"],"",$searchkey,$statut,$outjson); } $db->close(); +if ($outjson) print json_encode($arrayresult); + //print ""; //print ""; ?> diff --git a/htdocs/theme/auguria/style.css.php b/htdocs/theme/auguria/style.css.php index d150740713a..f3fa90937ed 100644 --- a/htdocs/theme/auguria/style.css.php +++ b/htdocs/theme/auguria/style.css.php @@ -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; +} diff --git a/htdocs/theme/eldy/style.css.php b/htdocs/theme/eldy/style.css.php index 5e3a20b712d..bee23a175c6 100644 --- a/htdocs/theme/eldy/style.css.php +++ b/htdocs/theme/eldy/style.css.php @@ -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; +} + + diff --git a/htdocs/theme/freelug/style.css.php b/htdocs/theme/freelug/style.css.php index cc2b1e7c4ff..ebf5e347725 100644 --- a/htdocs/theme/freelug/style.css.php +++ b/htdocs/theme/freelug/style.css.php @@ -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; +} + diff --git a/htdocs/theme/yellow/style.css.php b/htdocs/theme/yellow/style.css.php index eceea286e6b..b4f7ff434b9 100644 --- a/htdocs/theme/yellow/style.css.php +++ b/htdocs/theme/yellow/style.css.php @@ -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; +}