new: [UI] indexTable new fields / some refactoring

pull/5727/head
iglocska 2020-03-25 11:43:05 +01:00
parent cf312e78ef
commit 8ff7421721
No known key found for this signature in database
GPG Key ID: BEA224F1FEF113AC
9 changed files with 181 additions and 47 deletions

View File

@ -1,6 +1,6 @@
<?php
echo sprintf(
'<i class="black fa fa-%s"></i>',
(Hash::extract($row, $field['data_path'])[0]) ? 'check' : 'times'
(!empty(Hash::extract($row, $field['data_path'])[0])) ? 'check' : 'times'
);
?>

View File

@ -0,0 +1,26 @@
<?php
$data = Hash::extract($row, $field['data_path']);
if (is_array($data)) {
if (count($data) > 1) {
$data = implode(', ', $data);
} else {
if (count($data) > 0) {
$data = $data[0];
} else {
$data = '';
}
}
}
$data = h($data);
if (is_numeric($data)) {
$data = date('Y-m-d H:i:s', $data);
}
if (!empty($field['onClick'])) {
$data = sprintf(
'<span onClick="%s">%s</span>',
$field['onClick'],
$data
);
}
echo $data;
?>

View File

@ -11,5 +11,13 @@
}
}
}
echo h($data);
$data = h($data);
if (!empty($field['onClick'])) {
$data = sprintf(
'<span onClick="%s">%s</span>',
$field['onClick'],
$data
);
}
echo $data;
?>

View File

@ -0,0 +1,22 @@
<?php
$roles = Hash::extract($row, $field['data_path']);
if (!empty($roles)) {
if (!isset($roles[0])) {
$roles = array($roles);
}
$count = count($roles);
$i = 0;
foreach ($roles as $role) {
$i++;
echo sprintf(
'<a href="%s/roles/view/%s">%s</a>',
$baseurl,
h($role['id']),
h($role['name'])
);
if ($i < $count) {
echo '<br />';
}
}
}
?>

View File

@ -0,0 +1,59 @@
<?php
/*
* Toggle element - a simple checkbox with the current state selected
* On click, issues a GET to a given endpoint, retrieving a form with the
* value flipped, which is immediately POSTed.
* to fetch it.
*
*/
$data = Hash::extract($row, $field['data_path']);
$seed = rand();
$checkboxId = 'GenericToggle-' . $seed;
$tempboxId = 'TempBox-' . $seed;
echo sprintf(
'<input type="checkbox" id="%s" %s><span id="%s" class="hidden">',
$checkboxId,
empty($data[0]) ? '' : 'checked',
$tempboxId
);
?>
<script type="text/javascript">
$(document).ready(function() {
var url = baseurl + "<?= h($field['url']) ?>";
<?php
if (!empty($field['url_params_data_paths'][0])) {
$id = Hash::extract($row, $field['url_params_data_paths'][0]);
echo 'url = url + "/' . h($id[0]) . '";';
}
?>
$('#<?= $checkboxId ?>').on('click', function() {
$.ajax({
type:"get",
url: url,
error:function() {
showMessage('fail', '<?= __('Could not retrieve current state.') ?>.');
},
success: function (data, textStatus) {
$('#<?= $tempboxId ?>').html(data);
// Make @mokaddem aka Graphman happy
var $form = $('#<?= $tempboxId ?>').find('form');
$.ajax({
data: $form.serialize(),
cache: false,
type:"post",
url: $form.attr('action'),
success:function(data, textStatus) {
showMessage('success', '<?= __('Field updated.') ?>.');
},
error:function() {
showMessage('fail', '<?= __('Could not update field.') ?>.');
},
complete:function() {
$('#<?= $tempboxId ?>').empty();
}
});
}
});
});
});
</script>

View File

@ -1,29 +1,31 @@
<?php
$headersHtml = '';
foreach ($fields as $k => $header) {
$header_data = '';
if (!empty($header['sort'])) {
if (!empty($header['name'])) {
$header_data = $paginator->sort($header['sort'], $header['name']);
if (!isset($header['requirement']) || $header['requirement']) {
$header_data = '';
if (!empty($header['sort'])) {
if (!empty($header['name'])) {
$header_data = $paginator->sort($header['sort'], $header['name']);
} else {
$header_data = $paginator->sort($header['sort']);
}
} else {
$header_data = $paginator->sort($header['sort']);
}
} else {
if (!empty($header['element']) && $header['element'] === 'selector') {
$header_data = sprintf(
'<input class="%s" type="checkbox" %s>',
empty($header['select_all_class']) ? 'select_all' : $header['select_all_class'],
empty($header['select_all_function']) ? 'onclick="toggleAllAttributeCheckboxes();"' : 'onclick="' . $header['select_all_function'] . '"'
);
} else {
$header_data = h($header['name']);
}
if (!empty($header['element']) && $header['element'] === 'selector') {
$header_data = sprintf(
'<input class="%s" type="checkbox" %s>',
empty($header['select_all_class']) ? 'select_all' : $header['select_all_class'],
empty($header['select_all_function']) ? 'onclick="toggleAllAttributeCheckboxes();"' : 'onclick="' . $header['select_all_function'] . '"'
);
} else {
$header_data = h($header['name']);
}
}
$headersHtml .= sprintf(
'<th>%s</th>',
$header_data
);
}
$headersHtml .= sprintf(
'<th>%s</th>',
$header_data
);
}
if ($actions) {
$headersHtml .= sprintf(

View File

@ -19,10 +19,13 @@
echo sprintf('<h2>%s</h2>', h($data['title']));
}
if (!empty($data['description'])) {
echo sprintf('<p>%s</p>', h($data['description']));
echo sprintf(
'<div>%s</div>',
empty($data['description']) ? '' : h($data['description'])
);
}
if (!empty($data['html'])) {
echo sprintf('<p>%s</p>', $data['html']);
echo sprintf('<div>%s</div>', $data['html']);
}
$skipPagination = isset($data['skip_pagination']) ? $data['skip_pagination'] : 0;
if (!$skipPagination) {

View File

@ -1,31 +1,33 @@
<?php
$rowHtml = '';
foreach ($fields as $column => $field) {
if (empty($field['element'])) {
$valueField = $this->element('/genericElements/IndexTable/Fields/generic_field', array('field' => $field, 'row' => $row, 'data_path' => empty($field['data_path']) ? '' : $field['data_path'], 'k' => $k, 'column' => $column));
} else {
$valueField = $this->element(
'/genericElements/IndexTable/Fields/' . $field['element'],
array(
'field' => $field,
'row' => $row,
'column' => $column,
'data_path' => empty($field['data_path']) ? '' : $field['data_path'],
'k' => $k
)
if (!isset($field['requirement']) || $field['requirement']) {
if (empty($field['element'])) {
$valueField = $this->element('/genericElements/IndexTable/Fields/generic_field', array('field' => $field, 'row' => $row, 'data_path' => empty($field['data_path']) ? '' : $field['data_path'], 'k' => $k, 'column' => $column));
} else {
$valueField = $this->element(
'/genericElements/IndexTable/Fields/' . $field['element'],
array(
'field' => $field,
'row' => $row,
'column' => $column,
'data_path' => empty($field['data_path']) ? '' : $field['data_path'],
'k' => $k
)
);
}
$rowHtml .= sprintf(
'<td%s%s%s%s%s%s%s>%s</td>',
(empty($field['id'])) ? '' : sprintf('id="%s"', $field['id']),
(empty($field['class'])) ? '' : sprintf(' class="%s"', $field['class']),
(empty($field['style'])) ? '' : sprintf(' style="%s"', $field['style']),
(empty($field['title'])) ? '' : sprintf(' title="%s"', $field['title']),
(empty($field['name'])) ? '' : sprintf(' data-path="%s"', (h($field['data_path']))),
(empty($field['encode_raw_value']) || empty($field['data_path'])) ? '' : sprintf(' data-value="%s"', (h(Hash::extract($row, $field['data_path'])[0]))),
(empty($field['ondblclick'])) ? '' : sprintf(' ondblclick="%s"', $field['ondblclick']),
$valueField
);
}
$rowHtml .= sprintf(
'<td%s%s%s%s%s%s%s>%s</td>',
(empty($field['id'])) ? '' : sprintf('id="%s"', $field['id']),
(empty($field['class'])) ? '' : sprintf(' class="%s"', $field['class']),
(empty($field['style'])) ? '' : sprintf(' style="%s"', $field['style']),
(empty($field['title'])) ? '' : sprintf(' title="%s"', $field['title']),
(empty($field['name'])) ? '' : sprintf(' data-path="%s"', (h($field['data_path']))),
(empty($field['encode_raw_value']) || empty($field['data_path'])) ? '' : sprintf(' data-value="%s"', (h(Hash::extract($row, $field['data_path'])[0]))),
(empty($field['ondblclick'])) ? '' : sprintf(' ondblclick="%s"', $field['ondblclick']),
$valueField
);
}
if (!empty($actions)) {
$rowHtml .= $this->element(

View File

@ -0,0 +1,12 @@
<?php
/*
* Simple form to fetch/submit for toggle endpoints
* Takes the current state and reverses it.
* It is expected to be POSTed to the same endpoint as used by the GET request
* to fetch it.
*
*/
echo $this->Form->create();
echo $this->Form->input('value', array('default' => ($data ? 0 : 1)));
echo $this->Form->end();
?>