2020-05-29 13:41:58 +02:00
|
|
|
<?php
|
|
|
|
/*
|
|
|
|
* create single view child index
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
$randomId = Cake\Utility\Security::randomString(8);
|
2020-06-21 21:34:15 +02:00
|
|
|
if (!empty($child['url_params'])) {
|
|
|
|
if (!is_array($child['url_params'])) {
|
|
|
|
$child['url_params'] = [$child['url_params']];
|
|
|
|
}
|
|
|
|
foreach ($child['url_params'] as $i => $url_param) {
|
|
|
|
$child['url'] = str_replace('{{' . $i . '}}', $this->Hash->extract($data, $url_param)[0], $child['url']);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
echo sprintf(
|
|
|
|
'<div class="card">%s%s</div>',
|
2020-05-29 13:41:58 +02:00
|
|
|
sprintf(
|
|
|
|
'<div class="card-header" id="heading-%s"><h5 class="mb0">%s</h5></div>',
|
|
|
|
$randomId,
|
|
|
|
sprintf(
|
2021-09-17 13:04:37 +02:00
|
|
|
'<button class="btn btn-link" data-bs-toggle="collapse" data-bs-target="#view-child-%s" aria-expanded="true" aria-controls="collapseOne">%s</button>',
|
2020-06-21 21:34:15 +02:00
|
|
|
$randomId,
|
|
|
|
h($child['title'])
|
2020-05-29 13:41:58 +02:00
|
|
|
)
|
|
|
|
),
|
|
|
|
sprintf(
|
2021-09-17 13:04:37 +02:00
|
|
|
'<div class="collapse %s" id="view-child-%s" data-bs-parent="#accordion" labelledby="heading-%s"><div id="view-child-body-%s" class="card-body" data-content-url="%s" data-load-on="%s"></div></div>',
|
2020-06-21 21:34:15 +02:00
|
|
|
!empty($child['collapsed']) ? 'show' : 'collapsed',
|
2020-05-29 13:41:58 +02:00
|
|
|
$randomId,
|
|
|
|
$randomId,
|
2020-06-21 21:34:15 +02:00
|
|
|
$randomId,
|
|
|
|
h($child['url']),
|
|
|
|
empty($child['loadOn']) ? 'ready' : h($child['loadOn'])
|
|
|
|
)
|
2020-05-29 13:41:58 +02:00
|
|
|
);
|
2020-06-21 21:34:15 +02:00
|
|
|
?>
|
|
|
|
<script type="text/javascript">
|
|
|
|
$(document).ready(function() {
|
|
|
|
var url = $('#view-child-body-<?= h($randomId) ?>').data('content-url');
|
|
|
|
var loadon = $('#view-child-body-<?= h($randomId) ?>').data('load-on');
|
|
|
|
if (loadon === 'ready') {
|
|
|
|
$.ajax({
|
|
|
|
success:function (data, textStatus) {
|
|
|
|
$('#view-child-body-<?= h($randomId) ?>').html(data);
|
|
|
|
},
|
|
|
|
type: "get",
|
|
|
|
cache: false,
|
|
|
|
url: url,
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
$('#view-child-<?= h($randomId) ?>').on('hidden.bs.collapse', function () {
|
|
|
|
$.ajax({
|
|
|
|
success:function (data, textStatus) {
|
|
|
|
$('#view-child-body-<?= h($randomId) ?>').html(data);
|
|
|
|
},
|
|
|
|
type: "get",
|
|
|
|
cache: false,
|
|
|
|
url: url,
|
|
|
|
});
|
|
|
|
})
|
|
|
|
}
|
|
|
|
});
|
|
|
|
</script>
|