diff --git a/src/Controller/AlignmentsController.php b/src/Controller/AlignmentsController.php index b91db4c..a8dd626 100644 --- a/src/Controller/AlignmentsController.php +++ b/src/Controller/AlignmentsController.php @@ -36,10 +36,8 @@ class AlignmentsController extends AppController throw new NotFoundException(__('Invalid alignment.')); } $individual = $this->Alignments->get($id); - if ($this->ParamHandler->isRest()) { + if ($this->ParamHandler->isRest() || $this->ParamHandler->isAjax()) { return $this->RestResponse->viewData($individual, 'json'); - } else { - } $this->set('metaGroup', 'ContactDB'); $this->set('alignment', $individual); @@ -50,12 +48,11 @@ class AlignmentsController extends AppController if (empty($id)) { throw new NotFoundException(__('Invalid alignment.')); } - $individual = $this->Alignments->get($id); + $alignment = $this->Alignments->get($id); if ($this->request->is('post') || $this->request->is('delete')) { - if ($this->Alignments->delete($individual)) { - $message = __('Individual deleted.'); - if ($this->ParamHandler->isRest()) { - $individual = $this->Alignments->get($id); + if ($this->Alignments->delete($alignment)) { + $message = __('Alignments deleted.'); + if ($this->ParamHandler->isRest() || $this->ParamHandler->isAjax()) { return $this->RestResponse->saveSuccessResponse('Alignments', 'delete', $id, 'json', $message); } else { $this->Flash->success($message); @@ -65,8 +62,8 @@ class AlignmentsController extends AppController } $this->set('metaGroup', 'ContactDB'); $this->set('scope', 'alignments'); - $this->set('id', $individual['id']); - $this->set('alignment', $individual); + $this->set('id', $alignment['id']); + $this->set('alignment', $alignment); $this->viewBuilder()->setLayout('ajax'); $this->render('/genericTemplates/delete'); } @@ -86,18 +83,20 @@ class AlignmentsController extends AppController } else { $alignment['organisation_id'] = $source_id; } - if ($this->Alignments->save($alignment)) { + $alignment = $this->Alignments->save($alignment); + if ($alignment) { $message = __('Alignment added.'); if ($this->ParamHandler->isRest()) { - $alignment = $this->Alignments->get($this->Alignments->id); return $this->RestResponse->viewData($alignment, 'json'); + } else if($this->ParamHandler->isAjax()) { + return $this->RestResponse->ajaxSuccessResponse('Alignment', 'add', $alignment, $message); } else { $this->Flash->success($message); $this->redirect($this->referer()); } } else { $message = __('Alignment could not be added.'); - if ($this->ParamHandler->isRest()) { + if ($this->ParamHandler->isRest() || $this->ParamHandler->isAjax()) { return $this->RestResponse->saveFailResponse('Individuals', 'addAlignment', false, $message); } else { $this->Flash->error($message); diff --git a/src/Controller/AuthKeysController.php b/src/Controller/AuthKeysController.php index 0de9fed..27bb57d 100644 --- a/src/Controller/AuthKeysController.php +++ b/src/Controller/AuthKeysController.php @@ -22,8 +22,9 @@ class AuthKeysController extends AppController 'contain' => ['Users'], 'exclude_fields' => ['authkey'] ]); - if ($this->ParamHandler->isRest()) { - return $this->restResponsePayload; + $responsePayload = $this->CRUD->getResponsePayload(); + if (!empty($responsePayload)) { + return $responsePayload; } $this->set('metaGroup', $this->isAdmin ? 'Administration' : 'Cerebrate'); } @@ -31,8 +32,9 @@ class AuthKeysController extends AppController public function delete($id) { $this->CRUD->delete($id); - if ($this->ParamHandler->isRest()) { - return $this->restResponsePayload; + $responsePayload = $this->CRUD->getResponsePayload(); + if (!empty($responsePayload)) { + return $responsePayload; } $this->set('metaGroup', $this->isAdmin ? 'Administration' : 'Cerebrate'); } @@ -43,8 +45,9 @@ class AuthKeysController extends AppController $this->CRUD->add([ 'displayOnSuccess' => 'authkey_display' ]); - if ($this->ParamHandler->isRest()) { - return $this->restResponsePayload; + $responsePayload = $this->CRUD->getResponsePayload(); + if (!empty($responsePayload)) { + return $responsePayload; } $this->loadModel('Users'); $dropdownData = [ diff --git a/src/Controller/EncryptionKeysController.php b/src/Controller/EncryptionKeysController.php index df85c81..afcc611 100644 --- a/src/Controller/EncryptionKeysController.php +++ b/src/Controller/EncryptionKeysController.php @@ -19,6 +19,11 @@ class EncryptionKeysController extends AppController $this->CRUD->index([ 'quickFilters' => ['encryption_key'], 'filters' => ['owner_type', 'organisation_id', 'individual_id', 'encryption_key'], + 'contextFilters' => [ + 'fields' => [ + 'type' + ] + ], 'contain' => ['Individuals', 'Organisations'] ]); if ($this->ParamHandler->isRest()) { diff --git a/src/Controller/IndividualsController.php b/src/Controller/IndividualsController.php index e0c7737..e3445eb 100644 --- a/src/Controller/IndividualsController.php +++ b/src/Controller/IndividualsController.php @@ -18,15 +18,15 @@ class IndividualsController extends AppController 'filters' => ['uuid', 'email', 'first_name', 'last_name', 'position', 'Organisations.id', 'Alignments.type'], 'quickFilters' => ['uuid', 'email', 'first_name', 'last_name', 'position'], 'contextFilters' => [ - 'allow_all' => true, 'fields' => [ 'Alignments.type' ] ], 'contain' => ['Alignments' => 'Organisations'] ]); - if ($this->ParamHandler->isRest()) { - return $this->restResponsePayload; + $responsePayload = $this->CRUD->getResponsePayload(); + if (!empty($responsePayload)) { + return $responsePayload; } $this->set('alignmentScope', 'individuals'); $this->set('metaGroup', 'ContactDB'); diff --git a/src/Controller/MetaTemplatesController.php b/src/Controller/MetaTemplatesController.php index a66cc59..5255768 100644 --- a/src/Controller/MetaTemplatesController.php +++ b/src/Controller/MetaTemplatesController.php @@ -37,7 +37,6 @@ class MetaTemplatesController extends AppController 'filters' => ['name', 'uuid', 'scope', 'namespace'], 'quickFilters' => ['name', 'uuid', 'scope'], 'contextFilters' => [ - 'allow_all' => true, 'fields' => ['scope'], 'custom' => [ [ diff --git a/src/Controller/OrganisationsController.php b/src/Controller/OrganisationsController.php index 9e6162c..9a599c3 100644 --- a/src/Controller/OrganisationsController.php +++ b/src/Controller/OrganisationsController.php @@ -19,8 +19,9 @@ class OrganisationsController extends AppController 'quickFilters' => ['name', 'uuid', 'nationality', 'sector', 'type', 'url'], 'contain' => ['Alignments' => 'Individuals'] ]); - if ($this->ParamHandler->isRest()) { - return $this->restResponsePayload; + $responsePayload = $this->CRUD->getResponsePayload(); + if (!empty($responsePayload)) { + return $responsePayload; } $this->set('alignmentScope', 'individuals'); $this->set('metaGroup', 'ContactDB'); @@ -29,8 +30,9 @@ class OrganisationsController extends AppController public function add() { $this->CRUD->add(); - if ($this->ParamHandler->isRest()) { - return $this->restResponsePayload; + $responsePayload = $this->CRUD->getResponsePayload(); + if (!empty($responsePayload)) { + return $responsePayload; } $this->set('metaGroup', 'ContactDB'); } @@ -38,8 +40,9 @@ class OrganisationsController extends AppController public function view($id) { $this->CRUD->view($id, ['contain' => ['Alignments' => 'Individuals']]); - if ($this->ParamHandler->isRest()) { - return $this->restResponsePayload; + $responsePayload = $this->CRUD->getResponsePayload(); + if (!empty($responsePayload)) { + return $responsePayload; } $this->set('metaGroup', 'ContactDB'); } @@ -47,8 +50,9 @@ class OrganisationsController extends AppController public function edit($id) { $this->CRUD->edit($id); - if ($this->ParamHandler->isRest()) { - return $this->restResponsePayload; + $responsePayload = $this->CRUD->getResponsePayload(); + if (!empty($responsePayload)) { + return $responsePayload; } $this->set('metaGroup', 'ContactDB'); $this->render('add'); @@ -57,8 +61,9 @@ class OrganisationsController extends AppController public function delete($id) { $this->CRUD->delete($id); - if ($this->ParamHandler->isRest()) { - return $this->restResponsePayload; + $responsePayload = $this->CRUD->getResponsePayload(); + if (!empty($responsePayload)) { + return $responsePayload; } $this->set('metaGroup', 'ContactDB'); } diff --git a/templates/AuthKeys/index.php b/templates/AuthKeys/index.php index f4dcf07..0964ca1 100644 --- a/templates/AuthKeys/index.php +++ b/templates/AuthKeys/index.php @@ -64,8 +64,8 @@ echo $this->element('genericElements/IndexTable/index_table', [ 'pull' => 'right', 'actions' => [ [ - 'onclick' => 'populateAndLoadModal(\'/authKeys/delete/[onclick_params_data_path]\');', - 'onclick_params_data_path' => 'id', + 'open_modal' => '/authKeys/delete/[onclick_params_data_path]', + 'modal_params_data_path' => 'id', 'icon' => 'trash' ] ] diff --git a/templates/EncryptionKeys/index.php b/templates/EncryptionKeys/index.php index bc8178b..fed2abd 100644 --- a/templates/EncryptionKeys/index.php +++ b/templates/EncryptionKeys/index.php @@ -18,6 +18,10 @@ echo $this->element('genericElements/IndexTable/index_table', [ ] ] ], + [ + 'type' => 'context_filters', + 'context_filters' => $filteringContexts + ], [ 'type' => 'search', 'button' => __('Filter'), @@ -60,20 +64,20 @@ echo $this->element('genericElements/IndexTable/index_table', [ 'pull' => 'right', 'actions' => [ [ - 'onclick' => 'populateAndLoadModal(\'/encryptionKeys/view/[onclick_params_data_path]\');', - 'onclick_params_data_path' => 'id', + 'url' => '/encryptionKeys/view', + 'url_params_data_paths' => ['id'], 'icon' => 'eye' ], [ - 'onclick' => 'populateAndLoadModal(\'/encryptionKeys/edit/[onclick_params_data_path]\');', - 'onclick_params_data_path' => 'id', + 'open_modal' => '/encryptionKeys/edit/[onclick_params_data_path]', + 'modal_params_data_path' => 'id', 'icon' => 'edit' ], [ - 'onclick' => 'populateAndLoadModal(\'/encryptionKeys/delete/[onclick_params_data_path]\');', - 'onclick_params_data_path' => 'id', + 'open_modal' => '/encryptionKeys/delete/[onclick_params_data_path]', + 'modal_params_data_path' => 'id', 'icon' => 'trash' - ] + ], ] ] ]); diff --git a/templates/Individuals/index.php b/templates/Individuals/index.php index 7ff2e4c..02908d3 100644 --- a/templates/Individuals/index.php +++ b/templates/Individuals/index.php @@ -72,15 +72,15 @@ echo $this->element('genericElements/IndexTable/index_table', [ 'icon' => 'eye' ], [ - 'onclick' => 'openModalFromURL(\'/individuals/edit/[onclick_params_data_path]\');', - 'onclick_params_data_path' => 'id', + 'open_modal' => '/individuals/edit/[onclick_params_data_path]', + 'modal_params_data_path' => 'id', 'icon' => 'edit' ], [ - 'onclick' => 'openModalFromURL(\'/individuals/delete/[onclick_params_data_path]\');', - 'onclick_params_data_path' => 'id', + 'open_modal' => '/individuals/delete/[onclick_params_data_path]', + 'modal_params_data_path' => 'id', 'icon' => 'trash' - ] + ], ] ] ]); diff --git a/templates/Open/Individuals/index.php b/templates/Open/Individuals/index.php index 30ee3f5..411f331 100644 --- a/templates/Open/Individuals/index.php +++ b/templates/Open/Individuals/index.php @@ -56,16 +56,6 @@ echo $this->element('genericElements/IndexTable/index_table', [ 'url' => '/individuals/view', 'url_params_data_paths' => ['id'], 'icon' => 'eye' - ], - [ - 'onclick' => 'populateAndLoadModal(\'/individuals/edit/[onclick_params_data_path]\');', - 'onclick_params_data_path' => 'id', - 'icon' => 'edit' - ], - [ - 'onclick' => 'populateAndLoadModal(\'/individuals/delete/[onclick_params_data_path]\');', - 'onclick_params_data_path' => 'id', - 'icon' => 'trash' ] ] ] diff --git a/templates/Open/Organisations/index.php b/templates/Open/Organisations/index.php index 794f929..e74a5f2 100644 --- a/templates/Open/Organisations/index.php +++ b/templates/Open/Organisations/index.php @@ -77,16 +77,6 @@ echo $this->element('genericElements/IndexTable/index_table', [ 'url' => '/organisations/view', 'url_params_data_paths' => ['id'], 'icon' => 'eye' - ], - [ - 'onclick' => 'populateAndLoadModal(\'/organisations/edit/[onclick_params_data_path]\');', - 'onclick_params_data_path' => 'id', - 'icon' => 'edit' - ], - [ - 'onclick' => 'populateAndLoadModal(\'/organisations/delete/[onclick_params_data_path]\');', - 'onclick_params_data_path' => 'id', - 'icon' => 'trash' ] ] ] diff --git a/templates/Organisations/index.php b/templates/Organisations/index.php index d19cc49..5358dd1 100644 --- a/templates/Organisations/index.php +++ b/templates/Organisations/index.php @@ -78,15 +78,15 @@ echo $this->element('genericElements/IndexTable/index_table', [ 'icon' => 'eye' ], [ - 'onclick' => 'populateAndLoadModal(\'/organisations/edit/[onclick_params_data_path]\');', - 'onclick_params_data_path' => 'id', + 'open_modal' => '/organisations/edit/[onclick_params_data_path]', + 'modal_params_data_path' => 'id', 'icon' => 'edit' ], [ - 'onclick' => 'populateAndLoadModal(\'/organisations/delete/[onclick_params_data_path]\');', - 'onclick_params_data_path' => 'id', + 'open_modal' => '/organisations/delete/[onclick_params_data_path]', + 'modal_params_data_path' => 'id', 'icon' => 'trash' - ] + ], ] ] ]); diff --git a/templates/Roles/index.php b/templates/Roles/index.php index 4f45807..e3fec85 100644 --- a/templates/Roles/index.php +++ b/templates/Roles/index.php @@ -64,15 +64,15 @@ echo $this->element('genericElements/IndexTable/index_table', [ 'icon' => 'eye' ], [ - 'onclick' => 'populateAndLoadModal(\'/roles/edit/[onclick_params_data_path]\');', - 'onclick_params_data_path' => 'id', - 'icon' => 'edit', + 'open_modal' => '/roles/edit/[onclick_params_data_path]', + 'modal_params_data_path' => 'id', + 'icon' => 'edit' ], [ - 'onclick' => 'populateAndLoadModal(\'/roles/delete/[onclick_params_data_path]\');', - 'onclick_params_data_path' => 'id', + 'open_modal' => '/roles/delete/[onclick_params_data_path]', + 'modal_params_data_path' => 'id', 'icon' => 'trash' - ] + ], ] ] ]); diff --git a/templates/SharingGroups/index.php b/templates/SharingGroups/index.php index 070624a..357e79f 100644 --- a/templates/SharingGroups/index.php +++ b/templates/SharingGroups/index.php @@ -60,15 +60,15 @@ echo $this->element('genericElements/IndexTable/index_table', [ 'icon' => 'eye' ], [ - 'onclick' => 'populateAndLoadModal(\'/sharingGroups/edit/[onclick_params_data_path]\');', - 'onclick_params_data_path' => 'id', + 'open_modal' => '/sharingGroups/edit/[onclick_params_data_path]', + 'modal_params_data_path' => 'id', 'icon' => 'edit' ], [ - 'onclick' => 'populateAndLoadModal(\'/sharingGroups/delete/[onclick_params_data_path]\');', - 'onclick_params_data_path' => 'id', + 'open_modal' => '/sharingGroups/delete/[onclick_params_data_path]', + 'modal_params_data_path' => 'id', 'icon' => 'trash' - ] + ], ] ] ]); diff --git a/templates/SharingGroups/list_orgs.php b/templates/SharingGroups/list_orgs.php index c7bbe23..0c6fd96 100644 --- a/templates/SharingGroups/list_orgs.php +++ b/templates/SharingGroups/list_orgs.php @@ -52,10 +52,10 @@ echo $this->element('genericElements/IndexTable/index_table', [ 'icon' => 'eye' ], [ - 'onclick' => 'populateAndLoadModal(\'/sharingGroups/removeOrg/' . h($sharing_group_id) . '/[onclick_params_data_path]\');', - 'onclick_params_data_path' => 'id', + 'open_modal' => '/sharingGroups/removeOrg/' . h($sharing_group_id) . '/[onclick_params_data_path]', + 'modal_params_data_path' => 'id', 'icon' => 'trash' - ] + ], ] ] ]); diff --git a/templates/Users/index.php b/templates/Users/index.php index 7d7ef0d..9da12ba 100644 --- a/templates/Users/index.php +++ b/templates/Users/index.php @@ -86,15 +86,15 @@ echo $this->element('genericElements/IndexTable/index_table', [ 'icon' => 'eye' ], [ - 'onclick' => 'openModalFromURL(\'/users/edit/[onclick_params_data_path]\');', - 'onclick_params_data_path' => 'id', + 'open_modal' => '/users/edit/[onclick_params_data_path]', + 'modal_params_data_path' => 'id', 'icon' => 'edit' ], [ - 'onclick' => 'openModalFromURL(\'/users/delete/[onclick_params_data_path]\');', - 'onclick_params_data_path' => 'id', + 'open_modal' => '/users/delete/[onclick_params_data_path]', + 'modal_params_data_path' => 'id', 'icon' => 'trash' - ] + ], ] ] ]); diff --git a/templates/element/genericElements/IndexTable/Fields/actions.php b/templates/element/genericElements/IndexTable/Fields/actions.php index 17707b4..216e46b 100644 --- a/templates/element/genericElements/IndexTable/Fields/actions.php +++ b/templates/element/genericElements/IndexTable/Fields/actions.php @@ -80,6 +80,14 @@ $action['onclick'] ); + } else if (!empty($action['open_modal']) && !empty($action['modal_params_data_path'])) { + $modal_url = str_replace( + '[onclick_params_data_path]', + h(Cake\Utility\Hash::extract($row, $action['modal_params_data_path'])[0]), + $action['open_modal'] + ); + $reload_url = !empty($action['reload_url']) ? $action['reload_url'] : $this->Url->build(['action' => 'index']); + $action['onclick'] = sprintf('UI.openModalFromURL(\'%s\', \'%s\', \'%s\')', $modal_url, $reload_url, $tableRandomValue); } echo sprintf( ' ', diff --git a/templates/element/genericElements/IndexTable/Fields/alignments.php b/templates/element/genericElements/IndexTable/Fields/alignments.php index 1ee3df6..145cb59 100644 --- a/templates/element/genericElements/IndexTable/Fields/alignments.php +++ b/templates/element/genericElements/IndexTable/Fields/alignments.php @@ -13,10 +13,10 @@ if ($field['scope'] === 'individuals') { h($alignment['organisation']['name']) ), !$canRemove ? '' : sprintf( - "populateAndLoadModal(%s);", + "UI.openModalFromURL(%s);", sprintf( "'/alignments/delete/%s'", - $alignment['id'] + h($alignment['id']) ) ) ); @@ -32,10 +32,10 @@ if ($field['scope'] === 'individuals') { h($alignment['individual']['email']) ), !$canRemove ? '' : sprintf( - "populateAndLoadModal(%s);", + "UI.openModalFromURL(%s);", sprintf( "'/alignments/delete/%s'", - $alignment['id'] + h($alignment['id']) ) ) ); diff --git a/templates/element/genericElements/ListTopBar/element_simple.php b/templates/element/genericElements/ListTopBar/element_simple.php index 3ecd987..4e2f401 100644 --- a/templates/element/genericElements/ListTopBar/element_simple.php +++ b/templates/element/genericElements/ListTopBar/element_simple.php @@ -2,7 +2,7 @@ if (!isset($data['requirement']) || $data['requirement']) { if (!empty($data['popover_url'])) { $onClick = sprintf( - 'onClick="openModalFromURL(%s)"', + 'onClick="openModalForButton(%s)"', sprintf("'%s'", h($data['popover_url'])) ); } @@ -60,8 +60,8 @@ empty($data['fa-icon']) ? '' : sprintf( ' ', empty($data['fa-source']) ? 'fas' : h($data['fa-source']), - $data['fa-icon'] - ), // this has to be sanitised beforehand! + h($data['fa-icon']) + ), empty($data['html']) ? '' : $data['html'], // this has to be sanitised beforehand! empty($data['text']) ? '' : h($data['text']) ); @@ -69,9 +69,7 @@ ?> \ No newline at end of file diff --git a/templates/element/genericElements/ListTopBar/group_context_filters.php b/templates/element/genericElements/ListTopBar/group_context_filters.php index baa9254..e2b12c8 100644 --- a/templates/element/genericElements/ListTopBar/group_context_filters.php +++ b/templates/element/genericElements/ListTopBar/group_context_filters.php @@ -9,8 +9,16 @@ ]; $currentQuery = $this->request->getQuery(); unset($currentQuery['page'], $currentQuery['limit'], $currentQuery['sort']); + if (!empty($filteringContext['filterCondition'])) { // PHP replaces `.` by `_` when fetching the request parameter + $currentFilteringContextKey = array_key_first($filteringContext['filterCondition']); + $currentFilteringContext = [ + str_replace('.', '_', $currentFilteringContextKey) => $filteringContext['filterCondition'][$currentFilteringContextKey] + ]; + } else { + $currentFilteringContext = $filteringContext['filterCondition']; + } $contextArray[] = [ - 'active' => $currentQuery == $filteringContext['filterCondition'], + 'active' => $currentQuery == $currentFilteringContext, 'isFilter' => true, 'onClick' => 'UI.reload', 'onClickParams' => [ diff --git a/templates/element/genericElements/SingleViews/Fields/alignmentField.php b/templates/element/genericElements/SingleViews/Fields/alignmentField.php index 7d93530..32018b4 100644 --- a/templates/element/genericElements/SingleViews/Fields/alignmentField.php +++ b/templates/element/genericElements/SingleViews/Fields/alignmentField.php @@ -19,7 +19,7 @@ if ($field['scope'] === 'individuals') { h($alignment['organisation']['name']) ), sprintf( - "populateAndLoadModal(%s);", + "UI.openModalFromURL(%s);", sprintf( "'/alignments/delete/%s'", $alignment['id'] @@ -38,7 +38,7 @@ if ($field['scope'] === 'individuals') { h($alignment['individual']['email']) ), sprintf( - "populateAndLoadModal(%s);", + "UI.openModalFromURL(%s);", sprintf( "'/alignments/delete/%s'", $alignment['id'] @@ -51,7 +51,7 @@ echo sprintf( '
%s
', $alignments, sprintf( - "populateAndLoadModal('/alignments/add/%s/%s');", + "UI.openModalFromURL('/alignments/add/%s/%s');", h($field['scope']), h($extracted['id']) ), diff --git a/templates/element/genericElements/SingleViews/single_view.php b/templates/element/genericElements/SingleViews/single_view.php index 0e2dd49..b17244f 100644 --- a/templates/element/genericElements/SingleViews/single_view.php +++ b/templates/element/genericElements/SingleViews/single_view.php @@ -28,6 +28,7 @@ * ]); * */ + $tableRandomValue = Cake\Utility\Security::randomString(8); $listElements = ''; if (!empty($fields)) { foreach ($fields as $field) { @@ -109,18 +110,20 @@ __('{0} view', \Cake\Utility\Inflector::singularize(\Cake\Utility\Inflector::humanize($this->request->getParam('controller')))) : $title; echo sprintf( - "
+ "

%s

%s%s
- %s
+ %s
%s
%s
", + $tableRandomValue, h($title), empty($description) ? '' : sprintf('

%s

', h($description)), empty($description_html) ? '' : sprintf('

%s

', $description_html), + $tableRandomValue, $listElements, $metaTemplateTabs, $ajaxLists diff --git a/templates/element/genericElements/side_menu_scaffold.php b/templates/element/genericElements/side_menu_scaffold.php index 2993a0b..93d2ce1 100644 --- a/templates/element/genericElements/side_menu_scaffold.php +++ b/templates/element/genericElements/side_menu_scaffold.php @@ -35,7 +35,7 @@ if (isset($menu[$metaGroup])) { } $active = ($scope === $this->request->getParam('controller') && $action === $this->request->getParam('action')); if (!empty($data['popup'])) { - $link_template = '%s'; + $link_template = '%s'; } else { $link_template = '%s'; } diff --git a/webroot/js/bootstrap-helper.js b/webroot/js/bootstrap-helper.js index 591f075..93bf054 100644 --- a/webroot/js/bootstrap-helper.js +++ b/webroot/js/bootstrap-helper.js @@ -45,6 +45,35 @@ class UIFactory { }) } + /** + * Create and display a modal where the modal's content is fetched from the provided URL. Reload the table after a successful operation + * @param {string} url - The URL from which the modal's content should be fetched + * @param {string} tableId - The table ID which should be reloaded on success + * @return {Promise} Promise object resolving to the ModalFactory object + */ + openModalFromURL(url, reloadUrl=false, tableId=false) { + UI.modalFromURL(url, () => { + if (reloadUrl === false || tableId === false) { // Try to get information from the DOM + let $elligibleTable = $('table.table') + let currentModel = location.pathname.split('/')[1] + if ($elligibleTable.length == 1 && currentModel.length > 0) { + let $container = $elligibleTable.closest('div[id^="table-container-"]') + if ($container.length == 1) { + return UI.reload(`/${currentModel}/index`, $container, $elligibleTable) + } else { + $container = $elligibleTable.closest('div[id^="single-view-table-container-"]') + if ($container.length == 1) { + return UI.reload(location.pathname, $container, $elligibleTable) + } + } + } + } else { + return UI.reload(reloadUrl, $(`#table-container-${tableId}`), $(`#table-container-${tableId} table.table`)) + } + location.reload() + }) + } + /** * Fetch HTML from the provided URL and override the $container's content. $statusNode allows to specify another HTML node to display the loading * @param {string} url - The URL from which the $container's content should be fetched @@ -495,7 +524,7 @@ class ModalFactory { this.hide() } }) - .catch(() => { + .catch((err) => { this.options.APIError(() => { this.hide() }, this, evt) }) } diff --git a/webroot/js/main.js b/webroot/js/main.js index 6a185a1..1eea566 100644 --- a/webroot/js/main.js +++ b/webroot/js/main.js @@ -1,15 +1,3 @@ -function populateAndLoadModal(url) { - $.ajax({ - dataType:"html", - cache: false, - success:function (data, textStatus) { - $("#mainModal").html(data); - $("#mainModal").modal('show'); - }, - url:url, - }); -} - function executePagination(randomValue, url) { var target = '#table-container-' + randomValue $.ajax({