From 38fc903501fc609d0f1b1baf96dd62de6f6f9671 Mon Sep 17 00:00:00 2001 From: Jakub Onderka Date: Sun, 20 Mar 2022 14:40:58 +0100 Subject: [PATCH] chg: [UI] Open modal without onclick vol. 2 --- app/View/AuthKeys/index.ctp | 19 ++++-------- app/View/Elements/eventattributetoolbar.ctp | 30 +++++++++---------- .../IndexTable/Fields/actions.ctp | 19 ++++++++---- app/View/Roles/index.ctp | 14 ++++----- 4 files changed, 40 insertions(+), 42 deletions(-) diff --git a/app/View/AuthKeys/index.ctp b/app/View/AuthKeys/index.ctp index 87301c98c..2a3762fed 100644 --- a/app/View/AuthKeys/index.ctp +++ b/app/View/AuthKeys/index.ctp @@ -16,15 +16,8 @@ 'type' => 'simple', 'fa-icon' => 'plus', 'text' => __('Add authentication key'), - 'class' => 'btn btn-primary', - 'onClick' => 'openGenericModal', - 'onClickParams' => [ - sprintf( - '%s/auth_keys/add%s', - $baseurl, - empty($user_id) ? '' : ('/' . $user_id) - ) - ] + 'class' => 'btn-primary modal-open', + 'url' => "$baseurl/auth_keys/add" . (empty($user_id) ? '' : ('/' . $user_id)), ] ] ], @@ -101,11 +94,9 @@ 'title' => 'Edit auth key', ], [ - 'onclick' => sprintf( - 'openGenericModal(\'%s/authKeys/delete/[onclick_params_data_path]\');', - $baseurl - ), - 'onclick_params_data_path' => 'AuthKey.id', + 'class' => 'modal-open', + 'url' => "$baseurl/authKeys/delete", + 'url_params_data_paths' => ['AuthKey.id'], 'icon' => 'trash', 'title' => __('Delete auth key'), ] diff --git a/app/View/Elements/eventattributetoolbar.ctp b/app/View/Elements/eventattributetoolbar.ctp index a905d668a..18937d5ec 100644 --- a/app/View/Elements/eventattributetoolbar.ctp +++ b/app/View/Elements/eventattributetoolbar.ctp @@ -1,4 +1,5 @@ passedArgs['correlation'])) { $attributeFilter = 'correlation'; } @@ -28,7 +29,7 @@ 'text' => __('Proposal'), 'active' => $attributeFilter == 'proposal', 'onClick' => 'filterAttributes', - 'onClickParams' => array('proposal', $event['Event']['id']) + 'onClickParams' => array('proposal', $eventId) ); $simple_filter_data[] = array( 'id' => 'filter_correlation', @@ -44,7 +45,7 @@ 'text' => __('Warning'), 'active' => $attributeFilter == 'warning', 'onClick' => 'filterAttributes', - 'onClickParams' => array('warning', $event['Event']['id']) + 'onClickParams' => array('warning', $eventId) ); $data = array( 'children' => array( @@ -54,9 +55,8 @@ 'id' => 'create-button', 'title' => $possibleAction === 'attribute' ? __('Add attribute') : __('Add proposal'), 'fa-icon' => 'plus', - 'class' => 'last', - 'onClick' => 'openGenericModal', - 'onClickParams' => array('/' . $possibleAction . 's/add/' . h($event['Event']['id'])) + 'class' => 'last modal-open', + 'url' => $baseurl . '/' . $possibleAction . 's/add/' . $eventId, ), array( 'id' => 'multi-edit-button', @@ -64,7 +64,7 @@ 'class' => 'mass-select hidden', 'fa-icon' => 'edit', 'onClick' => 'editSelectedAttributes', - 'onClickParams' => array($event['Event']['id']) + 'onClickParams' => array($eventId) ), array( 'id' => 'multi-tag-button', @@ -81,7 +81,7 @@ 'fa-icon' => 'rebel', 'fa-source' => 'fab', 'onClick' => 'popoverPopup', - 'onClickParams' => array('this', 'selected/attribute/eventid:' . h($event['Event']['id']), 'galaxies', 'selectGalaxyNamespace') + 'onClickParams' => array('this', 'selected/attribute/eventid:' . $eventId, 'galaxies', 'selectGalaxyNamespace') ), array( 'id' => 'group-into-object-button', @@ -90,7 +90,7 @@ 'fa-icon' => 'object-group', 'fa-source' => 'fa', 'onClick' => 'proposeObjectsFromSelectedAttributes', - 'onClickParams' => array('this', $event['Event']['id']) + 'onClickParams' => array('this', $eventId) ), array( 'id' => 'multi-delete-button', @@ -98,7 +98,7 @@ 'class' => 'mass-select hidden', 'fa-icon' => 'trash', 'onClick' => 'multiSelectAction', - 'onClickParams' => array($event['Event']['id'], 'deleteAttributes') + 'onClickParams' => array($eventId, 'deleteAttributes') ), array( 'id' => 'multi-accept-button', @@ -106,7 +106,7 @@ 'class' => 'mass-proposal-select hidden', 'fa-icon' => 'check-circle', 'onClick' => 'multiSelectAction', - 'onClickParams' => array($event['Event']['id'], 'acceptProposals') + 'onClickParams' => array($eventId, 'acceptProposals') ), array( 'id' => 'multi-discard-button', @@ -114,7 +114,7 @@ 'class' => 'mass-proposal-select hidden', 'fa-icon' => 'times', 'onClick' => 'multiSelectAction', - 'onClickParams' => array($event['Event']['id'], 'discardProposals') + 'onClickParams' => array($eventId, 'discardProposals') ), array( 'id' => 'multi-sighting-button', @@ -132,7 +132,7 @@ 'title' => __('Populate using a template'), 'fa-icon' => 'list', 'onClick' => 'getPopup', - 'onClickParams' => array($event['Event']['id'], 'templates', 'templateChoices'), + 'onClickParams' => array($eventId, 'templates', 'templateChoices'), 'requirement' => $mayModify ), array( @@ -140,14 +140,14 @@ 'title' => __('Populate using the freetext import tool'), 'fa-icon' => 'align-left', 'onClick' => 'getPopup', - 'onClickParams' => array($event['Event']['id'], 'events', 'freeTextImport') + 'onClickParams' => array($eventId, 'events', 'freeTextImport') ), array( 'id' => 'attribute-replace-button', 'title' => __('Replace all attributes of a category/type combination within the event'), 'fa-icon' => 'random', 'onClick' => 'getPopup', - 'onClickParams' => array($event['Event']['id'], 'attributes', 'attributeReplace'), + 'onClickParams' => array($eventId, 'attributes', 'attributeReplace'), 'requirement' => $mayModify ) ) @@ -236,7 +236,7 @@ 'fa-icon' => 'times', 'title' => __('Remove filters'), 'onClick' => 'filterAttributes', - 'onClickParams' => array('all', $event['Event']['id']) + 'onClickParams' => array('all', $eventId) ) ) ) diff --git a/app/View/Elements/genericElements/IndexTable/Fields/actions.ctp b/app/View/Elements/genericElements/IndexTable/Fields/actions.ctp index 054a3bbe9..bd7993a63 100644 --- a/app/View/Elements/genericElements/IndexTable/Fields/actions.ctp +++ b/app/View/Elements/genericElements/IndexTable/Fields/actions.ctp @@ -114,13 +114,22 @@ $action['onclick'] ); } + $title = empty($action['title']) ? '' : h($action['title']); + + $classes = []; + if (!empty($action['class'])) { + $classes[] = h($action['class']); + } + if (!empty($action['dbclickAction'])) { + $classes[] = 'dblclickActionElement'; + } echo sprintf( - ' ', + ' ', $url, - empty($action['title']) ? '' : h($action['title']), - empty($action['title']) ? '' : h($action['title']), - empty($action['dbclickAction']) ? '' : 'class="dblclickActionElement"', - empty($action['onclick']) ? '' : sprintf('onclick="event.preventDefault();%s"', $action['onclick']), + $title, + $title, + empty($classes) ? '' : ' class="' . implode(' ', $classes) . '"', + empty($action['onclick']) ? '' : sprintf(' onclick="event.preventDefault();%s"', $action['onclick']), $this->FontAwesome->getClass($action['icon']) ); } diff --git a/app/View/Roles/index.ctp b/app/View/Roles/index.ctp index 5c1e33424..2e9bc719e 100644 --- a/app/View/Roles/index.ctp +++ b/app/View/Roles/index.ctp @@ -84,18 +84,16 @@ if ($isSiteAdmin) { $actions = [ [ 'url' => $baseurl . '/admin/roles/edit', - 'url_params_data_paths' => array( - 'Role.id' - ), + 'url_params_data_paths' => ['Role.id'], 'icon' => 'edit', + 'title' => __('Edit role'), ], [ - 'onclick' => sprintf( - 'openGenericModal(\'%s/admin/roles/delete/[onclick_params_data_path]\');', - $baseurl - ), - 'onclick_params_data_path' => 'Role.id', + 'class' => 'modal-open', + 'url' => "$baseurl/admin/roles/delete", + 'url_params_data_paths' => ['Role.id'], 'icon' => 'trash', + 'title' => __('Delete role'), ] ]; } else {