(function(angular, $, _) {
- angular.module('afformCore').directive('afformApi3Ctrl', function() {
+ angular.module('afformCore').directive('afApi3Ctrl', function() {
return {
restrict: 'EA',
scope: {
- afformApi3Ctrl: '=',
- afformApi3: '@',
- afformApi3Refresh: '@',
+ afApi3Ctrl: '=',
+ afApi3: '@',
+ afApi3Refresh: '@',
onRefresh: '@'
},
- controllerAs: 'afformApi3Ctrl',
+ controllerAs: 'afApi3Ctrl',
controller: function($scope, $parse, crmThrottle, crmApi) {
var ctrl = this;
// CONSIDER: Trade-offs of upfront vs ongoing evaluation.
- var parts = $parse($scope.afformApi3)($scope.$parent);
+ var parts = $parse($scope.afApi3)($scope.$parent);
ctrl.entity = parts[0];
ctrl.action = parts[1];
ctrl.params = parts[2];
});
};
- $scope.afformApi3Ctrl = this;
+ $scope.afApi3Ctrl = this;
- var mode = $scope.afformApi3Refresh ? $scope.afformApi3Refresh : 'auto';
+ var mode = $scope.afApi3Refresh ? $scope.afApi3Refresh : 'auto';
switch (mode) {
- case 'auto': $scope.$watchCollection('afformApi3Ctrl.params', ctrl.refresh); break;
+ case 'auto': $scope.$watchCollection('afApi3Ctrl.params', ctrl.refresh); break;
case 'init': ctrl.refresh(); break;
case 'manual': break;
default: throw 'Unrecognized refresh mode: '+ mode;
-# afform-api3-ctrl
+# af-api3-ctrl
This directive is designed for querying and displaying data from APIv3. Each API call is represented with an object like this:
}
```
-You can initialize this object using `<afform-api3-ctrl>` and `<afform-api3>`, as in:
+You can initialize this object using `<af-api3-ctrl>` and `<af-api3>`, as in:
```html
<div
- afform-api3-ctrl="apiData"
- afform-api3="['Contact','get', {display_name: ''}]">
+ af-api3-ctrl="apiData"
+ af-api3="['Contact','get', {display_name: ''}]">
<div crm-ui-debug="apiData"></div>
By default, the API call will refresh its results automatically - as soon as the filter parameters change.
-If you'd rather wait and trigger the refresh another way, then set the `afform-api3-refresh` policy to `init` or `manual`. Don't forget to fire the refresh some other way, such as `ng-click`:
+If you'd rather wait and trigger the refresh another way, then set the `af-api3-refresh` policy to `init` or `manual`. Don't forget to fire the refresh some other way, such as `ng-click`:
```html
<div
- afform-api3-ctrl="apiData"
- afform-api3="['Contact','get', {display_name: ''}]"
- afform-api3-refresh="init">
+ af-api3-ctrl="apiData"
+ af-api3="['Contact','get', {display_name: ''}]"
+ af-api3-refresh="init">
<div crm-ui-debug="apiData"></div>
```html
<div
- afform-api3-ctrl="apiData"
- afform-api3="['Contact','get', {display_name: ''}]"
+ af-api3-ctrl="apiData"
+ af-api3="['Contact','get', {display_name: ''}]"
on-refresh="doSomething(result)">
...
</div>
```
How do we use the `cid` to get information about the contact? Update `helloWorld.aff.html` to fetch data with
-`Contact.get` API and call the [afform-api3](https://github.com/totten/afform/blob/master/ang/afformCore/Api3Ctrl.md) utility:
+`Contact.get` API and call the [af-api3](https://github.com/totten/afform/blob/master/ang/afformCore/Api3Ctrl.md) utility:
```html
<div ng-if="!routeParams.cid">
{{ts('Please provide the "cid"')}}
</div>
<div ng-if="routeParams.cid"
- afform-api3="['Contact', 'get', {id: routeParams.cid}]"
- afform-api3-ctrl="apiData">
+ af-api3="['Contact', 'get', {id: routeParams.cid}]"
+ af-api3-ctrl="apiData">
<div ng-repeat="contact in apiData.result.values">
<h1 crm-page-title="">{{contact.display_name}}</h1>