Merge pull request #18147 from atm-john/fix_dialog_btn

Fix : dialog BTN and add doc
This commit is contained in:
Laurent Destailleur 2021-07-14 13:53:41 +02:00 committed by GitHub
commit a88ab8e443
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 231 additions and 22 deletions

View File

@ -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);
}
});
});
});

View File

@ -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())
@ -9818,7 +9834,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 +9845,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';
}

View File

@ -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');
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="description" content="Documentation and examples for theme.">
<link href="<?php echo DOL_URL_ROOT ?>/theme/eldy/style.css.php" rel="stylesheet">
</head>
<body class="docpage" style="padding: 20px;">
<main role="main" >
<h1 class="bd-title" id="content">Badges</h1>
<p class="bd-lead">Documentation and examples for badges, our small count and labeling component.</p>
@ -342,5 +334,4 @@ if ($dolibarr_main_prod) {
</main>
</body>
</html>
<?php llxFooter();

View File

@ -0,0 +1,196 @@
<?php
if (!defined('NOREQUIRESOC')) {
define('NOREQUIRESOC', '1');
}
if (!defined('NOCSRFCHECK')) {
define('NOCSRFCHECK', 1);
}
if (!defined('NOTOKENRENEWAL')) {
define('NOTOKENRENEWAL', 1);
}
if (!defined('NOLOGIN')) {
define('NOLOGIN', 1); // File must be accessed by logon page so without login
}
if (!defined('NOREQUIREHTML')) {
define('NOREQUIREHTML', 1);
}
if (!defined('NOREQUIREAJAX')) {
define('NOREQUIREAJAX', '1');
}
if (!defined('NOSESSION')) {
define('NOSESSION', '1');
}
if (!defined('NOREQUIREMENU')) {
define('NOREQUIREMENU', '1');
}
session_cache_limiter('public');
require_once '../../main.inc.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/functions.lib.php';
if ($dolibarr_main_prod) {
accessforbidden();
}
llxHeader('', 'Documentation and examples for theme');
?>
<main role="main" >
<h1 class="bd-title" id="content">Button for action</h1>
<p class="bd-lead">Documentation and examples for buttons.</p>
<h2 id="example01">Example of simple usage</h2>
<p>Buttons for user allowed to click.</p>
<div class="bd-example">
<?php
$n = 1;
$label = 'My action label used for accessibility visually for impaired people';
$html = '<span class="fa fa-clone" ></span> My default action';
$actionType = 'default';
$n++;
$id = 'mybuttonid'.$n;
$url = '#'.$id;
$userRight = 1;
$params = array();
print dolGetButtonAction($label, $html, $actionType, $url, $id, $userRight);
$html = '<span class="fa fa-clone" ></span> 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 = '<span class="fa fa-clone" ></span> My danger action';
$actionType = 'danger';
$n++;
$id = 'mybuttonid'.$n;
$url = $_SERVER['PHP_SELF'] . '?token='.newToken().'#'.$id;
print dolGetButtonAction($label, $html, $actionType, $url, $id, $userRight);
?>
</div>
<p>Buttons for user <strong>NOT</strong> allowed to click.</p>
<div class="bd-example">
<?php
$label = 'My action label used for accessibility visually for impaired people';
$html = '<span class="fa fa-clone" ></span> My default action';
$actionType = 'default';
$n++;
$id = 'mybuttonid'.$n;
$url = '#'.$id;
$userRight = 0;
print dolGetButtonAction($label, $html, $actionType, $url, $id, $userRight);
$html = '<span class="fa fa-clone" ></span> 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 = '<span class="fa fa-clone" ></span> My danger action';
$actionType = 'danger';
$n++;
$id = 'mybuttonid'.$n;
$url = $_SERVER['PHP_SELF'] . '?token='.newToken().'#'.$id;
print dolGetButtonAction($label, $html, $actionType, $url, $id, $userRight);
?>
</div>
<h2 id="example01">Example of confirm dialog</h2>
<p>Buttons for user allowed to click.</p>
<div class="bd-example">
<?php
$label = 'My action label used for accessibility visually for impaired people';
$html = '<span class="fa fa-clone" ></span> 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 = '<span class="fa fa-clone" ></span> 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 <strong>HTML</strong> compatible <ul><li>test 01</li><li>test 02</li><li>test 03</li></ul>'
)
);
print dolGetButtonAction($label, $html, $actionType, $url, $id, $userRight, $params);
?>
</div>
<p>Buttons for user <strong>NOT</strong> allowed to click.</p>
<div class="bd-example">
<?php
$label = 'My action label used for accessibility visually for impaired people';
$html = '<span class="fa fa-clone" ></span> 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 = '<span class="fa fa-clone" ></span> 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 <strong>HTML</strong> compatible <ul><li>test 01</li><li>test 02</li><li>test 03</li></ul>'
)
);
print dolGetButtonAction($label, $html, $actionType, $url, $id, $userRight, $params);
?>
</div>
</main>
<?php llxFooter();