From 2fc4caec71c05320bda26a3f0e69c10250a19778 Mon Sep 17 00:00:00 2001 From: nathangray Date: Wed, 24 Oct 2018 11:10:48 -0600 Subject: [PATCH] * Infolog - Exclude current entry from parent select/search results to avoid loop --- api/src/Link.php | 6 +++++- infolog/js/app.js | 24 ++++++++++++++++++++++++ infolog/templates/default/edit.xet | 2 +- 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/api/src/Link.php b/api/src/Link.php index 8f5b3cfcfb..281fb48714 100644 --- a/api/src/Link.php +++ b/api/src/Link.php @@ -755,7 +755,7 @@ class Link extends Link\Storage * * @param string $app app to search * @param string $pattern pattern to search - * @param array& $options passed to callback: type, start, num_rows, filter; on return value for "total" + * @param array& $options passed to callback: type, start, num_rows, filter, exclude; on return value for "total" * @return array with $id => $title pairs of matching entries of app */ static function query($app, $pattern, &$options = array()) @@ -778,6 +778,10 @@ class Link extends Link\Storage { $options['total'] = count($result); } + if (isset($options['exclude'])) + { + $result = array_diff_key($result, array_flip($options['exclude'])); + } if (is_array($result) && (isset($options['start']) || (isset($options['num_rows']) && count($result) > $options['num_rows']))) { $result = array_slice($result, $options['start'], (isset($options['num_rows']) ? $options['num_rows'] : count($result)), true); diff --git a/infolog/js/app.js b/infolog/js/app.js index 558ffbbff7..6c17bfa364 100644 --- a/infolog/js/app.js +++ b/infolog/js/app.js @@ -648,6 +648,30 @@ app.classes.infolog = AppJS.extend( } }, + /** + * Mess with the query for parent widget to exclude self + * + * @param {Object} request + * @param {et2_link_entry} widget + * @returns {boolean} + */ + parent_query: function(request, widget) + { + // No ID yet, no need to filter + if(!widget.getRoot().getArrayMgr('content').getEntry('info_id')) + { + return true; + } + if(!request.options) + { + request.options = {}; + } + // Exclude self from results - no app needed since it's just one app + request.options.exclude = [widget.getRoot().getArrayMgr('content').getEntry('info_id')]; + + return true; + }, + /** * View a list of timesheets for the linked infolog entry * diff --git a/infolog/templates/default/edit.xet b/infolog/templates/default/edit.xet index f8cc33154f..8b3c2a51cf 100644 --- a/infolog/templates/default/edit.xet +++ b/infolog/templates/default/edit.xet @@ -113,7 +113,7 @@ - +