From 20f0ffe01a98db0ac5b47235f5fbf01f8af35bc6 Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Fri, 13 Sep 2019 20:57:39 -0400 Subject: [PATCH] af/Form.js - Get the form name implicitly (without a global) --- ext/afform/core/CRM/Afform/Page/AfformBase.php | 1 - ext/afform/core/ang/af/Form.js | 8 ++++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/ext/afform/core/CRM/Afform/Page/AfformBase.php b/ext/afform/core/CRM/Afform/Page/AfformBase.php index 8684e04315..3d389528b6 100644 --- a/ext/afform/core/CRM/Afform/Page/AfformBase.php +++ b/ext/afform/core/CRM/Afform/Page/AfformBase.php @@ -13,7 +13,6 @@ class CRM_Afform_Page_AfformBase extends CRM_Core_Page { $loader->setPageName(implode('/', $pagePath)); $loader->getRes()->addSetting([ 'afform' => [ - 'name' => $pageArgs['afform'], 'open' => _afform_angular_module_name($pageArgs['afform'], 'dash'), ], ]); diff --git a/ext/afform/core/ang/af/Form.js b/ext/afform/core/ang/af/Form.js index 304ea43e0e..c5098391e6 100644 --- a/ext/afform/core/ang/af/Form.js +++ b/ext/afform/core/ang/af/Form.js @@ -37,6 +37,10 @@ this.getSchema = function getSchema(name) { return schema[name]; }; + // Returns the 'meta' record ('name', 'description', etc) of the active form. + this.getFormMeta = function getFormMeta() { + return $scope.$parent.meta; + }; this.loadData = function() { var toLoad = 0; _.each(schema, function(entity, entityName) { @@ -45,7 +49,7 @@ } }); if (toLoad) { - crmApi4('Afform', 'prefill', {name: CRM.afform.name, args: $routeParams}) + crmApi4('Afform', 'prefill', {name: this.getFormMeta().name, args: $routeParams}) .then(function(result) { _.each(result, function(item) { data[item.name] = _.extend(item.values, schema[item.name].data || {}); @@ -55,7 +59,7 @@ }; this.submit = function submit() { - crmApi4('Afform', 'submit', {name: CRM.afform.name, args: $routeParams, values: data}); + crmApi4('Afform', 'submit', {name: this.getFormMeta().name, args: $routeParams, values: data}); }; } }; -- 2.25.1