Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix 20.0 button dropdown part02 #31217

Conversation

thersane-john
Copy link
Contributor

@thersane-john thersane-john commented Oct 1, 2024

need #31215 PR before

FIX Ajax loaded button or if button was added after dom ready by js

see comment

FIX Abusive Url completion

Dropdown url doesn't work for non core url or javascript url

I have created an anonymous function to factor code during the fix

FIX inconsistent case isDropDown => isDropdown

keep isDropdown not isDropDown because Dropdown is used as a word

@eldy Sorry I can't split this one... the 3 problems are in same part of code.

@eldy
Copy link
Member

eldy commented Oct 3, 2024

I merge manually the fix for 2 of 3 points.
For the last one, the pb to use the function for external modules links, i pushed a different fixes.
Module can provide an url build with buildpath('/monmondule/mapage.php', 1) into 'urlroot' instead of 'url'
This looks better than compensating with js code to fix a bug in php.

@eldy eldy added the Discussion Some questions or discussions are opened and wait answers of author or other people to be processed label Oct 3, 2024
Comment on lines +12295 to +12324
/**
* An anonymous function to complete dropdown url
* @param string $url
* @return string
*/
$completeUrl = function ($url) use ($params) {
if (empty($url)) {
return '';
}

$parsedUrl = parse_url($url);
if (isset($parsedUrl['scheme']) && $parsedUrl['scheme'] === 'javascript') {
return $url;
}

if (!empty($parsedUrl['query'])) {
// Use parse_str() function to parse the string passed via URL
parse_str($parsedUrl['query'], $urlQuery);
if (!isset($urlQuery['backtopage']) && isset($params['backtopage'])) {
$url.= '&backtopage='.urlencode($params['backtopage']);
}
}

// TODO : this is a first fix of button behavior : external module will needs to use http:// or https:// prefix on there Urls
if (!isset($parsedUrl['scheme'])) {
$url = DOL_URL_ROOT.$url;
}

return $url;
};
Copy link
Contributor Author

@thersane-john thersane-john Oct 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@eldy I think you've misunderstood what I mean with this function.
In some case if href attribute of link start with javascript: because a link can have differrent sheme like

  • http:
  • https:
  • javascript:
  • maito: (I doesn't check this one yet)
  • # (I doesn't check this one yet)

but in all cases the code force to add &backtopage= to url. Also the actual dolibarr code doesn't check if query already contain backtopage param.

see this pull request of subtotal module and search javascript: to get a usecase.

to restart on good bases of code, I will recreate 2 separated PRs

  • first to fix ajax loaded BTN
  • secondly to allow deactivation of &backtopage=

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Discussion Some questions or discussions are opened and wait answers of author or other people to be processed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants