2
0
forked from Wavyzz/dolibarr

Add modal option to btn

This commit is contained in:
ATM john
2021-07-04 22:59:53 +02:00
parent d1c6a9899c
commit a709cc583f
4 changed files with 100 additions and 3 deletions

View File

@@ -245,3 +245,59 @@ print 'jQuery(\'.clipboardCPButton, .clipboardCPValueToPrint\').click(function()
lastchild.innerHTML = \''.dol_escape_js($langs->trans('CopiedToClipboard')).'\';
setTimeout(() => { lastchild.innerHTML = tmp; }, 1000);
})'."\n";
print "\n/* JS CODE TO ENABLE ClipBoard copy paste*/\n";
print '$( document ).ready(function() {
$(document).on("click", \'.butActionConfirm\', function(event) {
event.preventDefault();
// I don\'t use jquery $(this).data(\'confirm-url\'); to get $(this).attr(\'data-confirm-url\'); because .data() can doesn\'t work with ajax
var confirmUrl = $(this).attr(\'data-confirm-url\');
var confirmTitle = $(this).attr(\'data-confirm-title\');
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 confirmId = \'confirm-dialog-box\';
if($(this).attr(\'id\') != undefined){ var confirmId = confirmId + "-" + $(this).attr(\'id\'); }
if($("#" + confirmId) != undefined) { $(\'#\' + confirmId).remove(); }
// Create modal box
var $confirmBox = $(\'<div/>\', {
id: confirmId,
title: confirmTitle
}).appendTo(\'body\');
$confirmBox.dialog({
autoOpen: true,
modal: false,
//width: Math.min($( window ).width() - 50, 1700),
dialogClass: \'confirm-dialog-box\',
buttons: [
{
text: confirmActionBtnLabel,
"class": \'ui-state-information\',
click: function () {
window.location.replace(confirmUrl);
}
},
{
text: confirmCancelBtnLabel,
"class": \'ui-state-information\',
click: function () {
$(this).dialog("close");
}
}
],
close: function( event, ui ) {
$(\'#\'+confirmBox).remove();
},
open: function( event, ui ) {
$confirmBox.html(confirmContent);
}
});
});
});
'."\n";

View File

@@ -9734,6 +9734,8 @@ function dolGetStatus($statusLabel = '', $statusLabelShort = '', $html = '', $st
*/
function dolGetButtonAction($label, $html = '', $actionType = 'default', $url = '', $id = '', $userRight = 1, $params = array())
{
global $hookmanager, $action, $object, $langs;
$class = 'butAction';
if ($actionType == 'danger' || $actionType == 'delete') {
$class = 'butActionDelete';
@@ -9774,12 +9776,21 @@ function dolGetButtonAction($label, $html = '', $actionType = 'default', $url =
}
}
// Js Confirm button
if (!empty($params['confirm']) && is_array($params['confirm']) && !empty($params['confirm']['url'])) {
// for js desabled compatibility set $url as call to confirm action and $params['confirm']['url'] to confirmed action
$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-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['class'].= ' butActionConfirm';
}
if (isset($attr['href']) && empty($attr['href'])) {
unset($attr['href']);
}
// TODO : add a hook
// escape all attribute
$attr = array_map('dol_escape_htmltag', $attr);
@@ -9792,7 +9803,29 @@ function dolGetButtonAction($label, $html = '', $actionType = 'default', $url =
$tag = !empty($attr['href']) ? 'a' : 'span';
return '<'.$tag.' '.$compiledAttributes.'>'.$html.'</'.$tag.'>';
$parameters = array(
'TCompiledAttr' => $TCompiledAttr,
'compiledAttributes' => $compiledAttributes,
'attr' => $attr,
'tag' => $tag,
'label' => $label,
'html' => $html,
'actionType' => $actionType,
'url' => $url,
'id' => $id,
'userRight' => $userRight,
'params' => $params
);
$reshook = $hookmanager->executeHooks('dolGetButtonAction', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
if (empty($reshook)) {
return '<' . $tag . ' ' . $compiledAttributes . '>' . $html . '</' . $tag . '>';
} else {
return $hookmanager->resPrint;
}
}
/**

View File

@@ -291,3 +291,7 @@ PopuCom=Products/Services by popularity in Orders
ProductStatistics=Products/Services Statistics
NbOfQtyInOrders=Qty in orders
SelectTheTypeOfObjectToAnalyze=Select an object to view its statistics...
ConfirmBtnCommonContent = Are you sure you want to "%s" ?
ConfirmBtnCommonTitle = Confirm your action
CloseDialog = Close

View File

@@ -291,3 +291,7 @@ PopuCom=Produits/services par popularité dans les commandes
ProductStatistics=Statistiques sur les produits / services
NbOfQtyInOrders=Qté en commandes
SelectTheTypeOfObjectToAnalyze=Sélectionner un objet pour en voir les statistiques
ConfirmBtnCommonContent = Êtes-vous sûr de vouloir : "%s" ?
ConfirmBtnCommonTitle = Confirmez votre action
CloseDialog = Fermer