Clean code

This commit is contained in:
Laurent Destailleur 2023-05-01 15:09:43 +02:00
parent a4563c7ad4
commit 759ddd2d73
19 changed files with 56 additions and 41 deletions

View File

@ -188,7 +188,7 @@ if (!empty($number)) {
} else {
$txt = "Call Asterisk dialer for caller: ".$caller.", called: ".$called." clicktodiallogin: ".$login;
dol_syslog($txt);
print '<body onload="javascript:history.go(-1);">'."\n";
print '<body onload="history.go(-1);">'."\n";
print '<!-- '.$txt.' -->';
fputs($oSocket, "Action: login\r\n");
fputs($oSocket, "Events: off\r\n");

View File

@ -440,7 +440,7 @@ if ($action == 'create') {
print '<div class="center">';
print '<input type="submit" class="button button-add" value="'.$langs->trans("Add").'">';
print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
print '<input type="button" class="button button-cancel" value="'.$langs->trans("Cancel").'" onClick="javascript:history.go(-1)">';
print '<input type="button" class="button button-cancel" value="'.$langs->trans("Cancel").'" onClick="history.go(-1)">';
print '</div>';
print '</form>';

View File

@ -1115,7 +1115,7 @@ class Form
$out .= '</select>';
if ($conf->use_javascript_ajax && empty($disableautocomplete)) {
$out .= ajax_multiautocompleter('location_incoterms', '', DOL_URL_ROOT . '/core/ajax/locationincoterms.php') . "\n";
$out .= ajax_multiautocompleter('location_incoterms', array(), DOL_URL_ROOT . '/core/ajax/locationincoterms.php') . "\n";
$moreattrib .= ' autocomplete="off"';
}
$out .= '<input id="location_incoterms" class="maxwidthonsmartphone type="text" name="location_incoterms" value="' . $location_incoterms . '">' . "\n";

View File

@ -876,7 +876,7 @@ class FormCompany extends Form
* @param string $morecss More css
* @return string
*/
public function select_ziptown($selected = '', $htmlname = 'zipcode', $fields = '', $fieldsize = 0, $disableautocomplete = 0, $moreattrib = '', $morecss = '')
public function select_ziptown($selected = '', $htmlname = 'zipcode', $fields = array(), $fieldsize = 0, $disableautocomplete = 0, $moreattrib = '', $morecss = '')
{
// phpcs:enable
global $conf;

View File

@ -1905,7 +1905,7 @@ class Lessc
}
// type based operators
$fname = "op_${ltype}_${rtype}";
$fname = "op_".$ltype."_".$rtype;
if (is_callable(array($this, $fname))) {
$out = $this->$fname($op, $left, $right);
if (!is_null($out)) {

View File

@ -104,7 +104,7 @@ oConnector.CurrentFolder = '/' ;
var sConnUrl = GetUrlParam( 'Connector' );
// Gecko has some problems when using relative URLs (not starting with slash).
if ( sConnUrl.substr(0,1) != '/' && sConnUrl.indexOf( '://' ) < 0 )
if ( sConnUrl.substring(0,1) != '/' && sConnUrl.indexOf( '://' ) < 0 )
sConnUrl = window.location.href.replace( /browser.php.*$/, '' ) + sConnUrl ;
oConnector.ConnectorUrl = sConnUrl + ( sConnUrl.indexOf('?') != -1 ? '&' : '?' );

View File

@ -225,7 +225,7 @@ $(document).ready(function(){
$(this).find("li ul").slideToggle(200);
target = $(this);
var target = $(this);
$(\'html, body\').animate({
scrollTop: target.offset().top
}, 300);

View File

@ -1,4 +1,4 @@
// Copyright (C) 2011-2014 Laurent Destailleur <eldy@users.sourceforge.net>
// Copyright (C) 2011-2023 Laurent Destailleur <eldy@users.sourceforge.net>
// Copyright (C) 2011-2012 Regis Houssin <regis.houssin@inodbox.com>
// Copyright (C) 2015 Marcos García <marcosgdf@gmail.com>
//
@ -69,7 +69,7 @@ function DisplayDstSwitchDates(firstsecond)
var lastOffset = 99;
// Loop through every month of the current year
for (i = 0; i < 12; i++)
for (let i = 0; i < 12; i++)
{
// Fetch the timezone value for the month
var newDate = new Date(Date.UTC(year, i, 0, 0, 0, 0, 0));
@ -109,7 +109,7 @@ function FindDstSwitchDate(year, month)
var dstDate;
// Loop to find the exact day a timezone adjust occurs
for (day = 0; day < 50; day++)
for (let day = 0; day < 50; day++)
{
var tmpDate = new Date(Date.UTC(year, month, day, 0, 0, 0, 0));
var tmpOffset = -1 * tmpDate.getTimezoneOffset() / 60;

View File

@ -1227,7 +1227,7 @@ function pricejs(amount, mode = 'MT', currency_code = '', force_locale = '') {
* Function similar to PHP price2num()
*
* @param {number|string} amount The amount to convert/clean
* @return {string} The amount in universal numeric format (Example: '99.99999')
* @return {number} The amount in universal numeric format (Example: '99.99999')
* @todo Implement rounding parameter
*/
function price2numjs(amount) {
@ -1246,20 +1246,27 @@ function price2numjs(amount) {
var rounding = main_rounding_unit;
var pos = amount.indexOf(dec);
var decpart = '';
if (pos >= 0) decpart = amount.substr(pos + 1).replace('/0+$/i', ''); // Remove 0 for decimal part
if (pos >= 0) {
decpart = amount.substring(pos + 1).replace('/0+$/i', ''); // Remove 0 for decimal part
}
var nbdec = decpart.length;
if (nbdec > rounding) rounding = nbdec;
if (nbdec > rounding) {
rounding = nbdec;
}
// If rounding higher than max shown
if (rounding > main_max_dec_shown) rounding = main_max_dec_shown;
if (thousand != ',' && thousand != '.') amount = amount.replace(',', '.');
amount = amount.replace(' ', ''); // To avoid spaces
amount = amount.replace(thousand, ''); // Replace of thousand before replace of dec to avoid pb if thousand is .
amount = amount.replace(dec, '.');
//console.log("amount before="+amount+" rouding="+rounding)
var res = Math.round10(amount, - rounding);
// Other solution is
// var res = dolroundjs(amount, rounding)
console.log("price2numjs text="+amount+" return="+res);
return res;
}

View File

@ -63,7 +63,7 @@ function regexEvent(objet,evt,type)
case 'timeChar':
//var regex= /^[0-9:]{1}$/;
//alert(event.charCode);
var charCode = (evt.which) ? evt.which : event.keyCode;
var charCode = (evt.which) ? evt.which : evt.keyCode;
if(((charCode >= 48) && (charCode <= 57)) || //num
(charCode===46) || (charCode===8)||// comma & periode

View File

@ -305,7 +305,7 @@ function barcode_encode_upc($upc, $encoding = "UPC")
if ($a > 1) {
$text .= " ";
}
$text .= "$pos:12:{$upc[$a]}";
$text .= $pos.":12:".$upc[$a];
if ($a == 1) {
$pos += 15;
} elseif ($a == 6) {

View File

@ -1866,8 +1866,8 @@ function dolButtonToOpenUrlInDialogPopup($name, $label, $buttonstring, $url, $di
console.log("open popup name='.$name.', backtopagejsfields='.$backtopagejsfields.'");
},
close: function (event, ui) {
returnedid = jQuery("#varforreturndialogid'.$name.'").text();
returnedlabel = jQuery("#varforreturndialoglabel'.$name.'").text();
var returnedid = jQuery("#varforreturndialogid'.$name.'").text();
var returnedlabel = jQuery("#varforreturndialoglabel'.$name.'").text();
console.log("popup has been closed. returnedid (js var defined into parent page)="+returnedid+" returnedlabel="+returnedlabel);
if (returnedid != "" && returnedid != "div for returned id") {
jQuery("#'.(empty($backtopagejsfieldsid)?"none":$backtopagejsfieldsid).'").val(returnedid);

View File

@ -453,11 +453,12 @@ if (!empty($usemargins) && $user->rights->margins->creer) {
}
var price = 0;
remisejs=price2numjs(remise.val());
remisejs = price2numjs(remise.val());
if (remisejs != 100) // If a discount not 100 or no discount
{
if (remisejs == '') remisejs=0;
if (remisejs != 100) { // If a discount not 100 or no discount
if (remisejs == '') {
remisejs = 0;
}
bpjs=price2numjs(buying_price.val());
ratejs=price2numjs(rate.val());

View File

@ -86,8 +86,8 @@ print dol_get_fiche_head($head, 'compare', '', 1);
}
$userl = $(this).closest('ul');
listname = $userl.attr('name');
var $userl = $(this).closest('ul');
var listname = $userl.attr('name');
var TId = [];

View File

@ -630,7 +630,7 @@ function jscheckparam()
{
console.log("Click on jscheckparam");
ok=true;
var ok = true;
if (document.forminstall.main_dir.value == '')
{

View File

@ -2837,18 +2837,18 @@ function top_menu_bookmark()
jQuery("#topmenu-bookmark-dropdown .dropdown-toggle").on("click", function(event) {
console.log("Click on #topmenu-bookmark-dropdown .dropdown-toggle");
openBookMarkDropDown();
openBookMarkDropDown(event);
});
// Key map shortcut
jQuery(document).keydown(function(e){
if( e.which === 77 && e.ctrlKey && e.shiftKey ){
console.log(\'control + shift + m : trigger open bookmark dropdown\');
openBookMarkDropDown();
jQuery(document).keydown(function(event){
if( event.which === 77 && event.ctrlKey && event.shiftKey ){
console.log("Click on control + shift + m : trigger open bookmark dropdown");
openBookMarkDropDown(event);
}
});
var openBookMarkDropDown = function() {
var openBookMarkDropDown = function(event) {
event.preventDefault();
jQuery("#topmenu-bookmark-dropdown").toggleClass("open");
jQuery("#top-bookmark-search-input").focus();

View File

@ -249,6 +249,8 @@ function AddProductConfirm(placeid, productid){
});';
}
?>
return true;
}
function SetQty(place, selectedline, qty){
@ -278,6 +280,8 @@ function SetQty(place, selectedline, qty){
}
?>
LoadCats();
return true;
}
function SetNote(place, selectedline){

View File

@ -212,19 +212,19 @@ if (!isset($conf->global->TAKEPOS_NUMPAD_USE_PAYMENT_ICON) || !empty($conf->glob
<div style="position:absolute; top:33%; left:5%; height:52%; width:92%;">
<?php
print '<button type="button" class="calcbutton" onclick="AddReduction(7);">7</button>';
print '<button type="button" class="calcbutton" onclick="AddReduction(8);">8</button>';
print '<button type="button" class="calcbutton" onclick="AddReduction(9);">9</button>';
print '<button type="button" class="calcbutton" onclick="AddReduction(\'7\');">7</button>';
print '<button type="button" class="calcbutton" onclick="AddReduction(\'8\');">8</button>';
print '<button type="button" class="calcbutton" onclick="AddReduction(\'9\');">9</button>';
print '<button type="button" class="calcbutton2" id="reduction_type_percent" onclick="Edit(\'p\');">'.$htmlReductionPercent.'</button>';
print '<button type="button" class="calcbutton" onclick="AddReduction(4);">4</button>';
print '<button type="button" class="calcbutton" onclick="AddReduction(5);">5</button>';
print '<button type="button" class="calcbutton" onclick="AddReduction(6);">6</button>';
print '<button type="button" class="calcbutton" onclick="AddReduction(\'4\');">4</button>';
print '<button type="button" class="calcbutton" onclick="AddReduction(\'5\');">5</button>';
print '<button type="button" class="calcbutton" onclick="AddReduction(\'6\');">6</button>';
print '<button type="button" class="calcbutton2" id="reduction_type_amount" onclick="Edit(\'a\');">'.$htmlReductionAmount.'</button>';
print '<button type="button" class="calcbutton" onclick="AddReduction(1);">1</button>';
print '<button type="button" class="calcbutton" onclick="AddReduction(2);">2</button>';
print '<button type="button" class="calcbutton" onclick="AddReduction(3);">3</button>';
print '<button type="button" class="calcbutton" onclick="AddReduction(\'1\');">1</button>';
print '<button type="button" class="calcbutton" onclick="AddReduction(\'2\');">2</button>';
print '<button type="button" class="calcbutton" onclick="AddReduction(\'3\');">3</button>';
print '<button type="button" class="calcbutton3 poscolorblue" onclick="Reset();"><span id="printtext" style="font-weight: bold; font-size: 18pt;">C</span></button>';
print '<button type="button" class="calcbutton" onclick="AddReduction(0);">0</button>';
print '<button type="button" class="calcbutton" onclick="AddReduction(\'0\');">0</button>';
print '<button type="button" class="calcbutton" onclick="AddReduction(\'.\');">.</button>';
print '<button type="button" class="calcbutton">&nbsp;</button>';
print '<button type="button" class="calcbutton3 poscolordelete" onclick="parent.$.colorbox.close();"><span id="printtext" style="font-weight: bold; font-size: 18pt;">X</span></button>';

View File

@ -111,4 +111,7 @@ exclude:
- name: JSUnnecessarySemicolon
- name: JSPrimitiveTypeWrapperUsage
- name: PhpFullyQualifiedNameUsageInspection
- name: PhpDocMissingThrowsInspection
- name: UnnecessaryLabelJS