Fix: add compatibility with old static combobox

This commit is contained in:
Regis Houssin 2012-08-27 17:18:46 +02:00
parent 426b3c2627
commit 07a10d3984
3 changed files with 166 additions and 36 deletions

View File

@ -2444,6 +2444,48 @@ abstract class CommonObject
/* This is to show add lines */
/**
* Show add predefined products/services form
* TODO Edit templates to use global variables and include them directly in controller call
* But for the moment we don't know if it's possible as we keep a method available on overloaded objects.
*
* @param int $dateSelector 1=Show also date range input fields
* @param Societe $seller Object thirdparty who sell
* @param Societe $buyer Object thirdparty who buy
* @param HookManager $hookmanager Hook manager instance
* @return void
* @deprecated
*/
function formAddPredefinedProduct($dateSelector,$seller,$buyer,$hookmanager=false)
{
global $conf,$langs,$object;
global $form,$bcnd,$var;
// Use global variables + $dateSelector + $seller and $buyer
include(DOL_DOCUMENT_ROOT.'/core/tpl/predefinedproductline_create.tpl.php');
}
/**
* Show add free products/services form
* TODO Edit templates to use global variables and include them directly in controller call
* But for the moment we don't know if it'st possible as we keep a method available on overloaded objects.
*
* @param int $dateSelector 1=Show also date range input fields
* @param Societe $seller Object thirdparty who sell
* @param Societe $buyer Object thirdparty who buy
* @param HookManager $hookmanager Hook manager instance
* @return void
* @deprecated
*/
function formAddFreeProduct($dateSelector,$seller,$buyer,$hookmanager=false)
{
global $conf,$langs,$object;
global $form,$bcnd,$var;
// Use global variables + $dateSelector + $seller and $buyer
include(DOL_DOCUMENT_ROOT.'/core/tpl/freeproductline_create.tpl.php');
}
/**
* Show add free and predefined products/services form

View File

@ -218,7 +218,7 @@ $(document).ready(function() {
$('#service_duration_area').hide();
$('#idprod').change(function() {
if ($(this).val().length > 0) {
if ($(this).val() > 0) {
if (typeof CKEDITOR == 'object' && typeof CKEDITOR.instances != 'undefined' && CKEDITOR.instances['product_desc'] != 'undefined') {
// We use CKEditor
CKEDITOR.instances['product_desc'].focus();
@ -226,9 +226,46 @@ $(document).ready(function() {
// We use a simple textarea
$('#product_desc').focus();
}
// For compatibility with combobox
<?php if (empty($conf->global->PRODUIT_USE_SEARCH_TO_SELECT)) { ?>
$.post('<?php echo DOL_URL_ROOT; ?>/product/ajax/products.php', {
'action': 'fetch',
'id': $(this).val(),
'price_level': <?php echo $buyer->price_level; ?>
},
function(data) {
if (typeof data != 'undefined') {
$('#select_type').val(data.type).attr('disabled','disabled');
$('#product_ref').val(data.ref);
$('#product_label').val(data.label).attr('disabled','disabled');
$('#origin_label_cache').val(data.label);
$('#origin_desc_cache').val(data.desc);
$('#price_base_type').val(data.pricebasetype);
$('#price_ht').val(data.price_ht).attr('disabled','disabled');
$('#origin_price_ht_cache').val(data.price_ht);
$('#update_label_area').show().trigger('show');
$('#update_desc_area').show().trigger('show');
$('#update_price_area').show().trigger('show');
}
}, 'json');
<?php } ?>
} else {
$('#update_desc_checkbox').removeAttr('checked').trigger('change');
$('#update_price_checkbox').removeAttr('checked').trigger('change');
// For compatibility with combobox
<?php if (empty($conf->global->PRODUIT_USE_SEARCH_TO_SELECT)) { ?>
$('#select_type').val('').removeAttr('disabled');
$('#product_ref').val('');
$('#product_label').val('').removeAttr('disabled');
$('#origin_label_cache').val('');
$('#origin_desc_cache').val('');
$('#price_base_type').val('');
$('#price_ht').val('').removeAttr('disabled');
$('#origin_price_ht_cache').val('');
$('#update_label_area').hide().trigger('hide');
$('#update_desc_area').hide().trigger('hide');
$('#update_price_area').hide().trigger('hide');
<?php } ?>
}
});

View File

@ -31,10 +31,6 @@ if (! defined('NOCSRFCHECK')) define('NOCSRFCHECK','1');
if (empty($_GET['keysearch']) && ! defined('NOREQUIREHTML')) define('NOREQUIREHTML','1');
require '../../main.inc.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';
$langs->load("products");
$langs->load("main");
$htmlname=GETPOST('htmlname','alpha');
$socid=GETPOST('socid','int');
@ -43,50 +39,105 @@ $mode=GETPOST('mode','int');
$status=((GETPOST('status','int') >= 0) ? GETPOST('status','int') : -1);
$outjson=(GETPOST('outjson','int') ? GETPOST('outjson','int') : 0);
$pricelevel=GETPOST('price_level','int');
$action=GETPOST('action', 'alpha');
$id=GETPOST('id', 'int');
/*
* View
*/
// Ajout directives pour resoudre bug IE
//header('Cache-Control: Public, must-revalidate');
//header('Pragma: public');
//top_htmlhead("", "", 1); // Replaced with top_httphead. An ajax page does not need html header.
top_httphead();
//print '<!-- Ajax page called with url '.$_SERVER["PHP_SELF"].'?'.$_SERVER["QUERY_STRING"].' -->'."\n";
//print '<body class="nocellnopadd">'."\n";
dol_syslog(join(',',$_GET));
//print_r($_GET);
if (empty($htmlname)) return;
$match = preg_grep('/('.$htmlname.'[0-9]+)/',array_keys($_GET));
sort($match);
$idprod = (! empty($match[0]) ? $match[0] : '');
if (! GETPOST($htmlname) && ! GETPOST($idprod)) return;
// When used from jQuery, the search term is added as GET param "term".
$searchkey=(GETPOST($idprod)?GETPOST($idprod):(GETPOST($htmlname)?GETPOST($htmlname):''));
$form = new Form($db);
if (empty($mode) || $mode == 1)
if (! empty($action) && $action == 'fetch' && ! empty($id))
{
$arrayresult=$form->select_produits_do("",$htmlname,$type,"",$pricelevel,$searchkey,$status,2,$outjson);
require DOL_DOCUMENT_ROOT . '/product/class/product.class.php';
$outjson=array();
$object = new Product($db);
$ret=$object->fetch($id);
if ($ret > 0)
{
$outref=$object->ref;
$outlabel=$object->label;
$outdesc=$object->description;
$outtype=$object->type;
$found=false;
// Multiprice
if ($price_level >= 1) // If we need a particular price level (from 1 to 6)
{
$sql= "SELECT price, price_ttc, price_base_type ";
$sql.= "FROM ".MAIN_DB_PREFIX."product_price ";
$sql.= "WHERE fk_product='".$id."'";
$sql.= " AND price_level=".$price_level;
$sql.= " ORDER BY date_price";
$sql.= " DESC LIMIT 1";
$result = $this->db->query($sql);
if ($result)
{
$objp = $this->db->fetch_object($result);
if ($objp)
{
$found=true;
$outprice_ht=price($objp->price);
$outprice_ttc=price($objp->price_ttc);
$outpricebasetype=$objp->price_base_type;
}
}
}
if (! $found)
{
$outprice_ht=price($object->price);
$outprice_ttc=price($object->price_ttc);
$outpricebasetype=$object->price_base_type;
}
$outjson = array('ref'=>$outref, 'label'=>$outlabel, 'desc'=>$outdesc, 'type'=>$outtype, 'price_ht'=>$outprice_ht, 'price_ttc'=>$outprice_ttc, 'pricebasetype'=>$outpricebasetype);
}
echo json_encode($outjson);
}
elseif ($mode == 2)
else
{
$arrayresult=$form->select_produits_fournisseurs_do($socid,"",$htmlname,$type,"",$searchkey,$status,$outjson);
require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';
$langs->load("products");
$langs->load("main");
top_httphead();
if (empty($htmlname)) return;
$match = preg_grep('/('.$htmlname.'[0-9]+)/',array_keys($_GET));
sort($match);
$idprod = (! empty($match[0]) ? $match[0] : '');
if (! GETPOST($htmlname) && ! GETPOST($idprod)) return;
// When used from jQuery, the search term is added as GET param "term".
$searchkey=(GETPOST($idprod)?GETPOST($idprod):(GETPOST($htmlname)?GETPOST($htmlname):''));
$form = new Form($db);
if (empty($mode) || $mode == 1)
{
$arrayresult=$form->select_produits_do("",$htmlname,$type,"",$pricelevel,$searchkey,$status,2,$outjson);
}
elseif ($mode == 2)
{
$arrayresult=$form->select_produits_fournisseurs_do($socid,"",$htmlname,$type,"",$searchkey,$status,$outjson);
}
$db->close();
if ($outjson) print json_encode($arrayresult);
}
$db->close();
if ($outjson) print json_encode($arrayresult);
//print "</body>";
//print "</html>";
?>