From 1a330e0b887657c4d9a1596b84979c2508d52c01 Mon Sep 17 00:00:00 2001 From: ATM john Date: Wed, 14 Jul 2021 00:02:55 +0200 Subject: [PATCH 1/2] Fix dialog BTN and add doc --- htdocs/core/js/lib_foot.js.php | 13 +- htdocs/core/lib/functions.lib.php | 5 +- htdocs/public/test/badges.php | 21 +--- htdocs/public/test/buttons.php | 196 ++++++++++++++++++++++++++++++ 4 files changed, 214 insertions(+), 21 deletions(-) create mode 100644 htdocs/public/test/buttons.php diff --git a/htdocs/core/js/lib_foot.js.php b/htdocs/core/js/lib_foot.js.php index beb2788ca24..00f161a31ef 100644 --- a/htdocs/core/js/lib_foot.js.php +++ b/htdocs/core/js/lib_foot.js.php @@ -263,6 +263,8 @@ print '$( document ).ready(function() { var confirmContent = $(this).attr(\'data-confirm-content\'); var confirmActionBtnLabel = $(this).attr(\'data-confirm-action-btn-label\'); var confirmCancelBtnLabel = $(this).attr(\'data-confirm-cancel-btn-label\'); + var confirmModal = $(this).attr(\'data-confirm-modal\'); + if(confirmModal == undefined){ confirmModal = false; } var confirmId = \'confirm-dialog-box\'; if($(this).attr(\'id\') != undefined){ var confirmId = confirmId + "-" + $(this).attr(\'id\'); } @@ -277,8 +279,9 @@ print '$( document ).ready(function() { $confirmBox.dialog({ autoOpen: true, - modal: false, + modal: confirmModal, //width: Math.min($( window ).width() - 50, 1700), + width: \'auto\', dialogClass: \'confirm-dialog-box\', buttons: [ { @@ -297,11 +300,11 @@ print '$( document ).ready(function() { } ], close: function( event, ui ) { - $(\'#\'+confirmBox).remove(); -}, + $(\'#\'+confirmBox).remove(); + }, open: function( event, ui ) { - $confirmBox.html(confirmContent); -} + $confirmBox.html(confirmContent); + } }); }); }); diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index 7f69dfb8609..9107f9514e4 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -9818,7 +9818,7 @@ function dolGetButtonAction($label, $html = '', $actionType = 'default', $url = } // Js Confirm button - if (!empty($params['confirm'])) { + if ($userRight && !empty($params['confirm'])) { if (!is_array($params['confirm'])) { $params['confirm'] = array( 'url' => $url . (strpos($url, '?') > 0 ? '&' : '?') . 'confirm=yes' @@ -9829,8 +9829,11 @@ function dolGetButtonAction($label, $html = '', $actionType = 'default', $url = $attr['data-confirm-url'] = $params['confirm']['url']; $attr['data-confirm-title'] = !empty($params['confirm']['title']) ? $params['confirm']['title'] : $langs->trans('ConfirmBtnCommonTitle', $label); $attr['data-confirm-content'] = !empty($params['confirm']['content']) ? $params['confirm']['content'] : $langs->trans('ConfirmBtnCommonContent', $label); + $attr['data-confirm-content'] = preg_replace("/\r|\n/", "", $attr['data-confirm-content']); $attr['data-confirm-action-btn-label'] = !empty($params['confirm']['action-btn-label']) ? $params['confirm']['action-btn-label'] : $langs->trans('Confirm'); $attr['data-confirm-cancel-btn-label'] = !empty($params['confirm']['cancel-btn-label']) ? $params['confirm']['cancel-btn-label'] : $langs->trans('CloseDialog'); + $attr['data-confirm-modal'] = !empty($params['confirm']['modal']) ? $params['confirm']['modal'] : true; + $attr['class'].= ' butActionConfirm'; } diff --git a/htdocs/public/test/badges.php b/htdocs/public/test/badges.php index fd0add00af1..2190b96db7e 100644 --- a/htdocs/public/test/badges.php +++ b/htdocs/public/test/badges.php @@ -20,7 +20,9 @@ if (!defined('NOREQUIREAJAX')) { if (!defined('NOSESSION')) { define('NOSESSION', '1'); } - +if (!defined('NOREQUIREMENU')) { + define('NOREQUIREMENU', '1'); +} session_cache_limiter('public'); require_once '../../main.inc.php'; @@ -30,19 +32,9 @@ if ($dolibarr_main_prod) { accessforbidden(); } + +llxHeader('', 'Documentation and examples for theme'); ?> - - - - - - - - - - - -

Badges

Documentation and examples for badges, our small count and labeling component.

@@ -342,5 +334,4 @@ if ($dolibarr_main_prod) {
- - \ No newline at end of file + +
+

Button for action

+

Documentation and examples for buttons.

+ +

Example of simple usage

+ +

Buttons for user allowed to click.

+ +
+ My default action'; + $actionType = 'default'; + $n++; + $id = 'mybuttonid'.$n; + $url = '#'.$id; + $userRight = 1; + $params = array(); + + print dolGetButtonAction($label, $html, $actionType, $url, $id, $userRight); + + + $html = ' My delete action'; + $actionType = 'delete'; + $n++; + $id = 'mybuttonid'.$n; + $url = $_SERVER['PHP_SELF'] . '?token='.newToken().'#'.$id; + print dolGetButtonAction($label, $html, $actionType, $url, $id, $userRight); + + + $html = ' My danger action'; + $actionType = 'danger'; + $n++; + $id = 'mybuttonid'.$n; + $url = $_SERVER['PHP_SELF'] . '?token='.newToken().'#'.$id; + print dolGetButtonAction($label, $html, $actionType, $url, $id, $userRight); + + ?> +
+ +

Buttons for user NOT allowed to click.

+ +
+ My default action'; + $actionType = 'default'; + $n++; + $id = 'mybuttonid'.$n; + $url = '#'.$id; + $userRight = 0; + + print dolGetButtonAction($label, $html, $actionType, $url, $id, $userRight); + + + $html = ' My delete action'; + $actionType = 'delete'; + $n++; + $id = 'mybuttonid'.$n; + $url = $_SERVER['PHP_SELF'] . '?token='.newToken().'#'.$id; + print dolGetButtonAction($label, $html, $actionType, $url, $id, $userRight); + + + $html = ' My danger action'; + $actionType = 'danger'; + $n++; + $id = 'mybuttonid'.$n; + $url = $_SERVER['PHP_SELF'] . '?token='.newToken().'#'.$id; + print dolGetButtonAction($label, $html, $actionType, $url, $id, $userRight); + + ?> +
+ + +

Example of confirm dialog

+ +

Buttons for user allowed to click.

+ +
+ My default action'; + $actionType = 'default'; + $n++; + $id = 'mybuttonid'.$n; + $url = '#'.$id; + $userRight = 1; + $params = array( + 'confirm' => true + ); + + print dolGetButtonAction($label, $html, $actionType, $url, $id, $userRight, $params); + + + $html = ' My delete action'; + $actionType = 'delete'; + $n++; + $id = 'mybuttonid'.$n; + $url = $_SERVER['PHP_SELF'] . '?token='.newToken().'#'.$id; + + $params = array( + 'confirm' => array( + 'url' => 'your confirm action url', + 'title' => 'Your title to display', + 'action-btn-label' => 'Your confirm label', + 'cancel-btn-label' => 'Your cancel label', + 'content' => 'Content to display with HTML compatible
  • test 01
  • test 02
  • test 03
' + ) + ); + + print dolGetButtonAction($label, $html, $actionType, $url, $id, $userRight, $params); + + ?> +
+ +

Buttons for user NOT allowed to click.

+ +
+ My default action'; + $actionType = 'default'; + $n++; + $id = 'mybuttonid'.$n; + $url = '#'.$id; + $userRight = 0; + $params = array( + 'confirm' => true + ); + + print dolGetButtonAction($label, $html, $actionType, $url, $id, $userRight, $params); + + + $html = ' My delete action'; + $actionType = 'delete'; + $n++; + $id = 'mybuttonid'.$n; + $url = $_SERVER['PHP_SELF'] . '?token='.newToken().'#'.$id; + + $params = array( + 'confirm' => array( + 'url' => 'your confirm action url', + 'title' => 'Your title to display', + 'action-btn-label' => 'Your confirm label', + 'cancel-btn-label' => 'Your cancel label', + 'content' => 'Content to display with HTML compatible
  • test 01
  • test 02
  • test 03
' + ) + ); + + print dolGetButtonAction($label, $html, $actionType, $url, $id, $userRight, $params); + + ?> +
+ + +
+ + Date: Wed, 14 Jul 2021 10:07:03 +0200 Subject: [PATCH 2/2] Add php doc --- htdocs/core/lib/functions.lib.php | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index 9107f9514e4..26da9ee3d21 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -9770,7 +9770,23 @@ function dolGetStatus($statusLabel = '', $statusLabelShort = '', $html = '', $st * @param string $url the url for link * @param string $id attribute id of button * @param int $userRight user action right - * @param array $params various params for future : recommended rather than adding more function arguments + * // phpcs:disable + * @param array $params = [ // Various params for future : recommended rather than adding more function arguments + * 'attr' => [ // to add or override button attributes + * 'xxxxx' => '', // your xxxxx attribute you want + * 'class' => '', // to add more css class to the button class attribute + * 'classOverride' => '' // to replace class attribute of the button + * ], + * 'confirm' => [ + * 'url' => 'http://', // Overide Url to go when user click on action btn, if empty default url is $url.?confirm=yes, for no js compatibility use $url for fallback confirm. + * 'title' => '', // Overide title of modal, if empty default title use "ConfirmBtnCommonTitle" lang key + * 'action-btn-label' => '', // Overide label of action button, if empty default label use "Confirm" lang key + * 'cancel-btn-label' => '', // Overide label of cancel button, if empty default label use "CloseDialog" lang key + * 'content' => '', // Overide text of content, if empty default content use "ConfirmBtnCommonContent" lang key + * 'modal' => true, // true|false to display dialog as a modal (with dark background) + * ], + * ] + * // phpcs:enable * @return string html button */ function dolGetButtonAction($label, $html = '', $actionType = 'default', $url = '', $id = '', $userRight = 1, $params = array())