2
0
forked from Wavyzz/dolibarr

Debug v21 - Fix set of focus on description after slection of type of

line
This commit is contained in:
Laurent Destailleur (aka Eldy)
2024-12-19 01:05:39 +01:00
parent ff2aa10145
commit 289b69bb24
6 changed files with 592 additions and 544 deletions

View File

@@ -1155,9 +1155,10 @@ class Form
* @param int $hidetext Do not show label 'Type' before combo box (used only if there is at least 2 choices to select) * @param int $hidetext Do not show label 'Type' before combo box (used only if there is at least 2 choices to select)
* @param integer $forceall 1=Force to show products and services in combo list, whatever are activated modules, 0=No force, 2=Force to show only Products, 3=Force to show only services, -1=Force none (and set hidden field to 'service') * @param integer $forceall 1=Force to show products and services in combo list, whatever are activated modules, 0=No force, 2=Force to show only Products, 3=Force to show only services, -1=Force none (and set hidden field to 'service')
* @param string $morecss More css * @param string $morecss More css
* @param int $useajaxcombo 1=Use ajaxcombo
* @return void * @return void
*/ */
public function select_type_of_lines($selected = '', $htmlname = 'type', $showempty = 0, $hidetext = 0, $forceall = 0, $morecss = "") public function select_type_of_lines($selected = '', $htmlname = 'type', $showempty = 0, $hidetext = 0, $forceall = 0, $morecss = "", $useajaxcombo = 1)
{ {
// phpcs:enable // phpcs:enable
global $langs; global $langs;
@@ -1166,11 +1167,11 @@ class Form
if ($forceall == 1 || (empty($forceall) && isModEnabled("product") && isModEnabled("service")) if ($forceall == 1 || (empty($forceall) && isModEnabled("product") && isModEnabled("service"))
|| (empty($forceall) && !isModEnabled('product') && !isModEnabled('service'))) { || (empty($forceall) && !isModEnabled('product') && !isModEnabled('service'))) {
if (empty($hidetext)) { if (empty($hidetext)) {
print $langs->trans("Type") . ': '; print $langs->trans("Type").'...';
} }
print '<select class="flat'.($morecss ? ' '.$morecss : '').'" id="select_' . $htmlname . '" name="' . $htmlname . '">'; print '<select class="flat'.($morecss ? ' '.$morecss : '').'" id="select_' . $htmlname . '" name="' . $htmlname . '">';
if ($showempty) { if ($showempty) {
print '<option value="-1"'; print '<option value="-1" class="opacitymedium"'.($useajaxcombo ? '' : ' disabled="disabled"');
if ($selected == -1) { if ($selected == -1) {
print ' selected'; print ' selected';
} }
@@ -1196,7 +1197,10 @@ class Form
print '>' . $langs->trans("Service"); print '>' . $langs->trans("Service");
print '</select>'; print '</select>';
if ($useajaxcombo) {
print ajax_combobox('select_' . $htmlname); print ajax_combobox('select_' . $htmlname);
}
//if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1); //if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
} }
if ((empty($forceall) && !isModEnabled('product') && isModEnabled("service")) || $forceall == 3) { if ((empty($forceall) && !isModEnabled('product') && isModEnabled("service")) || $forceall == 3) {

View File

@@ -1557,11 +1557,13 @@ if (!getDolGlobalString('MAIN_DISABLE_SELECT2_FOCUS_PROTECTION') && !defined('DI
* TODO: Recheck with the select2 GH issue and remove once this is fixed on their side * TODO: Recheck with the select2 GH issue and remove once this is fixed on their side
*/ */
$(document).on('select2:open', (e) => { $(document).on('select2:open', (e) => {
console.log("Execute the focus (click on combo or use space when on component"); console.log("Execute the focus (click on combo or use space when on component)");
const target = $(e.target); const target = $(e.target);
if (target && target.length) { if (target && target.length) {
let id = target[0].id || target[0].name; let id = target[0].id || target[0].name;
if (id.substr(-2) == "[]") id = id.substr(0,id.length-2); if (id.substr(-2) == "[]") {
id = id.substr(0,id.length-2);
}
document.querySelector('input[aria-controls*='+id+']').focus(); document.querySelector('input[aria-controls*='+id+']').focus();
} }
}); });

View File

@@ -204,7 +204,7 @@ if ($nolinesbefore) {
} }
} }
// Free line // Select type of free line
$labelforempty = 1; $labelforempty = 1;
print '<span class="prod_entry_mode_free nowraponall">'; print '<span class="prod_entry_mode_free nowraponall">';
// Show radio for the non predefined product // Show radio for the non predefined product
@@ -215,10 +215,8 @@ if ($nolinesbefore) {
print((GETPOST('prod_entry_mode', 'alpha') == 'free' || getDolGlobalString('MAIN_FREE_PRODUCT_CHECKED_BY_DEFAULT')) ? ' checked' : ''); print((GETPOST('prod_entry_mode', 'alpha') == 'free' || getDolGlobalString('MAIN_FREE_PRODUCT_CHECKED_BY_DEFAULT')) ? ' checked' : '');
print '> '; print '> ';
// Show type selector // Show type selector
//print '<span class="textradioforitem">'.$langs->trans("FreeLineOfType").'</span>'; $labelforempty = $langs->trans("FreeLineOfType").'...';
$labelforempty = $langs->trans("FreeLineOfType");
print '</label>'; print '</label>';
//print ' ';
} else { } else {
echo '<input type="hidden" id="prod_entry_mode_free" name="prod_entry_mode" value="free">'; echo '<input type="hidden" id="prod_entry_mode_free" name="prod_entry_mode" value="free">';
// Show type selector // Show type selector
@@ -228,11 +226,10 @@ if ($nolinesbefore) {
} else { } else {
$labelforempty = $langs->trans("FreeLineOfType"); $labelforempty = $langs->trans("FreeLineOfType");
} }
//print ' ';
} }
} }
$form->select_type_of_lines(GETPOSTISSET("type") ? GETPOST("type", 'alpha', 2) : -1, 'type', $labelforempty, 1, $forceall, 'minwidth200'); $form->select_type_of_lines(GETPOSTISSET("type") ? GETPOST("type", 'alpha', 2) : -1, 'type', $labelforempty, 1, $forceall, 'minwidth200', 0);
print '</span>'; print '</span>';
} }
// Predefined product/service // Predefined product/service
@@ -281,10 +278,10 @@ if ($nolinesbefore) {
if (getDolGlobalString('MAIN_AUTO_OPEN_SELECT2_ON_FOCUS_FOR_CUSTOMER_PRODUCTS')) { if (getDolGlobalString('MAIN_AUTO_OPEN_SELECT2_ON_FOCUS_FOR_CUSTOMER_PRODUCTS')) {
?> ?>
<script> <script>
$(document).ready(function(){ $(document).ready(function() {
// On first focus on a select2 combo, auto open the menu (this allow to use the keyboard only) // On first focus on a select2 combo, auto open the menu (this allow to use the keyboard only)
$(document).on('focus', '.select2-selection.select2-selection--single', function (e) { $(document).on('focus', '.select2-selection.select2-selection--single', function (e) {
console.log('focus on a select2'); console.log("focus on a select2 because of MAIN_AUTO_OPEN_SELECT2_ON_FOCUS_FOR_CUSTOMER_PRODUCTS");
if ($(this).attr('aria-labelledby') == 'select2-idprod-container') if ($(this).attr('aria-labelledby') == 'select2-idprod-container')
{ {
console.log('open combo'); console.log('open combo');
@@ -321,7 +318,7 @@ if ($nolinesbefore) {
$(document).ready(function(){ $(document).ready(function(){
// On first focus on a select2 combo, auto open the menu (this allow to use the keyboard only) // On first focus on a select2 combo, auto open the menu (this allow to use the keyboard only)
$(document).on('focus', '.select2-selection.select2-selection--single', function (e) { $(document).on('focus', '.select2-selection.select2-selection--single', function (e) {
//console.log('focus on a select2'); //console.log('focus on a select2 because of MAIN_AUTO_OPEN_SELECT2_ON_FOCUS_FOR_SUPPLIER_PRODUCTS');
if ($(this).attr('aria-labelledby') == 'select2-idprodfournprice-container') if ($(this).attr('aria-labelledby') == 'select2-idprodfournprice-container')
{ {
$('#idprodfournprice').select2('open'); $('#idprodfournprice').select2('open');
@@ -638,6 +635,7 @@ if ((isModEnabled("service") || ($object->element == 'contrat')) && $dateSelecto
print "<script>\n"; print "<script>\n";
if (!empty($usemargins) && $user->hasRight('margins', 'creer')) { if (!empty($usemargins) && $user->hasRight('margins', 'creer')) {
?> ?>
/* Some js test when we click on button "Add" */ /* Some js test when we click on button "Add" */
@@ -645,12 +643,14 @@ if (!empty($usemargins) && $user->hasRight('margins', 'creer')) {
<?php <?php
if (getDolGlobalString('DISPLAY_MARGIN_RATES')) { ?> if (getDolGlobalString('DISPLAY_MARGIN_RATES')) { ?>
$("input[name='np_marginRate']:first").blur(function(e) { $("input[name='np_marginRate']:first").blur(function(e) {
console.log("np_marginRate blur");
return checkFreeLine(e, "np_marginRate"); return checkFreeLine(e, "np_marginRate");
}); });
<?php <?php
} }
if (getDolGlobalString('DISPLAY_MARK_RATES')) { ?> if (getDolGlobalString('DISPLAY_MARK_RATES')) { ?>
$("input[name='np_markRate']:first").blur(function(e) { $("input[name='np_markRate']:first").blur(function(e) {
console.log("np_markRate blur");
return checkFreeLine(e, "np_markRate"); return checkFreeLine(e, "np_markRate");
}); });
<?php <?php
@@ -707,6 +707,21 @@ if (!empty($usemargins) && $user->hasRight('margins', 'creer')) {
} }
?> ?>
/* Function to set focus on description */
function setFocusOnDescription() {
console.log("Set focus on description field");
/* this focus code works on a standard textarea but not if field was replaced with CKEDITOR */
jQuery('#dp_desc').focus();
/* this focus code works for CKEDITOR */
if (typeof CKEDITOR == "object" && typeof CKEDITOR.instances != "undefined") {
var editor = CKEDITOR.instances['dp_desc'];
if (editor) {
editor.focus();
}
}
}
/* JQuery for product free or predefined select */ /* JQuery for product free or predefined select */
jQuery(document).ready(function() { jQuery(document).ready(function() {
jQuery("#price_ht").keyup(function(event) { jQuery("#price_ht").keyup(function(event) {
@@ -717,6 +732,7 @@ if (!empty($usemargins) && $user->hasRight('margins', 'creer')) {
jQuery("#multicurrency_price_ht").val(''); jQuery("#multicurrency_price_ht").val('');
} }
}); });
jQuery("#price_ttc").keyup(function(event) { jQuery("#price_ttc").keyup(function(event) {
// console.log(event.which); // discard event tag and arrows // console.log(event.which); // discard event tag and arrows
if (event.which != 9 && (event.which < 37 || event.which > 40) && jQuery("#price_ttc").val() != '') { if (event.which != 9 && (event.which < 37 || event.which > 40) && jQuery("#price_ttc").val() != '') {
@@ -740,27 +756,11 @@ if (!empty($usemargins) && $user->hasRight('margins', 'creer')) {
} }
}); });
$("#prod_entry_mode_free").on( "click", function() {
setforfree();
});
$("#select_type").change(function() $("#select_type").change(function()
{ {
setforfree(); setforfree();
if (jQuery('#select_type').val() >= 0) { console.log("Hide/show date according to product type select_type="+jQuery('#select_type').val());
console.log("Set focus on description field");
/* this focus code works on a standard textarea but not if field was replaced with CKEDITOR */
jQuery('#dp_desc').focus();
/* this focus code works for CKEDITOR */
if (typeof CKEDITOR == "object" && typeof CKEDITOR.instances != "undefined") {
var editor = CKEDITOR.instances['dp_desc'];
if (editor) {
editor.focus();
}
}
}
console.log("Hide/show date according to product type");
if (jQuery('#select_type').val() == '0') if (jQuery('#select_type').val() == '0')
{ {
jQuery('#trlinefordates').hide(); jQuery('#trlinefordates').hide();
@@ -771,22 +771,40 @@ if (!empty($usemargins) && $user->hasRight('margins', 'creer')) {
jQuery('#trlinefordates').show(); jQuery('#trlinefordates').show();
jQuery('.divlinefordates').show(); jQuery('.divlinefordates').show();
} }
if (jQuery("#select_type").val() != '-1') {
console.log("we remove class");
jQuery("#select_type").removeClass("placeholder");
setFocusOnDescription();
} else {
console.log("we add class");
jQuery("#select_type").addClass("placeholder");
}
});
$("#prod_entry_mode_free").on( "click", function() {
setforfree();
}); });
$("#prod_entry_mode_predef").on( "click", function() { $("#prod_entry_mode_predef").on( "click", function() {
console.log("click prod_entry_mode_predef"); console.log("click prod_entry_mode_predef");
jQuery("#select_type").addClass("placeholder");
setforpredef(); setforpredef();
jQuery('#trlinefordates').show(); jQuery('#trlinefordates').show();
}); });
<?php <?php
if (!$freelines) { ?> if (!$freelines) { ?>
$("#prod_entry_mode_predef").click(); jQuery("#prod_entry_mode_predef").click();
<?php
} else { ?>
jQuery("#select_type").addClass("placeholder");
<?php <?php
} }
if (in_array($this->table_element_line, array('propaldet', 'commandedet', 'facturedet'))) { ?> if (in_array($this->table_element_line, array('propaldet', 'commandedet', 'facturedet'))) { ?>
$("#date_start, #date_end").focusout(function() { $("#date_start, #date_end").focusout(function() {
console.log("focusout of date");
let type = $(this).attr('type'); let type = $(this).attr('type');
let mandatoryP = $(this).attr('mandatoryperiod'); let mandatoryP = $(this).attr('mandatoryperiod');
if (type == 1 && mandatoryP == 1) { if (type == 1 && mandatoryP == 1) {
@@ -799,6 +817,7 @@ if (!empty($usemargins) && $user->hasRight('margins', 'creer')) {
}); });
<?php <?php
} ?> } ?>
/* When changing predefined product, we reload list of supplier prices required for margin combo */ /* When changing predefined product, we reload list of supplier prices required for margin combo */
$("#idprod, #idprodfournprice").change(function() $("#idprod, #idprodfournprice").change(function()
{ {
@@ -1261,13 +1280,16 @@ if (!empty($usemargins) && $user->hasRight('margins', 'creer')) {
/* To set focus */ /* To set focus */
if (jQuery('#idprod').val() > 0 || jQuery('#idprodfournprice').val() > 0) if (jQuery('#idprod').val() > 0 || jQuery('#idprodfournprice').val() > 0)
{ {
/* focus work on a standard textarea but not if field was replaced with CKEDITOR */ console.log("Try to set focus on desc");
/* this focus code works on a standard textarea but not if field was replaced with CKEDITOR */
jQuery('#dp_desc').focus(); jQuery('#dp_desc').focus();
/* focus if CKEDITOR */ /* this focus code works for CKEDITOR */
if (typeof CKEDITOR == "object" && typeof CKEDITOR.instances != "undefined") if (typeof CKEDITOR == "object" && typeof CKEDITOR.instances != "undefined")
{ {
var editor = CKEDITOR.instances['dp_desc']; var editor = CKEDITOR.instances['dp_desc'];
if (editor) { editor.focus(); } if (editor) {
editor.focus();
}
} }
} }
}); });
@@ -1275,6 +1297,7 @@ if (!empty($usemargins) && $user->hasRight('margins', 'creer')) {
<?php if (GETPOST('prod_entry_mode') == 'predef') { // When we submit with a predef product and it fails we must start with predef?> <?php if (GETPOST('prod_entry_mode') == 'predef') { // When we submit with a predef product and it fails we must start with predef?>
setforpredef(); setforpredef();
<?php } ?> <?php } ?>
}); });
/* Function to set fields visibility after selecting a free product */ /* Function to set fields visibility after selecting a free product */
@@ -1291,7 +1314,11 @@ if (!empty($usemargins) && $user->hasRight('margins', 'creer')) {
function setforpredef() { function setforpredef() {
console.log("objectline_create.tpl::setforpredef We hide some fields, show dates"); console.log("objectline_create.tpl::setforpredef We hide some fields, show dates");
jQuery("#select_type").val(-1); jQuery("#select_type").val(-1);
jQuery("#select_type").addClass("placeholder");
jQuery("#select_type").trigger("change");
jQuery("#prod_entry_mode_free").prop('checked',false).change(); jQuery("#prod_entry_mode_free").prop('checked',false).change();
jQuery("#prod_entry_mode_predef").prop('checked',true).change(); jQuery("#prod_entry_mode_predef").prop('checked',true).change();
<?php if (!getDolGlobalString('MAIN_DISABLE_EDIT_PREDEF_PRICEHT')) { ?> <?php if (!getDolGlobalString('MAIN_DISABLE_EDIT_PREDEF_PRICEHT')) { ?>
@@ -1329,4 +1356,6 @@ if (!empty($usemargins) && $user->hasRight('margins', 'creer')) {
print '</script>'; print '</script>';
//print '<span onclick="setFocusOnDescription();">Click</span>';
print "<!-- END PHP TEMPLATE objectline_create.tpl.php -->\n"; print "<!-- END PHP TEMPLATE objectline_create.tpl.php -->\n";

View File

@@ -798,7 +798,7 @@ Notes=Notes
AddNewLine=Add new line AddNewLine=Add new line
AddFile=Add file AddFile=Add file
FreeZone=Free-text product FreeZone=Free-text product
FreeLineOfType=Free-text item, type: FreeLineOfType=Free-text item, type
CloneMainAttributes=Clone object with its main attributes CloneMainAttributes=Clone object with its main attributes
ReGeneratePDF=Re-generate PDF ReGeneratePDF=Re-generate PDF
PDFMerge=PDF Merge PDFMerge=PDF Merge

View File

@@ -748,8 +748,12 @@ input:-webkit-autofill {
/* CSS for placeholder */ /* CSS for placeholder */
.placeholder { color: #ccc; } .placeholder { color: #ccc; }
select.placeholder { color: #ccc; }
::-webkit-input-placeholder { color: #ccc; } ::-webkit-input-placeholder { color: #ccc; }
input:-moz-placeholder { color: #ccc; } input:-moz-placeholder { color: #ccc; }
select.placeholder option:not(.opacitymediumbycolor):not(.opacitymedium) {
color: var(--colortext);
}
input[name=price], input[name=weight], input[name=volume], input[name=surface], input[name=sizeheight], input[name=net_measure], select[name=incoterm_id] { margin-right: 6px; } input[name=price], input[name=weight], input[name=volume], input[name=surface], input[name=sizeheight], input[name=net_measure], select[name=incoterm_id] { margin-right: 6px; }
fieldset { fieldset {
@@ -766,6 +770,7 @@ input#onlinepaymenturl, input#directdownloadlink {
opacity: 0.7; opacity: 0.7;
} }
.formconsumeproduce { .formconsumeproduce {
background: #f3f3f3; background: #f3f3f3;
padding: 20px 0px 0px 0px; padding: 20px 0px 0px 0px;

View File

@@ -933,11 +933,15 @@ input[type=checkbox], input[type=radio] {
/* CSS for placeholder */ /* CSS for placeholder */
.placeholder { color: #ccc; } .placeholder { color: #ccc; }
select.placeholder { color: #ccc; }
::-webkit-input-placeholder { color:#ccc; } ::-webkit-input-placeholder { color:#ccc; }
:-moz-placeholder { color:#bbb; } /* firefox 18- */ :-moz-placeholder { color:#bbb; } /* firefox 18- */
::-moz-placeholder { color:#bbb; } /* firefox 19+ */ ::-moz-placeholder { color:#bbb; } /* firefox 19+ */
:-ms-input-placeholder { color:#ccc; } /* ie */ :-ms-input-placeholder { color:#ccc; } /* ie */
input:-moz-placeholder { color:#ccc; } input:-moz-placeholder { color:#ccc; }
select.placeholder option:not(.opacitymediumbycolor):not(.opacitymedium) {
color: var(--colortext);
}
input[name=price], input[name=weight], input[name=volume], input[name=surface], input[name=sizeheight], input[name=net_measure], select[name=incoterm_id] { margin-right: 6px; } input[name=price], input[name=weight], input[name=volume], input[name=surface], input[name=sizeheight], input[name=net_measure], select[name=incoterm_id] { margin-right: 6px; }
fieldset { fieldset {
@@ -4490,7 +4494,7 @@ tr.liste_titre_filter td.liste_titre {
padding-top: 4px; padding-top: 4px;
padding-bottom: 3px; padding-bottom: 3px;
} }
.liste_titre_create td, .liste_titre_create th, .liste_titre_create .tagtd .liste_titre_create td:not(.linecoldescription), .liste_titre_create th, .liste_titre_create .tagtd
{ {
border-top-width: 1px; border-top-width: 1px;
border-top-color: var(--colortopbordertitle1); border-top-color: var(--colortopbordertitle1);
@@ -4512,6 +4516,10 @@ tr#trlinefordates td {
border-top-style: solid; border-top-style: solid;
} }
td.linecoldescription {
padding: 6px 10px 6px 12px !important; /* t r b l */
}
table.liste th, table.noborder th, table.noborder tr.liste_titre td, table.noborder tr.box_titre td { table.liste th, table.noborder th, table.noborder tr.liste_titre td, table.noborder tr.box_titre td {
padding: 8px 8px 8px 10px; /* t r b l */ padding: 8px 8px 8px 10px; /* t r b l */
} }