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

Open
wants to merge 4 commits into
base: 20.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion htdocs/core/js/lib_head.js.php
Original file line number Diff line number Diff line change
Expand Up @@ -1321,7 +1321,7 @@ function price2numjs(amount) {


jQuery(document).ready(function() {
jQuery(".butAction.dropdown-toggle").on("click", function(event) {
jQuery(document).on("click", ".butAction.dropdown-toggle", function(event) {
Copy link
Contributor Author

@thersane-john thersane-john Oct 1, 2024

Choose a reason for hiding this comment

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

This fix ajax loaded button.

console.log("Click on .butAction.dropdown-toggle");
var parentholder = jQuery(".butAction.dropdown-toggle").closest(".dropdown");
var offset = parentholder.offset();
Expand Down
48 changes: 40 additions & 8 deletions htdocs/core/lib/functions.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -12291,6 +12291,34 @@

// If $url is an array, we must build a dropdown button or recursively iterate over each value
if (is_array($url)) {
// An anonymous function to complette dropdown url

Check failure on line 12294 in htdocs/core/lib/functions.lib.php

View workflow job for this annotation

GitHub Actions / pre-commit / pre-commit

complette ==> complete
$completeUrl = function ($url) use ($params) {

Check warning on line 12295 in htdocs/core/lib/functions.lib.php

View workflow job for this annotation

GitHub Actions / phan / Run phan

functions.lib.php: PhanPluginUnknownClosureParamType: Closure Closure($url) has no declared or inferred parameter type for $url (Types inferred after analysis: string)

Check warning on line 12295 in htdocs/core/lib/functions.lib.php

View workflow job for this annotation

GitHub Actions / phan / Run phan

functions.lib.php: PhanPluginUnknownClosureReturnType: Closure Closure($url) has no declared or inferred return type (Types inferred after analysis: non-empty-mixed|string)
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;
};


// Loop on $url array to remove entries of disabled modules
foreach ($url as $key => $subbutton) {
if (isset($subbutton['enabled']) && empty($subbutton['enabled'])) {
Expand All @@ -12309,15 +12337,17 @@
$text = $button['text'] ?? '';
$actionType = $button['actionType'] ?? '';
$tmpUrl = DOL_URL_ROOT.$button['url'].(empty($params['backtopage']) ? '' : '&backtopage='.urlencode($params['backtopage']));
$id = $button['$id'] ?? '';
$id = $button['id'] ?? '';
$userRight = $button['perm'] ?? 1;
$params = $button['$params'] ?? [];
$button['params'] = $button['params'] ?? [];

$out .= dolGetButtonAction($label, $text, $actionType, $tmpUrl, $id, $userRight, $params);
$out .= dolGetButtonAction($label, $text, $actionType, $tmpUrl, $id, $userRight, $button['params']);
}
return $out;
}



if (count($url) > 1) {
$out .= '<div class="dropdown inline-block dropdown-holder">';
$out .= '<a style="margin-right: auto;" class="dropdown-toggle classfortooltip butAction'.($userRight ? '' : 'Refused').'" title="'.dol_escape_htmltag($label).'" data-toggle="dropdown">'.($text ? $text : $label).'</a>';
Expand All @@ -12326,8 +12356,12 @@
if (!empty($subbutton['lang'])) {
$langs->load($subbutton['lang']);
}
$tmpurl = DOL_URL_ROOT.$subbutton['url'].(empty($params['backtopage']) ? '' : '&amp;backtopage='.urlencode($params['backtopage']));
$out .= dolGetButtonAction('', $langs->trans($subbutton['label']), 'default', $tmpurl, '', $subbutton['perm'], array('isDropDown' => true));

if (!isset($subbutton['params'])) {
$subbutton['params'] = array();
}
$subbutton['params']['isDropdown'] = true;
$out .= dolGetButtonAction('', $langs->trans($subbutton['label']), 'default', $completeUrl($subbutton['url']), $subbutton['id'] ?? '', $subbutton['perm'], $subbutton['params']);
}
$out .= "</div>";
$out .= "</div>";
Expand All @@ -12336,16 +12370,14 @@
if (!empty($subbutton['lang'])) {
$langs->load($subbutton['lang']);
}
$tmpurl = DOL_URL_ROOT.$subbutton['url'].(empty($params['backtopage']) ? '' : '&amp;backtopage='.urlencode($params['backtopage']));
$out .= dolGetButtonAction('', $langs->trans($subbutton['label']), 'default', $tmpurl, '', $subbutton['perm']);
$out .= dolGetButtonAction('', $langs->trans($subbutton['label']), 'default', $completeUrl($subbutton['url']), '', $subbutton['perm']);
}
}

return $out;
}

// Here, $url is a simple link

if (!empty($params['isDropdown'])) {
$class = "dropdown-item";
} else {
Expand Down
Loading