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

@@ -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;
}
}
/**