From 3e0fc1c885629dea5a79f8dbf36985ec6e94df76 Mon Sep 17 00:00:00 2001 From: Ioannis Igoumenos Date: Tue, 24 Sep 2024 12:44:04 +0300 Subject: [PATCH] Render Enrollment Attributes edit/add/view in a modal --- .../Model/Table/EnrollmentAttributesTable.php | 1 + .../EnrollmentAttributes/columns.inc | 6 ++- app/src/Lib/Traits/LayoutTrait.php | 48 +++++++++++++++++++ app/src/Model/Table/AdHocAttributesTable.php | 13 +---- app/src/Model/Table/AddressesTable.php | 15 +----- app/src/Model/Table/EmailAddressesTable.php | 15 +----- .../Table/ExtIdentitySourceRecordsTable.php | 13 +---- app/src/Model/Table/GroupMembersTable.php | 16 +------ app/src/Model/Table/IdentifiersTable.php | 15 +----- app/src/Model/Table/NamesTable.php | 2 +- app/src/Model/Table/PronounsTable.php | 15 +----- app/src/Model/Table/TelephoneNumbersTable.php | 17 ++----- app/src/Model/Table/UrlsTable.php | 15 +----- app/src/View/Helper/CommonHelper.php | 13 +++++ app/templates/Standard/index.php | 31 ++++++++---- 15 files changed, 107 insertions(+), 128 deletions(-) create mode 100644 app/src/Lib/Traits/LayoutTrait.php diff --git a/app/plugins/CoreEnroller/src/Model/Table/EnrollmentAttributesTable.php b/app/plugins/CoreEnroller/src/Model/Table/EnrollmentAttributesTable.php index dea7a12fb..fb0bbad24 100644 --- a/app/plugins/CoreEnroller/src/Model/Table/EnrollmentAttributesTable.php +++ b/app/plugins/CoreEnroller/src/Model/Table/EnrollmentAttributesTable.php @@ -41,6 +41,7 @@ class EnrollmentAttributesTable extends Table { use \App\Lib\Traits\AutoViewVarsTrait; use \App\Lib\Traits\CoLinkTrait; + use \App\Lib\Traits\LayoutTrait; use \App\Lib\Traits\PermissionsTrait; use \App\Lib\Traits\PrimaryLinkTrait; use \App\Lib\Traits\TableMetaTrait; diff --git a/app/plugins/CoreEnroller/templates/EnrollmentAttributes/columns.inc b/app/plugins/CoreEnroller/templates/EnrollmentAttributes/columns.inc index 266a11720..b1d8006e1 100644 --- a/app/plugins/CoreEnroller/templates/EnrollmentAttributes/columns.inc +++ b/app/plugins/CoreEnroller/templates/EnrollmentAttributes/columns.inc @@ -28,7 +28,11 @@ $indexColumns = [ 'label' => [ 'type' => 'link', - 'sortable' => true + 'sortable' => true, + 'class' => 'cm-modal-link nospin', // launch this in a modal + 'dataAttrs' => [ + ['data-cm-modal-title', __d('operation', 'EnrollmentAttributes', 1)] + ] ], 'attribute' => [ // XXX we probably want to render something more like v4 does diff --git a/app/src/Lib/Traits/LayoutTrait.php b/app/src/Lib/Traits/LayoutTrait.php new file mode 100644 index 000000000..a24143c7f --- /dev/null +++ b/app/src/Lib/Traits/LayoutTrait.php @@ -0,0 +1,48 @@ + 'iframe', + default => 'default' + }; + } +} \ No newline at end of file diff --git a/app/src/Model/Table/AdHocAttributesTable.php b/app/src/Model/Table/AdHocAttributesTable.php index e1092e6b9..a8f2edf2e 100644 --- a/app/src/Model/Table/AdHocAttributesTable.php +++ b/app/src/Model/Table/AdHocAttributesTable.php @@ -37,6 +37,7 @@ class AdHocAttributesTable extends Table { use \App\Lib\Traits\ChangelogBehaviorTrait; use \App\Lib\Traits\CoLinkTrait; use \App\Lib\Traits\HistoryTrait; + use \App\Lib\Traits\LayoutTrait; use \App\Lib\Traits\PermissionsTrait; use \App\Lib\Traits\PrimaryLinkTrait; use \App\Lib\Traits\ProvisionableTrait; @@ -44,18 +45,6 @@ class AdHocAttributesTable extends Table { use \App\Lib\Traits\SearchFilterTrait; use \App\Lib\Traits\TableMetaTrait; use \App\Lib\Traits\ValidationTrait; - - /** - * Provide the default layout - * - * @since COmanage Registry v5.0.0 - * @return string Type of redirect - */ - public function getLayout(string $action = ''): string { - return match($action) { - default => 'iframe' - }; - } /** * Perform Cake Model initialization. diff --git a/app/src/Model/Table/AddressesTable.php b/app/src/Model/Table/AddressesTable.php index f1fc87173..fa0f81f16 100644 --- a/app/src/Model/Table/AddressesTable.php +++ b/app/src/Model/Table/AddressesTable.php @@ -39,14 +39,15 @@ class AddressesTable extends Table { use \App\Lib\Traits\ChangelogBehaviorTrait; use \App\Lib\Traits\CoLinkTrait; use \App\Lib\Traits\HistoryTrait; + use \App\Lib\Traits\LayoutTrait; use \App\Lib\Traits\PermissionsTrait; use \App\Lib\Traits\PrimaryLinkTrait; use \App\Lib\Traits\ProvisionableTrait; use \App\Lib\Traits\QueryModificationTrait; + use \App\Lib\Traits\SearchFilterTrait; use \App\Lib\Traits\TableMetaTrait; use \App\Lib\Traits\TypeTrait; use \App\Lib\Traits\ValidationTrait; - use \App\Lib\Traits\SearchFilterTrait; // Default "out of the box" types for this model. Entries here should be // given a default localization in app/resources/locales/*/defaultType.po @@ -58,18 +59,6 @@ class AddressesTable extends Table { 'postal' ] ]; - - /** - * Provide the default layout - * - * @since COmanage Registry v5.0.0 - * @return string Type of redirect - */ - public function getLayout(string $action = ''): string { - return match($action) { - default => 'iframe' - }; - } /** * Perform Cake Model initialization. diff --git a/app/src/Model/Table/EmailAddressesTable.php b/app/src/Model/Table/EmailAddressesTable.php index baa6c77af..62b41c3db 100644 --- a/app/src/Model/Table/EmailAddressesTable.php +++ b/app/src/Model/Table/EmailAddressesTable.php @@ -44,6 +44,7 @@ class EmailAddressesTable extends Table { use \App\Lib\Traits\CoLinkTrait; use \App\Lib\Traits\HistoryTrait; use \App\Lib\Traits\LabeledLogTrait; + use \App\Lib\Traits\LayoutTrait; use \App\Lib\Traits\PermissionsTrait; use \App\Lib\Traits\PrimaryLinkTrait; use \App\Lib\Traits\ProvisionableTrait; @@ -66,19 +67,7 @@ class EmailAddressesTable extends Table { 'recovery' ] ]; - - /** - * Provide the default layout - * - * @since COmanage Registry v5.0.0 - * @return string Type of redirect - */ - public function getLayout(string $action = ''): string { - return match($action) { - default => 'iframe' - }; - } - + /** * Perform Cake Model initialization. * diff --git a/app/src/Model/Table/ExtIdentitySourceRecordsTable.php b/app/src/Model/Table/ExtIdentitySourceRecordsTable.php index c8356f2f4..e4db956b9 100644 --- a/app/src/Model/Table/ExtIdentitySourceRecordsTable.php +++ b/app/src/Model/Table/ExtIdentitySourceRecordsTable.php @@ -43,6 +43,7 @@ class ExtIdentitySourceRecordsTable extends Table { use \App\Lib\Traits\ChangelogBehaviorTrait; use \App\Lib\Traits\CoLinkTrait; use \App\Lib\Traits\LabeledLogTrait; + use \App\Lib\Traits\LayoutTrait; use \App\Lib\Traits\PermissionsTrait; use \App\Lib\Traits\PrimaryLinkTrait; use \App\Lib\Traits\QueryModificationTrait; @@ -50,18 +51,6 @@ class ExtIdentitySourceRecordsTable extends Table { use \App\Lib\Traits\TableMetaTrait; use \App\Lib\Traits\ValidationTrait; - /** - * Provide the default layout - * - * @since COmanage Registry v5.0.0 - * @return string Type of redirect - */ - public function getLayout(string $action = ''): string { - return match($action) { - default => 'iframe' - }; - } - /** * Perform Cake Model initialization. * diff --git a/app/src/Model/Table/GroupMembersTable.php b/app/src/Model/Table/GroupMembersTable.php index 3aaca7a71..b645aaf2a 100644 --- a/app/src/Model/Table/GroupMembersTable.php +++ b/app/src/Model/Table/GroupMembersTable.php @@ -46,26 +46,14 @@ class GroupMembersTable extends Table { use \App\Lib\Traits\CoLinkTrait; use \App\Lib\Traits\HistoryTrait; use \App\Lib\Traits\LabeledLogTrait; + use \App\Lib\Traits\LayoutTrait; use \App\Lib\Traits\PermissionsTrait; use \App\Lib\Traits\PrimaryLinkTrait; use \App\Lib\Traits\ProvisionableTrait; use \App\Lib\Traits\QueryModificationTrait; + use \App\Lib\Traits\SearchFilterTrait; use \App\Lib\Traits\TableMetaTrait; use \App\Lib\Traits\ValidationTrait; - use \App\Lib\Traits\SearchFilterTrait; - - /** - * Provide the default layout - * - * @since COmanage Registry v5.0.0 - * @return string Type of redirect - */ - public function getLayout(string $action = ''): string { - return match($action) { - 'add','edit','view' => 'iframe', - default => 'default' - }; - } /** * Perform Cake Model initialization. diff --git a/app/src/Model/Table/IdentifiersTable.php b/app/src/Model/Table/IdentifiersTable.php index 3d6312cb0..cbc80efb0 100644 --- a/app/src/Model/Table/IdentifiersTable.php +++ b/app/src/Model/Table/IdentifiersTable.php @@ -40,6 +40,7 @@ class IdentifiersTable extends Table { use \App\Lib\Traits\ChangelogBehaviorTrait; use \App\Lib\Traits\CoLinkTrait; use \App\Lib\Traits\HistoryTrait; + use \App\Lib\Traits\LayoutTrait; use \App\Lib\Traits\PermissionsTrait; use \App\Lib\Traits\PrimaryLinkTrait; use \App\Lib\Traits\ProvisionableTrait; @@ -73,19 +74,7 @@ class IdentifiersTable extends Table { 'uid' ] ]; - - /** - * Provide the default layout - * - * @since COmanage Registry v5.0.0 - * @return string Type of redirect - */ - public function getLayout(string $action = ''): string { - return match($action) { - default => 'iframe' - }; - } - + /** * Perform Cake Model initialization. * diff --git a/app/src/Model/Table/NamesTable.php b/app/src/Model/Table/NamesTable.php index 6785ab3dc..8b960aab1 100644 --- a/app/src/Model/Table/NamesTable.php +++ b/app/src/Model/Table/NamesTable.php @@ -44,6 +44,7 @@ class NamesTable extends Table { use \App\Lib\Traits\CoLinkTrait; use \App\Lib\Traits\HistoryTrait; use \App\Lib\Traits\LabeledLogTrait; + use \App\Lib\Traits\LayoutTrait; use \App\Lib\Traits\PermissionsTrait; use \App\Lib\Traits\PrimaryLinkTrait; use \App\Lib\Traits\ProvisionableTrait; @@ -53,7 +54,6 @@ class NamesTable extends Table { use \App\Lib\Traits\TypeTrait; use \App\Lib\Traits\ValidationTrait; - // Default "out of the box" types for this model. Entries here should be // given a default localization in app/resources/locales/*/defaultType.po protected $defaultTypes = [ diff --git a/app/src/Model/Table/PronounsTable.php b/app/src/Model/Table/PronounsTable.php index 82bb98c6a..399a921de 100644 --- a/app/src/Model/Table/PronounsTable.php +++ b/app/src/Model/Table/PronounsTable.php @@ -38,6 +38,7 @@ class PronounsTable extends Table { use \App\Lib\Traits\ChangelogBehaviorTrait; use \App\Lib\Traits\CoLinkTrait; use \App\Lib\Traits\HistoryTrait; + use \App\Lib\Traits\LayoutTrait; use \App\Lib\Traits\PermissionsTrait; use \App\Lib\Traits\PrimaryLinkTrait; use \App\Lib\Traits\ProvisionableTrait; @@ -54,19 +55,7 @@ class PronounsTable extends Table { 'default' ] ]; - - /** - * Provide the default layout - * - * @since COmanage Registry v5.0.0 - * @return string Type of redirect - */ - public function getLayout(string $action = ''): string { - return match($action) { - default => 'iframe' - }; - } - + /** * Perform Cake Model initialization. * diff --git a/app/src/Model/Table/TelephoneNumbersTable.php b/app/src/Model/Table/TelephoneNumbersTable.php index 6f40d7ae6..dd2776ee2 100644 --- a/app/src/Model/Table/TelephoneNumbersTable.php +++ b/app/src/Model/Table/TelephoneNumbersTable.php @@ -38,6 +38,7 @@ class TelephoneNumbersTable extends Table { use \App\Lib\Traits\ChangelogBehaviorTrait; use \App\Lib\Traits\CoLinkTrait; use \App\Lib\Traits\HistoryTrait; + use \App\Lib\Traits\LayoutTrait; use \App\Lib\Traits\PermissionsTrait; use \App\Lib\Traits\PrimaryLinkTrait; use \App\Lib\Traits\ProvisionableTrait; @@ -46,7 +47,7 @@ class TelephoneNumbersTable extends Table { use \App\Lib\Traits\TableMetaTrait; use \App\Lib\Traits\TypeTrait; use \App\Lib\Traits\ValidationTrait; - + // Default "out of the box" types for this model. Entries here should be // given a default localization in app/resources/locales/*/defaultType.po protected $defaultTypes = [ @@ -58,19 +59,7 @@ class TelephoneNumbersTable extends Table { 'office' ] ]; - - /** - * Provide the default layout - * - * @since COmanage Registry v5.0.0 - * @return string Type of redirect - */ - public function getLayout(string $action = ''): string { - return match($action) { - default => 'iframe' - }; - } - + /** * Perform Cake Model initialization. * diff --git a/app/src/Model/Table/UrlsTable.php b/app/src/Model/Table/UrlsTable.php index eb6e53707..307ccf854 100644 --- a/app/src/Model/Table/UrlsTable.php +++ b/app/src/Model/Table/UrlsTable.php @@ -37,6 +37,7 @@ class UrlsTable extends Table { use \App\Lib\Traits\ChangelogBehaviorTrait; use \App\Lib\Traits\CoLinkTrait; use \App\Lib\Traits\HistoryTrait; + use \App\Lib\Traits\LayoutTrait; use \App\Lib\Traits\PermissionsTrait; use \App\Lib\Traits\PrimaryLinkTrait; use \App\Lib\Traits\ProvisionableTrait; @@ -54,19 +55,7 @@ class UrlsTable extends Table { 'personal' ] ]; - - /** - * Provide the default layout - * - * @since COmanage Registry v5.0.0 - * @return string Type of redirect - */ - public function getLayout(string $action = ''): string { - return match($action) { - default => 'iframe' - }; - } - + /** * Perform Cake Model initialization. * diff --git a/app/src/View/Helper/CommonHelper.php b/app/src/View/Helper/CommonHelper.php index e7660bf88..e19e3dd10 100644 --- a/app/src/View/Helper/CommonHelper.php +++ b/app/src/View/Helper/CommonHelper.php @@ -29,12 +29,25 @@ namespace App\View\Helper; +use Cake\ORM\Table; use Cake\ORM\TableRegistry; use Cake\Utility\Inflector; use Cake\View\Helper; class CommonHelper extends Helper { + /** + * Get reference to Model Table + * + * @param string $modelsName + * + * @return Table + */ + public function getModelTableReference(string $modelsName): Table + { + return TableRegistry::getTableLocator()->get($modelsName); + } + /** * Select count(*) * diff --git a/app/templates/Standard/index.php b/app/templates/Standard/index.php index b253337ae..099d6c1bf 100644 --- a/app/templates/Standard/index.php +++ b/app/templates/Standard/index.php @@ -103,13 +103,13 @@ // Index view top link action item can be atomized using the user's identifier // since there will not always be an object id available. Like the case of add action if($vv_permissions['add']) { - $action_args = array(); + $action_args = []; $action_args['vv_attr_id'] = $vv_user['username']; - $action_args['vv_actions'] = array(); + $action_args['vv_actions'] = []; // Include the Add link to actions menu unless suppressed by the page if(empty($suppressAddLink)) { - $action_args['vv_actions'][] = [ + $action_configuration = [ 'order' => $this->Menu->getMenuOrder('Add'), 'icon' => $this->Menu->getMenuIcon('Add'), 'url' => [ @@ -118,13 +118,26 @@ '?' => $linkFilter ], 'label' => __d( - 'operation', - 'add.a', - \App\Lib\Util\StringUtilities::localizeController( - controllerName: $modelsName, - pluginName: $this->getPlugin(), - plural: false)) + 'operation', + 'add.a', + \App\Lib\Util\StringUtilities::localizeController( + controllerName: $modelsName, + pluginName: $this->getPlugin(), + plural: false)) ]; + + // Check to see if the model names a specific layout + + $fullModelsName = !empty($this->getPlugin()) ? $this->getPlugin() . '.' . $modelsName : $modelsName; + $modelsTable = $this->Common->getModelTableReference($fullModelsName); + if(method_exists($modelsTable, 'getLayout')) { + $action_configuration['class'] = 'cm-modal-link nospin'; // launch this in a modal + $action_configuration['dataAttrs'] = [ + ['data-cm-modal-title', __d('operation', 'EnrollmentAttributes', 1)] + ]; + } + + $action_args['vv_actions'][] = $action_configuration; }