From 30246dfc70e50a963db1967c3af7a389ab7069d9 Mon Sep 17 00:00:00 2001 From: mokaddem Date: Tue, 15 Dec 2020 16:36:53 +0100 Subject: [PATCH] chg: [genericElements:indexTable] Added documentation for toggle field --- templates/MetaTemplates/index.php | 6 ++--- .../IndexTable/Fields/toggle.php | 26 ++++++++++++++----- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/templates/MetaTemplates/index.php b/templates/MetaTemplates/index.php index 28231be..5516f82 100644 --- a/templates/MetaTemplates/index.php +++ b/templates/MetaTemplates/index.php @@ -31,10 +31,10 @@ echo $this->element('genericElements/IndexTable/index_table', [ 'url' => '/metaTemplates/toggle/{{0}}', 'url_params_vars' => ['id'], 'toggle_data' => [ - 'requirement' => [ + 'editRequirement' => [ 'function' => function($row, $options) { return true; - } + }, ], 'skip_full_reload' => true ] @@ -47,7 +47,7 @@ echo $this->element('genericElements/IndexTable/index_table', [ 'url' => '/metaTemplates/toggle/{{0}}/{{1}}', 'url_params_vars' => [['datapath' => 'id'], ['raw' => 'is_default']], 'toggle_data' => [ - 'requirement' => [ + 'editRequirement' => [ 'function' => function($row, $options) { return true; } diff --git a/templates/element/genericElements/IndexTable/Fields/toggle.php b/templates/element/genericElements/IndexTable/Fields/toggle.php index f8a2237..39ecb67 100644 --- a/templates/element/genericElements/IndexTable/Fields/toggle.php +++ b/templates/element/genericElements/IndexTable/Fields/toggle.php @@ -4,6 +4,18 @@ * On click, issues a GET to a given endpoint, retrieving a form with the * value flipped, which is immediately POSTed. * 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']); @@ -11,15 +23,15 @@ $checkboxId = 'GenericToggle-' . $seed; $tempboxId = 'TempBox-' . $seed; - $requirementMet = true; - if (isset($field['toggle_data']['requirement'])) { - if (isset($field['toggle_data']['requirement']['options']['datapath'])) { - foreach ($field['toggle_data']['requirement']['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]; + $requirementMet = false; + if (isset($field['toggle_data']['editRequirement'])) { + if (isset($field['toggle_data']['editRequirement']['options']['datapath'])) { + foreach ($field['toggle_data']['editRequirement']['options']['datapath'] as $name => $path) { + $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(); - $requirementMet = $field['toggle_data']['requirement']['function']($row, $options); + $options = isset($field['toggle_data']['editRequirement']['options']) ? $field['toggle_data']['editRequirement']['options'] : array(); + $requirementMet = $field['toggle_data']['editRequirement']['function']($row, $options); } echo sprintf(