2020-05-29 13:41:58 +02:00
|
|
|
<?php
|
|
|
|
/*
|
|
|
|
* Create the action field in a table
|
|
|
|
* - pass a list of actions that will be added as separate icons to the field
|
|
|
|
* - each action can have the following fields setTLDs
|
|
|
|
* - url: url to query
|
|
|
|
* - url_params_data_paths: add dynamic URL elements such as an id to the URL. Can be an array with each value added in a separate param
|
|
|
|
* - title: title of the action. Automatically generates aria labels too
|
|
|
|
* - postLink: convert the button into a POST request
|
|
|
|
* - postLinkConfirm: As the user to confirm the POST before submission with the given message
|
|
|
|
* - onclick: custom onclick action instead of a simple GET/POST request
|
|
|
|
* - onclick_params_data_path: pass a data path param to the onclick field. requires [onclick_params_data_path] in the onclick field
|
|
|
|
* as a needle for replacement
|
|
|
|
* - icon: FA icon (added using the helper, knowing the fa domain is not needed, just add the short name such as "edit")
|
|
|
|
* - requirement evaluates to true/false
|
|
|
|
* - complex_requirement - add complex requirements via lambda functions:
|
|
|
|
* - function($row, $options): the lambda function. $row contain the row data
|
|
|
|
* - options: array of options. datapaths described in the datapath keyname will be extracted and replaced with the actual row value
|
|
|
|
*/
|
|
|
|
echo '<td class="action-links text-right">';
|
|
|
|
foreach ($actions as $action) {
|
|
|
|
if (isset($action['requirement']) && !$action['requirement']) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (isset($action['complex_requirement'])) {
|
|
|
|
if (isset($action['complex_requirement']['options']['datapath'])) {
|
|
|
|
foreach ($action['complex_requirement']['options']['datapath'] as $name => $path) {
|
|
|
|
$action['complex_requirement']['options']['datapath'][$name] = empty($this->Hash->extract($row, $path)[0]) ? null : $this->Hash->extract($row, $path)[0];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$options = isset($action['complex_requirement']['options']) ? $action['complex_requirement']['options'] : array();
|
|
|
|
$requirementMet = $action['complex_requirement']['function']($row, $options);
|
|
|
|
if (!$requirementMet) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$url_param_data_paths = '';
|
2021-05-14 13:31:19 +02:00
|
|
|
$url = empty($action['url']) ? '#' : $baseurl . h($action['url']);
|
2020-05-29 13:41:58 +02:00
|
|
|
if (!empty($action['url_params_data_paths'])) {
|
|
|
|
if (is_array($action['url_params_data_paths'])) {
|
|
|
|
$temp = array();
|
|
|
|
foreach ($action['url_params_data_paths'] as $path) {
|
|
|
|
$temp[] = h(Cake\Utility\Hash::extract($row, $path)[0]);
|
|
|
|
}
|
|
|
|
$url_param_data_paths = implode('/', $temp);
|
|
|
|
} else {
|
|
|
|
$url_param_data_paths = h(Cake\Utility\Hash::extract($row, $action['url_params_data_paths'])[0]);
|
|
|
|
}
|
|
|
|
$url .= '/' . $url_param_data_paths;
|
|
|
|
}
|
|
|
|
if (!empty($action['url_named_params_data_paths'])) {
|
|
|
|
if (is_array($action['url_named_params_data_paths'])) {
|
|
|
|
$temp = array();
|
|
|
|
foreach ($action['url_named_params_data_paths'] as $namedParam => $path) {
|
|
|
|
$temp[] = sprintf('%s:%s', h($namedParam), h($this->Hash->extract($row, $path)[0]));
|
|
|
|
}
|
|
|
|
$url_param_data_paths = implode('/', $temp);
|
|
|
|
}
|
|
|
|
$url .= '/' . $url_param_data_paths;
|
|
|
|
}
|
|
|
|
if (!empty($action['url_extension'])) {
|
|
|
|
$url .= '.' . $action['url_extension'];
|
|
|
|
}
|
|
|
|
if (isset($action['postLink'])) {
|
|
|
|
echo $this->Form->postLink(
|
|
|
|
'',
|
|
|
|
$url,
|
|
|
|
array(
|
2020-06-23 14:26:41 +02:00
|
|
|
'class' => $this->FontAwesome->getClass($action['icon']) . (empty($action['class']) ? '' : h($action['class'])),
|
2020-05-29 13:41:58 +02:00
|
|
|
'title' => empty($action['title']) ? '' : h($action['title']),
|
|
|
|
'aria-label' => empty($action['aria-label']) ? '' : h($action['aria-label']),
|
|
|
|
),
|
|
|
|
empty($action['postLinkConfirm'])? '' : $action['postLinkConfirm']
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
if (!empty($action['onclick']) && !empty($action['onclick_params_data_path'])) {
|
|
|
|
$action['onclick'] = str_replace(
|
|
|
|
'[onclick_params_data_path]',
|
|
|
|
h(Cake\Utility\Hash::extract($row, $action['onclick_params_data_path'])[0]),
|
|
|
|
$action['onclick']
|
|
|
|
);
|
|
|
|
|
2021-01-11 16:28:07 +01:00
|
|
|
} else if (!empty($action['open_modal']) && !empty($action['modal_params_data_path'])) {
|
2021-06-01 07:46:29 +02:00
|
|
|
if (is_array($action['modal_params_data_path'])) {
|
|
|
|
foreach ($action['modal_params_data_path'] as $k => $v) {
|
|
|
|
$modal_url = str_replace(
|
|
|
|
sprintf('{{%s}}', $k),
|
|
|
|
h(Cake\Utility\Hash::extract($row, $v)[0]),
|
|
|
|
$action['open_modal']
|
|
|
|
);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$modal_url = str_replace(
|
|
|
|
'[onclick_params_data_path]',
|
|
|
|
h(Cake\Utility\Hash::extract($row, $action['modal_params_data_path'])[0]),
|
|
|
|
$action['open_modal']
|
|
|
|
);
|
|
|
|
}
|
2021-01-11 16:28:07 +01:00
|
|
|
$reload_url = !empty($action['reload_url']) ? $action['reload_url'] : $this->Url->build(['action' => 'index']);
|
2021-03-10 14:54:52 +01:00
|
|
|
$action['onclick'] = sprintf('UI.submissionModalForIndex(\'%s\', \'%s\', \'%s\')', $modal_url, $reload_url, $tableRandomValue);
|
2020-05-29 13:41:58 +02:00
|
|
|
}
|
|
|
|
echo sprintf(
|
2021-05-14 13:31:19 +02:00
|
|
|
'<a href="%s" title="%s" aria-label="%s" %s %s class="link-unstyled"><i class="%s"></i></a> ',
|
2020-05-29 13:41:58 +02:00
|
|
|
$url,
|
|
|
|
empty($action['title']) ? '' : h($action['title']),
|
|
|
|
empty($action['title']) ? '' : h($action['title']),
|
|
|
|
empty($action['dbclickAction']) ? '' : 'class="dblclickActionElement"',
|
|
|
|
empty($action['onclick']) ? '' : sprintf('onClick="%s"', $action['onclick']),
|
|
|
|
$this->FontAwesome->getClass($action['icon'])
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
echo '</td>';
|
|
|
|
?>
|