Skip to content

Commit

Permalink
Evarisk#268 [RegistrationCertificate] fix: JS reload fields
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-eoxia committed Sep 27, 2024
1 parent 4f85e95 commit 36ce8b6
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 9 deletions.
2 changes: 1 addition & 1 deletion js/dolicar.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 14 additions & 1 deletion js/modules/registrationcertificate.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,28 @@ window.dolicar.registrationcertificate.event = function() {
* @return {void}
*/
window.dolicar.registrationcertificate.reloadFields = function() {
let form = document.getElementById('registrationcertificatefr_form');
let formData = new FormData(form);

let token = window.saturne.toolbox.getToken();
let querySeparator = window.saturne.toolbox.getQuerySeparator(document.URL);
let productID = $(this).val();

window.saturne.loader.display($('.field_fk_lot'));
window.saturne.loader.display($('.field_d1_vehicle_brand'));

let actionPost = '';
if (!document.URL.match('action=')) {
let action = formData.get('action');
if (action === 'add') {
actionPost = 'action=create';
} else if (action === 'update') {
actionPost = 'action=edit';
}
}

$.ajax({
url: document.URL + querySeparator + '&fk_product=' + productID + '&token=' + token,
url: document.URL + querySeparator + actionPost + '&fk_product=' + productID + '&token=' + token,
type: 'POST',
processData: false,
contentType: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@
print '<hr>';
print '<br>';

print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'" id="registrationcertificatefr_create">';
print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'" id="registrationcertificatefr_form">';
print '<input type="hidden" name="token" value="'.newToken().'">';
print '<input type="hidden" name="action" value="add">';
if ($backtopage) {
Expand All @@ -187,22 +187,22 @@

print '<table class="border centpercent tableforfieldcreate">';

$_POST['fk_product'] = getDolGlobalInt('DOLICAR_DEFAULT_VEHICLE');
$object->fields['fk_product']['default'] = getDolGlobalInt('DOLICAR_DEFAULT_VEHICLE');
$object->fields['d1_vehicle_brand']['default'] = get_vehicle_brand(GETPOSTINT('fk_product'));

// Fk_lot
print'<tr class="field_fk_lot"><td>';
print $langs->trans('DolicarBatch');
print '</td><td>';
$productLotsData = [];
$productLots = saturne_fetch_all_object_type('ProductLot', '', '', 0, 0, ['customsql' => 't.fk_product = ' . GETPOST('fk_product')]);
$productLots = saturne_fetch_all_object_type('ProductLot', '', '', 0, 0, ['customsql' => 't.fk_product = ' . GETPOSTINT('fk_product')]);
if (is_array($productLots) && !empty($productLots)) {
foreach ($productLots as $productLotSingle) {
$productLotsData[$productLotSingle->id] = $productLotSingle->batch;
}
}
print img_picto('', 'lot', 'class="pictofixedwidth"') . $form::selectarray('fk_lot', $productLotsData, GETPOST('fk_lot'), $langs->transnoentities('SelectProductLots'), '', '', '', '', '', '','', 'maxwidth500 widthcentpercentminusx');
print '<a class="butActionNew" href="' . DOL_URL_ROOT . '/product/stock/productlot_card.php?action=create' . ((GETPOST('fk_product') > 0) ? '&fk_product=' . GETPOST('fk_product') : '') . '&backtopage=' . urlencode($_SERVER['PHP_SELF'] . '?action=create') . '"><span class="fa fa-plus-circle valignmiddle paddingleft" title="' . $langs->trans('AddProductLot') . '"></span></a>';
print img_picto('', 'lot', 'class="pictofixedwidth"') . $form::selectarray('fk_lot', $productLotsData, GETPOSTINT('fk_lot'), $langs->transnoentities('SelectProductLots'), '', '', '', '', '', '','', 'maxwidth500 widthcentpercentminusx');
print '<a class="butActionNew" href="' . DOL_URL_ROOT . '/product/stock/productlot_card.php?action=create' . (GETPOSTISSET('fk_product') && GETPOST('fk_product') > 0 ? '&fk_product=' . GETPOST('fk_product') : '') . '&backtopage=' . urlencode($_SERVER['PHP_SELF'] . '?action=create') . '"><span class="fa fa-plus-circle valignmiddle paddingleft" title="' . $langs->trans('AddProductLot') . '"></span></a>';
print '</td></tr>';

// Common attributes
Expand Down Expand Up @@ -233,11 +233,10 @@
if (($id || $ref) && $action == 'edit') {
print load_fiche_titre($langs->trans('Modify' . ucfirst($object->element)), '', 'object_' . $object->picto);

print '<form method="POST" action="' . $_SERVER['PHP_SELF'] . '" id="registrationcertificatefr_edit">';
print '<form method="POST" action="' . $_SERVER['PHP_SELF'] . '" id="registrationcertificatefr_form">';
print '<input type="hidden" name="token" value="' . newToken() . '">';
print '<input type="hidden" name="action" value="update">';
print '<input type="hidden" name="id" value="' . $object->id . '">';
print '<input hidden class="car-brand" value="' . $brandName . '">';
if ($backtopage) {
print '<input type="hidden" name="backtopage" value="' . $backtopage . '">';
}
Expand Down

0 comments on commit 36ce8b6

Please sign in to comment.