1 (function(angular
, $, _
) {
3 angular
.module('afCore').directive('afApi3Ctrl', function() {
12 controllerAs
: 'afApi3Ctrl',
13 controller: function($scope
, $parse
, crmThrottle
, crmApi
) {
16 // CONSIDER: Trade-offs of upfront vs ongoing evaluation.
17 var parts
= $parse($scope
.afApi3
)($scope
.$parent
);
18 ctrl
.entity
= parts
[0];
19 ctrl
.action
= parts
[1];
20 ctrl
.params
= parts
[2];
22 ctrl
.loading
= ctrl
.firstLoad
= true;
24 ctrl
.refresh
= function refresh() {
26 crmThrottle(function () {
27 return crmApi(ctrl
.entity
, ctrl
.action
, ctrl
.params
)
28 .then(function (response
) {
29 ctrl
.result
= response
;
30 ctrl
.loading
= ctrl
.firstLoad
= false;
31 if ($scope
.onRefresh
) {
32 $scope
.$parent
.$eval($scope
.onRefresh
, ctrl
);
38 $scope
.afApi3Ctrl
= this;
40 var mode
= $scope
.afApi3Refresh
? $scope
.afApi3Refresh
: 'auto';
42 case 'auto': $scope
.$watchCollection('afApi3Ctrl.params', ctrl
.refresh
); break;
43 case 'init': ctrl
.refresh(); break;
45 default: throw 'Unrecognized refresh mode: '+ mode
;
51 })(angular
, CRM
.$, CRM
._
);