chg: [genericElements:indexTable] Added documentation for toggle field

pull/37/head
mokaddem 2020-12-15 16:36:53 +01:00
parent dddc7d1a12
commit 30246dfc70
2 changed files with 22 additions and 10 deletions

View File

@ -31,10 +31,10 @@ echo $this->element('genericElements/IndexTable/index_table', [
'url' => '/metaTemplates/toggle/{{0}}', 'url' => '/metaTemplates/toggle/{{0}}',
'url_params_vars' => ['id'], 'url_params_vars' => ['id'],
'toggle_data' => [ 'toggle_data' => [
'requirement' => [ 'editRequirement' => [
'function' => function($row, $options) { 'function' => function($row, $options) {
return true; return true;
} },
], ],
'skip_full_reload' => true 'skip_full_reload' => true
] ]
@ -47,7 +47,7 @@ echo $this->element('genericElements/IndexTable/index_table', [
'url' => '/metaTemplates/toggle/{{0}}/{{1}}', 'url' => '/metaTemplates/toggle/{{0}}/{{1}}',
'url_params_vars' => [['datapath' => 'id'], ['raw' => 'is_default']], 'url_params_vars' => [['datapath' => 'id'], ['raw' => 'is_default']],
'toggle_data' => [ 'toggle_data' => [
'requirement' => [ 'editRequirement' => [
'function' => function($row, $options) { 'function' => function($row, $options) {
return true; return true;
} }

View File

@ -4,6 +4,18 @@
* On click, issues a GET to a given endpoint, retrieving a form with the * On click, issues a GET to a given endpoint, retrieving a form with the
* value flipped, which is immediately POSTed. * value flipped, which is immediately POSTed.
* to fetch it. * to fetch it.
* Options:
* - url: The URL on which to perform the POST
* - url_params_vars: Variables to be injected into the URL using the DataFromPath helper
* - toggle_data.skip_full_reload: If true, the index will not be reloaded and the checkbox will be flipped on success
* - toggle_data.editRequirement.function: A function to be called to assess if the checkbox can be toggled
* - toggle_data.editRequirement.options: Option that will be passed to the function
* - toggle_data.editRequirement.options.datapath: If provided, entries will have their datapath values converted into their extracted value
* - toggle_data.confirm.[enable/disable].title:
* - toggle_data.confirm.[enable/disable].titleHtml:
* - toggle_data.confirm.[enable/disable].body:
* - toggle_data.confirm.[enable/disable].bodyHtml:
* - toggle_data.confirm.[enable/disable].type:
* *
*/ */
$data = $this->Hash->get($row, $field['data_path']); $data = $this->Hash->get($row, $field['data_path']);
@ -11,15 +23,15 @@
$checkboxId = 'GenericToggle-' . $seed; $checkboxId = 'GenericToggle-' . $seed;
$tempboxId = 'TempBox-' . $seed; $tempboxId = 'TempBox-' . $seed;
$requirementMet = true; $requirementMet = false;
if (isset($field['toggle_data']['requirement'])) { if (isset($field['toggle_data']['editRequirement'])) {
if (isset($field['toggle_data']['requirement']['options']['datapath'])) { if (isset($field['toggle_data']['editRequirement']['options']['datapath'])) {
foreach ($field['toggle_data']['requirement']['options']['datapath'] as $name => $path) { foreach ($field['toggle_data']['editRequirement']['options']['datapath'] as $name => $path) {
$field['toggle_data']['requirement']['options']['datapath'][$name] = empty($this->Hash->extract($row, $path)[0]) ? null : $this->Hash->extract($row, $path)[0]; $field['toggle_data']['editRequirement']['options']['datapath'][$name] = empty($this->Hash->extract($row, $path)[0]) ? null : $this->Hash->extract($row, $path)[0];
} }
} }
$options = isset($field['toggle_data']['requirement']['options']) ? $field['toggle_data']['requirement']['options'] : array(); $options = isset($field['toggle_data']['editRequirement']['options']) ? $field['toggle_data']['editRequirement']['options'] : array();
$requirementMet = $field['toggle_data']['requirement']['function']($row, $options); $requirementMet = $field['toggle_data']['editRequirement']['function']($row, $options);
} }
echo sprintf( echo sprintf(