Fix: compatibility with edit in place

Qual: use generic function and remove unused
Todo: Type of product combobox is not compatible with edit in place
This commit is contained in:
Regis Houssin 2012-03-04 09:43:56 +01:00
parent 00b7ad4a78
commit 68ce569d05
5 changed files with 27 additions and 108 deletions

View File

@ -62,6 +62,7 @@ if((isset($_GET['field']) && ! empty($_GET['field']))
if ($element == 'propal') $element = 'propale'; if ($element == 'propal') $element = 'propale';
else if ($element == 'fichinter') $element = 'ficheinter'; else if ($element == 'fichinter') $element = 'ficheinter';
else if ($element == 'product') $element = 'produit';
else if ($element == 'order_supplier') { else if ($element == 'order_supplier') {
$element = 'fournisseur'; $element = 'fournisseur';
$subelement = 'commande'; $subelement = 'commande';

View File

@ -69,6 +69,7 @@ if((isset($_POST['field']) && ! empty($_POST['field']))
if ($element == 'propal') $element = 'propale'; if ($element == 'propal') $element = 'propale';
else if ($element == 'fichinter') $element = 'ficheinter'; else if ($element == 'fichinter') $element = 'ficheinter';
else if ($element == 'product') $element = 'produit';
else if ($element == 'order_supplier') { else if ($element == 'order_supplier') {
$element = 'fournisseur'; $element = 'fournisseur';
$subelement = 'commande'; $subelement = 'commande';

View File

@ -81,7 +81,8 @@ class Form
$ret=''; $ret='';
if (! empty($conf->global->MAIN_USE_JQUERY_JEDITABLE)) // TODO change for compatibility
if (! empty($conf->global->MAIN_USE_JQUERY_JEDITABLE) && ! preg_match('/^select;/',$typeofdata))
{ {
if ($perm) if ($perm)
{ {
@ -128,7 +129,8 @@ class Form
$ret=''; $ret='';
// When option to edit inline is activated // When option to edit inline is activated
if (! empty($conf->global->MAIN_USE_JQUERY_JEDITABLE)) // TODO change for compatibility
if (! empty($conf->global->MAIN_USE_JQUERY_JEDITABLE) && ! preg_match('/^select;/',$typeofdata))
{ {
$ret.=$this->editInPlace($object, $value, $htmlname, $perm, $typeofdata, $editvalue, $extObject, $success); $ret.=$this->editInPlace($object, $value, $htmlname, $perm, $typeofdata, $editvalue, $extObject, $success);
} }

View File

@ -2813,85 +2813,6 @@ class Product extends CommonObject
} }
} }
/**
* Update product/service type
*
* @param User $user Utilisateur qui fait la modification
* @return void
* TODO Replace this by a method update_field into common
*/
function update_type($user)
{
$sql = "UPDATE ".MAIN_DB_PREFIX."product";
$sql.= " SET fk_product_type = '".$this->type."'";
$sql.= " WHERE rowid = ".$this->id;
dol_syslog(get_class($this)."::update_type sql=".$sql);
$resql=$this->db->query($sql);
if ($resql)
{
return 1;
}
else
{
dol_print_error($this->db);
return -1;
}
}
/**
* Mise a jour du code barre
*
* @param User $user Utilisateur qui fait la modification
* @return void
* TODO Replace this by a method update_field into common
*/
function update_barcode($user)
{
$sql = "UPDATE ".MAIN_DB_PREFIX."product";
$sql.= " SET barcode = '".$this->barcode."'";
$sql.= " WHERE rowid = ".$this->id;
dol_syslog(get_class($this)."::update_barcode sql=".$sql);
$resql=$this->db->query($sql);
if ($resql)
{
return 1;
}
else
{
dol_print_error($this->db);
return -1;
}
}
/**
* Mise a jour du type de code barre
*
* @param User $user Utilisateur qui fait la modification
* @return void
* TODO Replace this by a method update_field into common
*/
function update_barcode_type($user)
{
$sql = "UPDATE ".MAIN_DB_PREFIX."product";
$sql.= " SET fk_barcode_type = '".$this->barcode_type."'";
$sql.= " WHERE rowid = ".$this->id;
dol_syslog(get_class($this)."::update_barcode_type sql=".$sql);
$resql=$this->db->query($sql);
if ($resql)
{
return 1;
}
else
{
dol_print_error($this->db);
return -1;
}
}
/** /**
* Return if object is a product * Return if object is a product
* *

View File

@ -88,12 +88,10 @@ $error=$hookmanager->error; $errors=$hookmanager->errors;
if (empty($reshook)) if (empty($reshook))
{ {
// Type // Type
if ($action == 'setproducttype' && $user->rights->produit->creer) if ($action == 'setfk_product_type' && $user->rights->produit->creer)
{ {
var_dump($action);
$object->fetch($id); $object->fetch($id);
$object->type = $_POST['producttype']; $result = $object->setValueFrom('fk_product_type', $_POST['fk_product_type']);
$result = $object->update_type($user);
Header("Location: ".$_SERVER['PHP_SELF']."?id=".$id); Header("Location: ".$_SERVER['PHP_SELF']."?id=".$id);
exit; exit;
} }
@ -102,8 +100,7 @@ if (empty($reshook))
if ($action == 'setbarcodetype' && $user->rights->barcode->creer) if ($action == 'setbarcodetype' && $user->rights->barcode->creer)
{ {
$object->fetch($id); $object->fetch($id);
$object->barcode_type = $_POST['barcodetype_id']; $result = $object->setValueFrom('fk_barcode_type', $_POST['barcodetype_id']);
$result = $object->update_barcode_type($user);
Header("Location: ".$_SERVER['PHP_SELF']."?id=".$id); Header("Location: ".$_SERVER['PHP_SELF']."?id=".$id);
exit; exit;
} }
@ -112,18 +109,16 @@ if (empty($reshook))
if ($action == 'setbarcode' && $user->rights->barcode->creer) if ($action == 'setbarcode' && $user->rights->barcode->creer)
{ {
$object->fetch($id); $object->fetch($id);
$object->barcode = $_POST['barcode']; //Todo: ajout verification de la validite du code barre en fonction du type //Todo: ajout verification de la validite du code barre en fonction du type
$result = $object->update_barcode($user); $result = $object->setValueFrom('barcode', $_POST['barcode']);
Header("Location: ".$_SERVER['PHP_SELF']."?id=".$id); Header("Location: ".$_SERVER['PHP_SELF']."?id=".$id);
exit; exit;
} }
if ($action == 'setproductaccountancycodebuy') if ($action == 'setaccountancy_code_buy')
{ {
$product = new Product($db); $object->fetch($id,$ref);
$result=$product->fetch($id,$ref); $result = $object->setValueFrom('accountancy_code_buy', $_POST['productaccountancycodebuy']);
$product->accountancy_code_buy=$_POST["productaccountancycodebuy"];
$result=$product->update($product->id,$user,1,0,1);
if ($result < 0) if ($result < 0)
{ {
$mesg=join(',',$product->errors); $mesg=join(',',$product->errors);
@ -131,12 +126,12 @@ if (empty($reshook))
$action=""; $action="";
} }
if ($action == 'setproductaccountancycodesell') if ($action == 'setaccountancy_code_buy')
{ {
$product = new Product($db); $object->fetch($id,$ref);
$result=$product->fetch($id,$ref);
$product->accountancy_code_sell=$_POST["productaccountancycodesell"]; $product->accountancy_code_sell=$_POST["productaccountancycodesell"];
$result=$product->update($product->id,$user,1,0,1); $result=$product->update($product->id,$user,1,0,1);
$result = $object->setValueFrom('accountancy_code_sell', $_POST['productaccountancycodesell']);
if ($result < 0) if ($result < 0)
{ {
$mesg=join(',',$product->errors); $mesg=join(',',$product->errors);
@ -1092,9 +1087,10 @@ else
// Type // Type
if ($conf->produit->enabled && $conf->service->enabled) if ($conf->produit->enabled && $conf->service->enabled)
{ {
$typeformat='select;0:'.$langs->trans("Product").',1:'.$langs->trans("Service"); // TODO change for compatibility with edit in place
print '<tr><td>'.$form->editfieldkey("Type",'producttype',$object->type,$object,$user->rights->produit->creer|$user->rights->service->creer,$typeformat).'</td><td colspan="2">'; $typeformat='select;0:'.$langs->trans("Product").',1:'.$langs->trans("Service");
print $form->editfieldval("Type",'producttype',$object->type,$object,$user->rights->produit->creer|$user->rights->service->creer,$typeformat); print '<tr><td>'.$form->editfieldkey("Type",'fk_product_type',$object->type,$object,$user->rights->produit->creer||$user->rights->service->creer,$typeformat).'</td><td colspan="2">';
print $form->editfieldval("Type",'fk_product_type',$object->type,$object,$user->rights->produit->creer||$user->rights->service->creer,$typeformat);
print '</td></tr>'; print '</td></tr>';
} }
@ -1145,13 +1141,13 @@ else
} }
// Accountancy sell code // Accountancy sell code
print '<tr><td>'.$form->editfieldkey("ProductAccountancySellCode",'productaccountancycodesell',$object->accountancy_code_sell,$object,$user->rights->produit->creer|$user->rights->service->creer).'</td><td colspan="2">'; print '<tr><td>'.$form->editfieldkey("ProductAccountancySellCode",'accountancy_code_sell',$object->accountancy_code_sell,$object,$user->rights->produit->creer||$user->rights->service->creer).'</td><td colspan="2">';
print $form->editfieldval("ProductAccountancySellCode",'productaccountancycodesell',$object->accountancy_code_sell,$object,$user->rights->produit->creer|$user->rights->service->creer); print $form->editfieldval("ProductAccountancySellCode",'accountancy_code_sell',$object->accountancy_code_sell,$object,$user->rights->produit->creer||$user->rights->service->creer);
print '</td></tr>'; print '</td></tr>';
// Accountancy buy code // Accountancy buy code
print '<tr><td>'.$form->editfieldkey("ProductAccountancyBuyCode",'productaccountancycodebuy',$object->accountancy_code_buy,$object,$user->rights->produit->creer|$user->rights->service->creer).'</td><td colspan="2">'; print '<tr><td>'.$form->editfieldkey("ProductAccountancyBuyCode",'accountancy_code_buy',$object->accountancy_code_buy,$object,$user->rights->produit->creer||$user->rights->service->creer).'</td><td colspan="2">';
print $form->editfieldval("ProductAccountancyBuyCode",'productaccountancycodebuy',$object->accountancy_code_buy,$object,$user->rights->produit->creer|$user->rights->service->creer); print $form->editfieldval("ProductAccountancyBuyCode",'accountancy_code_buy',$object->accountancy_code_buy,$object,$user->rights->produit->creer||$user->rights->service->creer);
print '</td></tr>'; print '</td></tr>';
// Status (to sell) // Status (to sell)
@ -1742,8 +1738,6 @@ if ($object->id && ($action == '' || $action == 'view') && $object->status)
} }
llxFooter();
$db->close(); $db->close();
llxFooter();
?> ?>