2021-12-08 11:11:46 +01:00
|
|
|
<?php
|
2021-12-14 15:09:40 +01:00
|
|
|
$create_new_allowed = true;
|
2023-02-14 14:42:35 +01:00
|
|
|
$update_allowed = true;
|
2021-12-14 15:09:40 +01:00
|
|
|
$delete_all_allowed = false;
|
2023-02-14 14:42:35 +01:00
|
|
|
$totalAllowed = $create_new_allowed + $update_allowed + $delete_all_allowed;
|
|
|
|
$maxWidth = 99 - ($create_new_allowed ? 33 : 0) - ($update_allowed ? 33 : 0) - ($delete_all_allowed ? 33 : 0);
|
|
|
|
$defaultStrategy = 'update_existing';
|
2021-12-14 15:09:40 +01:00
|
|
|
|
2021-12-08 11:11:46 +01:00
|
|
|
$form = $this->element('genericElements/Form/genericForm', [
|
|
|
|
'entity' => null,
|
|
|
|
'ajax' => false,
|
|
|
|
'raw' => true,
|
|
|
|
'data' => [
|
|
|
|
'model' => 'MetaTemplate',
|
|
|
|
'fields' => [
|
|
|
|
[
|
|
|
|
'field' => 'update_strategy',
|
|
|
|
'type' => 'radio',
|
|
|
|
'options' => [
|
2021-12-14 15:09:40 +01:00
|
|
|
['value' => 'create_new', 'text' => 'create_new', 'id' => 'radio_create_new'],
|
2023-02-14 14:42:35 +01:00
|
|
|
['value' => 'update_existing', 'text' => 'update', 'id' => 'radio_update'],
|
2021-12-08 11:11:46 +01:00
|
|
|
['value' => 'delete', 'text' => 'delete', 'id' => 'radio_delete'],
|
|
|
|
],
|
|
|
|
]
|
|
|
|
],
|
|
|
|
'submit' => [
|
|
|
|
'action' => $this->request->getParam('action')
|
|
|
|
],
|
|
|
|
]
|
|
|
|
]);
|
|
|
|
?>
|
|
|
|
|
|
|
|
<div class="conflict-resolution-picker">
|
2021-12-01 11:01:31 +01:00
|
|
|
<div class="mt-3 d-flex justify-content-center">
|
|
|
|
<div class="btn-group justify-content-center" role="group" aria-label="Basic radio toggle button group">
|
2021-12-14 15:09:40 +01:00
|
|
|
<?php if ($create_new_allowed) : ?>
|
2023-02-14 14:42:35 +01:00
|
|
|
<input type="radio" class="btn-check" name="btnradio" id="btnradio1" autocomplete="off" value="create_new" <?= $defaultStrategy == 'create_new' ? 'checked' : '' ?>>
|
|
|
|
<label class="btn btn-outline-warning mw-<?= $maxWidth ?>" for="btnradio1">
|
2021-12-14 15:09:40 +01:00
|
|
|
<div>
|
2023-02-14 14:42:35 +01:00
|
|
|
<h5 class="mb-3">
|
|
|
|
<?= $defaultStrategy == 'create_new' ? $this->Bootstrap->badge(['text' => 'recommended', 'variant' => 'success', 'class' => ['mb-3', 'fs-8']]) : '' ?>
|
|
|
|
<?= __('Create new template') ?>
|
|
|
|
</h5>
|
2021-12-14 15:09:40 +01:00
|
|
|
<ul class="text-start fs-7">
|
|
|
|
<li><?= __('A new meta-template will be created and made default.') ?></li>
|
|
|
|
<li><?= __('The old meta-template will remain untouched.') ?></li>
|
|
|
|
<li><?= __('Migration of meta-fields to this newer template can be done manually via the UI.') ?></li>
|
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
</label>
|
|
|
|
<?php endif; ?>
|
|
|
|
|
2023-02-14 14:42:35 +01:00
|
|
|
<?php if ($update_allowed) : ?>
|
|
|
|
<input type="radio" class="btn-check" name="btnradio" id="btnradio2" autocomplete="off" value="update_existing" <?= $defaultStrategy == 'update_existing' ? 'checked' : '' ?>>
|
|
|
|
<label class="btn btn-outline-primary mw-<?= $maxWidth ?>" for="btnradio2">
|
2021-12-14 15:09:40 +01:00
|
|
|
<div>
|
2023-02-14 14:42:35 +01:00
|
|
|
<div><?= $defaultStrategy == 'update_existing' ? $this->Bootstrap->badge(['text' => 'recommended', 'variant' => 'success', 'class' => ['mb-3']]) : '' ?></div>
|
|
|
|
<h5 class="mb-3">
|
|
|
|
<?= __('Update non-conflicting') ?>
|
|
|
|
</h5>
|
2021-12-14 15:09:40 +01:00
|
|
|
<ul class="text-start fs-7">
|
2023-02-14 14:42:35 +01:00
|
|
|
<li><?= __('Entities not having conflicts will have their meta-fields migrated to the new meta-template.') ?></li>
|
|
|
|
<li><?= __('Entities having a conflicts will stay on their current meta-template.') ?></li>
|
2021-12-14 15:09:40 +01:00
|
|
|
<li><?= __('Conflicts can be taken care of manually via the UI.') ?></li>
|
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
</label>
|
|
|
|
<?php endif; ?>
|
2021-12-01 11:01:31 +01:00
|
|
|
|
2021-12-14 15:09:40 +01:00
|
|
|
<?php if ($delete_all_allowed) : ?>
|
2023-02-14 14:42:35 +01:00
|
|
|
<input type="radio" class="btn-check" name="btnradio" id="btnradio3" autocomplete="off" value="delete" <?= $defaultStrategy == 'delete' ? 'checked' : '' ?>>
|
2021-12-14 15:09:40 +01:00
|
|
|
<label class="btn btn-outline-danger mw-<?= $maxWidth ?>" for="btnradio3">
|
|
|
|
<div>
|
2023-02-14 14:42:35 +01:00
|
|
|
<h5 class="mb-3">
|
|
|
|
<?= $defaultStrategy == 'delete' ? $this->Bootstrap->badge(['text' => 'recommended', 'variant' => 'success', 'class' => ['mb-3', 'fs-8']]) : '' ?>
|
|
|
|
<?= __('Delete conflicting fields') ?>
|
|
|
|
</h5>
|
2021-12-14 15:09:40 +01:00
|
|
|
<ul class="text-start fs-7">
|
|
|
|
<li><?= __('Meta-fields not satisfying the new meta-template definition will be deleted.') ?></li>
|
|
|
|
<li><?= __('All other meta-fields will be upgraded to the new meta-template.') ?></li>
|
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
</label>
|
|
|
|
<?php endif; ?>
|
2021-12-01 11:01:31 +01:00
|
|
|
</div>
|
|
|
|
</div>
|
2021-12-08 11:11:46 +01:00
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class="d-none conflict-resolution-form-container">
|
|
|
|
<?= $form ?>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
(function() {
|
|
|
|
const $form = $('.conflict-resolution-form-container form')
|
2021-12-14 15:09:40 +01:00
|
|
|
const $create = $form.find('input#radio_create_new')
|
2023-02-14 14:42:35 +01:00
|
|
|
const $keep = $form.find('input#radio_update')
|
2021-12-08 11:11:46 +01:00
|
|
|
const $delete = $form.find('input#radio_delete')
|
|
|
|
|
|
|
|
$(document).ready(function() {
|
|
|
|
$('.conflict-resolution-picker').find('input[type="radio"]').change(function() {
|
|
|
|
updateSelected($(this).val())
|
|
|
|
})
|
2023-02-14 14:42:35 +01:00
|
|
|
updateSelected('<?= $defaultStrategy ?>')
|
2021-12-08 11:11:46 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
function updateSelected(choice) {
|
2023-02-14 14:42:35 +01:00
|
|
|
if (choice == 'update_existing') {
|
2021-12-08 11:11:46 +01:00
|
|
|
$keep.prop('checked', true)
|
|
|
|
} else if (choice == 'delete') {
|
|
|
|
$delete.prop('checked', true)
|
2021-12-14 15:09:40 +01:00
|
|
|
} else if (choice == 'create_new') {
|
|
|
|
$create.prop('checked', true)
|
2021-12-08 11:11:46 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}())
|
|
|
|
</script>
|