X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=ext%2Fsearch_kit%2Fang%2FcrmSearchAdmin%2FcrmSearchAdmin.component.js;h=1100fe36f60108290defd58f21a754a6b83ddb39;hb=ea04af0c9483be804df873fbb54515e97286662a;hp=f6b22aeeaadf9ee67d1a21c675ca17d8d88ee9cd;hpb=088ae5a300c506b6896afbdff3ed85740430149c;p=civicrm-core.git diff --git a/ext/search_kit/ang/crmSearchAdmin/crmSearchAdmin.component.js b/ext/search_kit/ang/crmSearchAdmin/crmSearchAdmin.component.js index f6b22aeeaa..1100fe36f6 100644 --- a/ext/search_kit/ang/crmSearchAdmin/crmSearchAdmin.component.js +++ b/ext/search_kit/ang/crmSearchAdmin/crmSearchAdmin.component.js @@ -9,10 +9,12 @@ controller: function($scope, $element, $location, $timeout, crmApi4, dialogService, searchMeta) { var ts = $scope.ts = CRM.ts('org.civicrm.search_kit'), ctrl = this, + afformLoad, fieldsForJoinGetters = {}; this.DEFAULT_AGGREGATE_FN = 'GROUP_CONCAT'; - + this.afformEnabled = CRM.crmSearchAdmin.afformEnabled; + this.afformAdminEnabled = CRM.crmSearchAdmin.afformAdminEnabled; this.displayTypes = _.indexBy(CRM.crmSearchAdmin.displayTypes, 'id'); $scope.controls = {tab: 'compose', joinType: 'LEFT'}; @@ -73,6 +75,7 @@ }); loadFieldOptions(); + loadAfforms(); }; function onChangeAnything() { @@ -151,6 +154,16 @@ } else if (!display.trashed) { $scope.selectTab('display_' + index); } + if (display.trashed && afformLoad) { + afformLoad.then(function() { + if (ctrl.afforms[display.name]) { + var msg = ctrl.afforms[display.name].length === 1 ? + ts('Form "%1" will be deleted if the embedded display "%2" is deleted.', {1: ctrl.afforms[display.name][0].title, 2: display.label}) : + ts('%1 forms will be deleted if the embedded display "%2" is deleted.', {1: ctrl.afforms[display.name].length, 2: display.label}); + CRM.alert(msg, ts('Display embedded'), 'alert'); + } + }); + } } else { $scope.selectTab('compose'); ctrl.savedSearch.displays.splice(index, 1); @@ -696,6 +709,37 @@ return _.uniq(links, 'path'); }; + function loadAfforms() { + if (ctrl.afformEnabled && ctrl.savedSearch.id) { + var findDisplays = _.transform(ctrl.savedSearch.displays, function(findDisplays, display) { + if (display.id && display.name) { + findDisplays.push(['search_displays', 'CONTAINS', ctrl.savedSearch.name + '.' + display.name]); + } + }, [['search_displays', 'CONTAINS', ctrl.savedSearch.name]]); + afformLoad = crmApi4('Afform', 'get', { + select: ['name', 'title', 'search_displays'], + where: [['OR', findDisplays]] + }).then(function(afforms) { + ctrl.afforms = {}; + _.each(afforms, function(afform) { + _.each(_.uniq(afform.search_displays), function(searchNameDisplayName) { + var displayName = searchNameDisplayName.split('.')[1] || ''; + ctrl.afforms[displayName] = ctrl.afforms[displayName] || []; + ctrl.afforms[displayName].push({ + title: afform.title, + link: ctrl.afformAdminEnabled ? CRM.url('civicrm/admin/afform#/edit/' + afform.name) : '', + }); + }); + }); + }); + } + } + + // Creating an Afform opens a new tab, so when switching back to this tab, re-check for Afforms + $(window).on('focus', _.debounce(function() { + $scope.$apply(loadAfforms); + }, 10000, {leading: true, trailing: false})); + } });