Load data from ids passed in url
authorColeman Watts <coleman@civicrm.org>
Wed, 26 Jun 2019 01:42:29 +0000 (21:42 -0400)
committerCiviCRM <info@civicrm.org>
Wed, 16 Sep 2020 02:13:18 +0000 (19:13 -0700)
ext/afform/core/ang/af/ModelList.js

index cdbe8b9f47ca9ce6f8ce989aeda809ce7ab2dd3d..8976fe0e29b3f7e30b9ef1b4602e23499f243b5a 100644 (file)
@@ -8,8 +8,15 @@
         // afModelList: '=',
         ctrl: '@'
       },
-      link: function($scope, $el, $attr) {},
-      controller: ['$scope', function($scope) {
+      link: {
+        pre: function($scope, $el, $attr) {
+
+        },
+        post: function($scope, $el, $attr) {
+          $scope.myCtrl.loadData();
+        }
+      },
+      controller: function($scope, $routeParams, crmApi4) {
         var schema = {}, data = {};
 
         $scope.$parent[$scope.ctrl] = this;
         this.getSchema = function getSchema(name) {
           return schema[name];
         };
+        this.loadData = function() {
+          var apiCalls = {};
+          _.each(schema, function(entity, entityName) {
+            if ($routeParams[entityName]) {
+              var id = $routeParams[entityName];
+              apiCalls[entityName] = [entity.type, 'get', {select: entity.fields, where: [['id', '=', id]]}, 0];
+            }
+          });
+          if (!_.isEmpty(apiCalls)) {
+            crmApi4(apiCalls).then(function(resp) {
+              data = resp;
+            });
+          }
+        };
 
         this.submit = function submit() {
           CRM.alert('TODO: Submit');