From 36ce8b6d1ca78787bf5ceb969faf1e694dbef9d9 Mon Sep 17 00:00:00 2001 From: Nicolas Domenech Date: Fri, 27 Sep 2024 08:35:42 +0200 Subject: [PATCH] #268 [RegistrationCertificate] fix: JS reload fields --- js/dolicar.min.js | 2 +- js/modules/registrationcertificate.js | 15 ++++++++++++++- .../registrationcertificatefr_card.php | 13 ++++++------- 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/js/dolicar.min.js b/js/dolicar.min.js index 2a94493..cc4e1e8 100644 --- a/js/dolicar.min.js +++ b/js/dolicar.min.js @@ -1 +1 @@ -window.dolicar||(window.dolicar={},window.dolicar.scriptsLoaded=!1),window.dolicar.scriptsLoaded||(window.dolicar.init=function(){window.dolicar.load_list_script()},window.dolicar.load_list_script=function(){if(!window.dolicar.scriptsLoaded){for(var o in window.dolicar)if(window.dolicar.hasOwnProperty(o)&&"object"==typeof window.dolicar[o])for(var i in"function"==typeof window.dolicar[o].init&&window.dolicar[o].init(),window.dolicar[o])window.dolicar[o].hasOwnProperty(i)&&"object"==typeof window.dolicar[o][i]&&"function"==typeof window.dolicar[o][i].init&&window.dolicar[o][i].init();window.dolicar.scriptsLoaded=!0}},window.dolicar.refresh=function(){for(var o in window.dolicar)if(window.dolicar.hasOwnProperty(o)&&"object"==typeof window.dolicar[o])for(var i in"function"==typeof window.dolicar[o].refresh&&window.dolicar[o].refresh(),window.dolicar[o])window.dolicar[o].hasOwnProperty(i)&&window.dolicar[o][i]&&"function"==typeof window.dolicar[o][i].refresh&&window.dolicar[o][i].refresh()},$(document).ready(window.dolicar.init)),window.dolicar.registrationcertificate={},window.dolicar.registrationcertificate.init=function(){window.dolicar.registrationcertificate.event()},window.dolicar.registrationcertificate.event=function(){$(document).on("change","#fk_product",window.dolicar.registrationcertificate.reloadFields),$("#public-vehicle-log-book-form").on("submit",function(o){o.preventDefault(),$(this).find(".public-vehicle-log-book-validate").hasClass("button-disable")||window.dolicar.registrationcertificate.createPublicVehicleLogBook()}),$(document).on("touchstart mousedown",".canvas-signature",function(){window.saturne.toolbox.removeAddButtonClass("public-vehicle-log-book-validate","button-grey button-disable","button-blue")}),$(document).on("click",".signature-erase",function(){window.saturne.toolbox.removeAddButtonClass("public-vehicle-log-book-validate","button-blue","button-grey button-disable")})},window.dolicar.registrationcertificate.reloadFields=function(){var o=window.saturne.toolbox.getToken(),i=window.saturne.toolbox.getQuerySeparator(document.URL),n=$(this).val();window.saturne.loader.display($(".field_fk_lot")),window.saturne.loader.display($(".field_d1_vehicle_brand")),$.ajax({url:document.URL+i+"&fk_product="+n+"&token="+o,type:"POST",processData:!1,contentType:!1,success:function(o){$(".field_fk_lot").replaceWith($(o).find(".field_fk_lot")),$(".field_d1_vehicle_brand").replaceWith($(o).find(".field_d1_vehicle_brand"))},error:function(){}})},window.dolicar.registrationcertificate.createPublicVehicleLogBook=function(){var o,i=window.saturne.toolbox.getToken(),n=window.saturne.toolbox.getQuerySeparator(document.URL),e=new FormData($("#public-vehicle-log-book-form")[0]);window.saturne.signature.canvas&&(o=window.saturne.signature.canvas.toDataURL(),e.append("signature",JSON.stringify(o))),$.ajax({url:document.URL+n+"action=add&token="+i,type:"POST",processData:!1,contentType:!1,data:e,success:function(){$(".public-vehicle-log-book-confirmation-close").closest(".card__confirmation").css("display","flex"),$(".public-vehicle-log-book-confirmation-close").on("click",function(){$(".public-vehicle-log-book-confirmation-close").closest(".card__confirmation").css("display","none"),window.location.reload()})},error:function(){}})}; \ No newline at end of file +window.dolicar||(window.dolicar={},window.dolicar.scriptsLoaded=!1),window.dolicar.scriptsLoaded||(window.dolicar.init=function(){window.dolicar.load_list_script()},window.dolicar.load_list_script=function(){if(!window.dolicar.scriptsLoaded){for(var o in window.dolicar)if(window.dolicar.hasOwnProperty(o)&&"object"==typeof window.dolicar[o])for(var i in"function"==typeof window.dolicar[o].init&&window.dolicar[o].init(),window.dolicar[o])window.dolicar[o].hasOwnProperty(i)&&"object"==typeof window.dolicar[o][i]&&"function"==typeof window.dolicar[o][i].init&&window.dolicar[o][i].init();window.dolicar.scriptsLoaded=!0}},window.dolicar.refresh=function(){for(var o in window.dolicar)if(window.dolicar.hasOwnProperty(o)&&"object"==typeof window.dolicar[o])for(var i in"function"==typeof window.dolicar[o].refresh&&window.dolicar[o].refresh(),window.dolicar[o])window.dolicar[o].hasOwnProperty(i)&&window.dolicar[o][i]&&"function"==typeof window.dolicar[o][i].refresh&&window.dolicar[o][i].refresh()},$(document).ready(window.dolicar.init)),window.dolicar.registrationcertificate={},window.dolicar.registrationcertificate.init=function(){window.dolicar.registrationcertificate.event()},window.dolicar.registrationcertificate.event=function(){$(document).on("change","#fk_product",window.dolicar.registrationcertificate.reloadFields),$("#public-vehicle-log-book-form").on("submit",function(o){o.preventDefault(),$(this).find(".public-vehicle-log-book-validate").hasClass("button-disable")||window.dolicar.registrationcertificate.createPublicVehicleLogBook()}),$(document).on("touchstart mousedown",".canvas-signature",function(){window.saturne.toolbox.removeAddButtonClass("public-vehicle-log-book-validate","button-grey button-disable","button-blue")}),$(document).on("click",".signature-erase",function(){window.saturne.toolbox.removeAddButtonClass("public-vehicle-log-book-validate","button-blue","button-grey button-disable")})},window.dolicar.registrationcertificate.reloadFields=function(){var o=document.getElementById("registrationcertificatefr_form"),o=new FormData(o),i=window.saturne.toolbox.getToken(),t=window.saturne.toolbox.getQuerySeparator(document.URL),e=$(this).val();window.saturne.loader.display($(".field_fk_lot")),window.saturne.loader.display($(".field_d1_vehicle_brand"));let n="";document.URL.match("action=")||("add"===(o=o.get("action"))?n="action=create":"update"===o&&(n="action=edit")),$.ajax({url:document.URL+t+n+"&fk_product="+e+"&token="+i,type:"POST",processData:!1,contentType:!1,success:function(o){$(".field_fk_lot").replaceWith($(o).find(".field_fk_lot")),$(".field_d1_vehicle_brand").replaceWith($(o).find(".field_d1_vehicle_brand"))},error:function(){}})},window.dolicar.registrationcertificate.createPublicVehicleLogBook=function(){var o,i=window.saturne.toolbox.getToken(),t=window.saturne.toolbox.getQuerySeparator(document.URL),e=new FormData($("#public-vehicle-log-book-form")[0]);window.saturne.signature.canvas&&(o=window.saturne.signature.canvas.toDataURL(),e.append("signature",JSON.stringify(o))),$.ajax({url:document.URL+t+"action=add&token="+i,type:"POST",processData:!1,contentType:!1,data:e,success:function(){$(".public-vehicle-log-book-confirmation-close").closest(".card__confirmation").css("display","flex"),$(".public-vehicle-log-book-confirmation-close").on("click",function(){$(".public-vehicle-log-book-confirmation-close").closest(".card__confirmation").css("display","none"),window.location.reload()})},error:function(){}})}; \ No newline at end of file diff --git a/js/modules/registrationcertificate.js b/js/modules/registrationcertificate.js index de99c9e..3314115 100644 --- a/js/modules/registrationcertificate.js +++ b/js/modules/registrationcertificate.js @@ -85,6 +85,9 @@ 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(); @@ -92,8 +95,18 @@ window.dolicar.registrationcertificate.reloadFields = function() { 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, diff --git a/view/registrationcertificatefr/registrationcertificatefr_card.php b/view/registrationcertificatefr/registrationcertificatefr_card.php index f74a92f..31c3e43 100644 --- a/view/registrationcertificatefr/registrationcertificatefr_card.php +++ b/view/registrationcertificatefr/registrationcertificatefr_card.php @@ -173,7 +173,7 @@ print '
'; print '
'; - print '
'; + print ''; print ''; print ''; if ($backtopage) { @@ -187,7 +187,7 @@ print ''; - $_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 @@ -195,14 +195,14 @@ print $langs->trans('DolicarBatch'); print ''; // Common attributes @@ -233,11 +233,10 @@ if (($id || $ref) && $action == 'edit') { print load_fiche_titre($langs->trans('Modify' . ucfirst($object->element)), '', 'object_' . $object->picto); - print ''; + print ''; print ''; print ''; print ''; - print ''; if ($backtopage) { print ''; }
'; $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 ''; + print img_picto('', 'lot', 'class="pictofixedwidth"') . $form::selectarray('fk_lot', $productLotsData, GETPOSTINT('fk_lot'), $langs->transnoentities('SelectProductLots'), '', '', '', '', '', '','', 'maxwidth500 widthcentpercentminusx'); + print ''; print '