Commit | Line | Data |
---|---|---|
0034006a TO |
1 | (function(angular, $, _) { |
2 | // Declare a list of dependencies. | |
c1b9955f | 3 | angular.module('afCore', CRM.angRequires('afCore')); |
ddae34c0 | 4 | |
c1b9955f | 5 | // Use `afCoreDirective(string name)` to generate an AngularJS directive. |
0a7837ca | 6 | angular.module('afCore').service('afCoreDirective', function($location, crmApi4, crmStatus, crmUiAlert) { |
7ea6ab60 | 7 | return function(camelName, meta, d) { |
04417491 | 8 | d.restrict = 'E'; |
ddae34c0 | 9 | d.scope = {}; |
4fa089bb | 10 | d.scope.options = '='; |
7ea6ab60 CW |
11 | d.link = { |
12 | pre: function($scope, $el, $attr) { | |
13 | $scope.ts = CRM.ts(camelName); | |
7ea6ab60 CW |
14 | $scope.meta = meta; |
15 | $scope.crmApi4 = crmApi4; | |
16 | $scope.crmStatus = crmStatus; | |
17 | $scope.crmUiAlert = crmUiAlert; | |
18 | $scope.crmUrl = CRM.url; | |
0a7837ca CW |
19 | |
20 | // Afforms do not use routing, but some forms get input from search params | |
41161b88 CW |
21 | var dialog = $el.closest('.ui-dialog-content'); |
22 | if (!dialog.length) { | |
23 | // Full-screen mode | |
24 | $scope.$watch(function() {return $location.search();}, function(params) { | |
25 | $scope.routeParams = params; | |
26 | }); | |
27 | } else { | |
28 | // Use urlHash embedded in popup dialog | |
29 | $scope.routeParams = {}; | |
30 | if (dialog.data('urlHash')) { | |
31 | var searchParams = new URLSearchParams(dialog.data('urlHash')); | |
32 | searchParams.forEach(function(value, key) { | |
33 | $scope.routeParams[key] = value; | |
34 | }); | |
35 | } | |
36 | } | |
007167df CW |
37 | |
38 | $scope.$parent.afformTitle = meta.title; | |
39 | ||
40 | // Prepends a string to the afform title | |
41 | // Provides contextual titles to search Afforms in standalone mode | |
42 | $scope.addTitle = function(addition) { | |
43 | $scope.$parent.afformTitle = addition + ' ' + meta.title; | |
44 | }; | |
7ea6ab60 | 45 | } |
ddae34c0 TO |
46 | }; |
47 | return d; | |
48 | }; | |
49 | }); | |
0034006a | 50 | })(angular, CRM.$, CRM._); |