Commit | Line | Data |
---|---|---|
128850fd TO |
1 | (function(angular, $, _) { |
2 | angular.module('oauthUtil', CRM.angRequires('oauthUtil')); | |
3 | // Import data from the 'CRM.foo' settings. | |
4 | // Ex: <div oauth-util-import="CRM.oauthUtil.providers" to="theProviders" /> | |
5 | angular.module('oauthUtil').directive('oauthUtilImport', function() { | |
6 | return { | |
7 | restrict: 'EA', | |
8 | scope: { | |
9 | to: '=', | |
10 | oauthUtilImport: '@' | |
11 | }, | |
12 | controller: function($scope, $parse) { | |
13 | $scope.to = $parse($scope.oauthUtilImport)({CRM: CRM}); | |
14 | } | |
15 | }; | |
16 | }); | |
17 | angular.module('oauthUtil').directive('oauthUtilGrantCtrl', function() { | |
18 | return { | |
19 | restrict: 'EA', | |
20 | scope: { | |
21 | oauthUtilGrantCtrl: '=' | |
22 | }, | |
23 | controllerAs: 'oauthUtilGrantCtrl', | |
24 | controller: function($scope, $parse, crmBlocker, crmApi4, crmStatus) { | |
25 | var block = crmBlocker(); | |
26 | var ctrl = this; | |
27 | ctrl.authCode = function(clientId) { | |
28 | var confirmOpt = { | |
29 | message: ts('You are about to be redirected to an external site.'), | |
30 | options: {no: ts('Cancel'), yes: ts('Continue')} | |
31 | }; | |
32 | CRM.confirm(confirmOpt) | |
33 | .on('crmConfirm:yes', function(){ | |
34 | var going = crmApi4('OAuthClient', 'authorizationCode', { | |
35 | 'landingUrl': window.location.href, | |
36 | 'where': [['id', '=', clientId]] | |
37 | }).then(function(r){ | |
38 | window.location = r[0].url; | |
39 | }); | |
40 | return block(crmStatus({start: ts('Redirecting...'), success: ts('Redirecting...')}, going)); | |
41 | }); | |
42 | }; | |
43 | ||
44 | $scope.oauthUtilGrantCtrl = this; | |
45 | } | |
46 | }; | |
47 | }); | |
48 | })(angular, CRM.$, CRM._); |