From 1d23311bc6f0c5eeced1916de14f2654c2e5daf9 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Tue, 25 Jun 2019 21:42:29 -0400 Subject: [PATCH] Load data from ids passed in url --- ext/afform/core/ang/af/ModelList.js | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/ext/afform/core/ang/af/ModelList.js b/ext/afform/core/ang/af/ModelList.js index cdbe8b9f47..8976fe0e29 100644 --- a/ext/afform/core/ang/af/ModelList.js +++ b/ext/afform/core/ang/af/ModelList.js @@ -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; @@ -32,6 +39,20 @@ 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'); -- 2.25.1