chg: [genericElements:toggle] Added support of requirement for being
able to change the toggle's statepull/37/head
parent
ad8ce73fdf
commit
4cfff0fce4
|
@ -29,6 +29,11 @@ echo $this->element('genericElements/IndexTable/index_table', [
|
|||
'element' => 'toggle',
|
||||
'url' => '/metaTemplates/toggle',
|
||||
'url_params_data_paths' => ['id'],
|
||||
'toggle_requirement' => [
|
||||
'function' => function($row, $options) {
|
||||
return true;
|
||||
}
|
||||
]
|
||||
],
|
||||
[
|
||||
'name' => __('Scope'),
|
||||
|
@ -60,29 +65,6 @@ echo $this->element('genericElements/IndexTable/index_table', [
|
|||
'url_params_data_paths' => ['id'],
|
||||
'icon' => 'eye'
|
||||
],
|
||||
[
|
||||
'url' => '/metaTemplates/toggle',
|
||||
'url_params_data_paths' => ['id'],
|
||||
'title' => __('Enable template'),
|
||||
'icon' => 'plus',
|
||||
'complex_requirement' => [
|
||||
'function' => function($row, $options) {
|
||||
return !(bool)$row['enabled'];
|
||||
}
|
||||
]
|
||||
],
|
||||
[
|
||||
'url' => '/metaTemplates/toggle',
|
||||
'url_params_data_paths' => ['id'],
|
||||
'title' => __('DIsable template'),
|
||||
'icon' => 'minus',
|
||||
'complex_requirement' => [
|
||||
'function' => function($row, $options) {
|
||||
return (bool)$row['enabled'];
|
||||
}
|
||||
]
|
||||
]
|
||||
|
||||
]
|
||||
]
|
||||
]);
|
||||
|
|
|
@ -10,13 +10,28 @@
|
|||
$seed = rand();
|
||||
$checkboxId = 'GenericToggle-' . $seed;
|
||||
$tempboxId = 'TempBox-' . $seed;
|
||||
|
||||
$requirementMet = true;
|
||||
if (isset($field['toggle_requirement'])) {
|
||||
if (isset($field['toggle_requirement']['options']['datapath'])) {
|
||||
foreach ($field['toggle_requirement']['options']['datapath'] as $name => $path) {
|
||||
$field['toggle_requirement']['options']['datapath'][$name] = empty($this->Hash->extract($row, $path)[0]) ? null : $this->Hash->extract($row, $path)[0];
|
||||
}
|
||||
}
|
||||
$options = isset($field['toggle_requirement']['options']) ? $field['toggle_requirement']['options'] : array();
|
||||
$requirementMet = $field['toggle_requirement']['function']($row, $options);
|
||||
}
|
||||
|
||||
echo sprintf(
|
||||
'<input type="checkbox" id="%s" %s><span id="%s" class="d-none">',
|
||||
'<input type="checkbox" id="%s" %s %s><span id="%s" class="d-none">',
|
||||
$checkboxId,
|
||||
empty($data[0]) ? '' : 'checked',
|
||||
$requirementMet ? '' : 'disabled="disabled"',
|
||||
$tempboxId
|
||||
);
|
||||
?>
|
||||
|
||||
<?php if ($requirementMet): ?>
|
||||
<script type="text/javascript">
|
||||
$(document).ready(function() {
|
||||
var url = "<?= h($field['url']) ?>";
|
||||
|
@ -69,3 +84,4 @@ $(document).ready(function() {
|
|||
});
|
||||
});
|
||||
</script>
|
||||
<?php endif; ?>
|
|
@ -48,7 +48,7 @@ if ($field['scope'] === 'individuals') {
|
|||
}
|
||||
}
|
||||
echo sprintf(
|
||||
'<div class="alignments-list">%s</div><div class="alignments-add-container"><button class="alignments-add-button btn btn-secondary btn-sm" onclick="%s">%s</button></div>',
|
||||
'<div class="alignments-list">%s</div><div class="alignments-add-container"><button class="alignments-add-button btn btn-primary btn-sm" onclick="%s">%s</button></div>',
|
||||
$alignments,
|
||||
sprintf(
|
||||
"populateAndLoadModal('/alignments/add/%s/%s');",
|
||||
|
|
Loading…
Reference in New Issue