From eac1a6fd0d5ae78174f08a56506e99aa695906ec Mon Sep 17 00:00:00 2001 From: Vasia Korobkin Date: Tue, 9 Feb 2016 01:21:16 +0300 Subject: [PATCH] Callback-accepting permanentFilters: 1st implementation --- examples/blog/config.js | 3 +++ src/javascripts/ng-admin/Crud/field/maReferenceField.js | 5 +++++ .../ng-admin/Crud/fieldView/ReferenceFieldView.js | 2 +- 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/examples/blog/config.js b/examples/blog/config.js index ae9078b6..ec1b4276 100644 --- a/examples/blog/config.js +++ b/examples/blog/config.js @@ -325,6 +325,9 @@ refreshDelay: 200, searchQuery: function(search) { return { q: search }; } }) + .permanentFilters(function(entry) { + return {author: entry['author.name']}; + }) ]); comment.editionView() diff --git a/src/javascripts/ng-admin/Crud/field/maReferenceField.js b/src/javascripts/ng-admin/Crud/field/maReferenceField.js index fcde6975..9d8f9659 100644 --- a/src/javascripts/ng-admin/Crud/field/maReferenceField.js +++ b/src/javascripts/ng-admin/Crud/field/maReferenceField.js @@ -31,6 +31,11 @@ export default function maReferenceField(ReferenceRefresher) { })); scope.$broadcast('choices:update', { choices: initialChoices }); } else { + if (!!field._getPermanentFilters) { + scope.$watch('entry.values', function(newValue, oldValue){ + field._getPermanentFilters(newValue); + }, true); + } // ui-select doesn't allow to prepopulate autocomplete selects, see https://github.com/angular-ui/ui-select/issues/1197 // let ui-select fetch the options using the ReferenceRefresher scope.refresh = function refresh(search) { diff --git a/src/javascripts/ng-admin/Crud/fieldView/ReferenceFieldView.js b/src/javascripts/ng-admin/Crud/fieldView/ReferenceFieldView.js index c44284dd..d1750f19 100644 --- a/src/javascripts/ng-admin/Crud/fieldView/ReferenceFieldView.js +++ b/src/javascripts/ng-admin/Crud/fieldView/ReferenceFieldView.js @@ -2,5 +2,5 @@ export default { getReadWidget: () => '', getLinkWidget: () => '', getFilterWidget: () => '', - getWriteWidget: () => '' + getWriteWidget: () => '' };