From 8410442c139aa5159ed74338e96f34d91b41b59f Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Fri, 13 Sep 2019 13:13:44 -0400 Subject: [PATCH] Rename `[af-name]` to `af-model[name]` and `af-fieldset[model]` --- ext/afform/core/CRM/Afform/ArrayHtml.php | 6 ++-- ext/afform/core/Civi/Afform/Utils.php | 4 +-- .../core/Civi/Api4/Action/Afform/Prefill.php | 6 ++-- ext/afform/core/afform.php | 4 +-- ext/afform/core/ang/af/Fieldset.js | 12 +++---- ext/afform/core/ang/af/Form.js | 4 +-- ext/afform/core/ang/af/Model.js | 4 +-- ext/afform/core/ang/afBlock/ContactEmail.html | 2 +- ext/afform/core/ang/afBlock/ContactName.html | 2 +- ext/afform/core/ang/afBlock/ContactName.js | 2 +- ext/afform/core/ang/afField/afField.js | 4 +-- ext/afform/docs/sandbox/planning-v0.3.md | 36 +++++++++---------- ext/afform/mock/ang/afex.aff.html | 14 ++++---- 13 files changed, 50 insertions(+), 50 deletions(-) diff --git a/ext/afform/core/CRM/Afform/ArrayHtml.php b/ext/afform/core/CRM/Afform/ArrayHtml.php index acf0ac6fcc..0a536f829b 100644 --- a/ext/afform/core/CRM/Afform/ArrayHtml.php +++ b/ext/afform/core/CRM/Afform/ArrayHtml.php @@ -22,7 +22,7 @@ class CRM_Afform_ArrayHtml { '*' => 'text', ], 'af-model' => [ - 'af-name' => 'text', + 'name' => 'text', 'af-entity' => 'text', 'data' => 'js', ], @@ -31,7 +31,7 @@ class CRM_Afform_ArrayHtml { 'defn' => 'js', ], 'af-fieldset' => [ - 'af-name' => 'text', + 'model' => 'text', ], ]; @@ -160,7 +160,7 @@ class CRM_Afform_ArrayHtml { * @param string $tag * Ex: 'af-model' * @param string $attrName - * Ex: 'af-name' + * Ex: 'label' * @return string * Ex: 'text' or 'js' */ diff --git a/ext/afform/core/Civi/Afform/Utils.php b/ext/afform/core/Civi/Afform/Utils.php index 9095ed0208..d343894dc8 100644 --- a/ext/afform/core/Civi/Afform/Utils.php +++ b/ext/afform/core/Civi/Afform/Utils.php @@ -11,7 +11,7 @@ class Utils { * @return array */ public static function getEntities($layout) { - $entities = array_column(self::getTags($layout, 'af-model'), NULL, 'af-name'); + $entities = array_column(self::getTags($layout, 'af-model'), NULL, 'name'); self::getFields($layout, $entities); return $entities; } @@ -41,7 +41,7 @@ class Utils { protected static function getFields($layout, &$entities) { foreach ($layout['#children'] as $child) { if ($child['#tag'] == 'af-fieldset' && !empty($child['#children'])) { - $entities[$child['af-name']]['fields'] = array_merge($entities[$child['af-name']]['fields'] ?? [], self::getTags($child, 'af-field')); + $entities[$child['model']]['fields'] = array_merge($entities[$child['model']]['fields'] ?? [], self::getTags($child, 'af-field')); } elseif (!empty($child['#children'])) { self::getFields($child['#children'], $entities); diff --git a/ext/afform/core/Civi/Api4/Action/Afform/Prefill.php b/ext/afform/core/Civi/Api4/Action/Afform/Prefill.php index 0a05e550de..f7c64d77ca 100644 --- a/ext/afform/core/Civi/Api4/Action/Afform/Prefill.php +++ b/ext/afform/core/Civi/Api4/Action/Afform/Prefill.php @@ -37,9 +37,9 @@ class Prefill extends AbstractProcessor { */ private function loadEntity($entity, $id) { $checkPermissions = TRUE; - if ($entity['type'] == 'Contact' && !empty($this->args[$entity['af-name'] . '-cs'])) { + if ($entity['type'] == 'Contact' && !empty($this->args[$entity['name'] . '-cs'])) { $checkSum = civicrm_api4('Contact', 'validateChecksum', [ - 'checksum' => $this->args[$entity['af-name'] . '-cs'], + 'checksum' => $this->args[$entity['name'] . '-cs'], 'contactId' => $id, ]); $checkPermissions = empty($checkSum[0]['valid']); @@ -50,7 +50,7 @@ class Prefill extends AbstractProcessor { 'checkPermissions' => $checkPermissions, ]); if ($result->first()) { - $this->_data[$entity['af-name']] = $result->first(); + $this->_data[$entity['name']] = $result->first(); } } diff --git a/ext/afform/core/afform.php b/ext/afform/core/afform.php index ae148d8bd0..6eb602bc1f 100644 --- a/ext/afform/core/afform.php +++ b/ext/afform/core/afform.php @@ -182,7 +182,7 @@ function afform_civicrm_alterAngular($angular) { foreach (pq('af-field', $doc) as $afField) { /** @var DOMElement $afField */ $fieldName = $afField->getAttribute('name'); - $entityName = pq($afField)->parent('af-fieldset[af-name]')->attr('af-name'); // TEST ME + $entityName = pq($afField)->parent('af-fieldset[model]')->attr('model'); // TEST ME if (!preg_match(';^[a-zA-Z0-9\_\-\. ]+$;', $entityName)) { throw new \CRM_Core_Exception("Cannot process $path: malformed entity name ($entityName)"); } @@ -215,7 +215,7 @@ function afform_civicrm_alterAngular($angular) { function _afform_getMetadata(phpQueryObject $doc) { $entities = []; foreach ($doc->find('af-model') as $afmModelProp) { - $entities[$afmModelProp->getAttribute('af-name')] = [ + $entities[$afmModelProp->getAttribute('name')] = [ 'type' => $afmModelProp->getAttribute('type'), ]; } diff --git a/ext/afform/core/ang/af/Fieldset.js b/ext/afform/core/ang/af/Fieldset.js index 6afe95b664..72e6e5481d 100644 --- a/ext/afform/core/ang/af/Fieldset.js +++ b/ext/afform/core/ang/af/Fieldset.js @@ -1,30 +1,30 @@ (function(angular, $, _) { // "afFieldset" is a basic skeletal directive. - // Example usage: ... ... ... + // Example usage: ... ... ... angular.module('af').directive('afFieldset', function() { return { restrict: 'AE', require: '^afForm', scope: { - afName: '@' + modelName: '@model' }, link: function($scope, $el, $attr, afFormCtrl) { $scope.afFormCtrl = afFormCtrl; // This is faster than waiting for each field directive to register itself $('af-field', $el).each(function() { - afFormCtrl.registerField($scope.afName, $(this).attr('name')) + afFormCtrl.registerField($scope.modelName, $(this).attr('name')) }); }, controller: function($scope){ this.getDefn = function getDefn() { - return $scope.afFormCtrl.getEntity($scope.afName); + return $scope.afFormCtrl.getEntity($scope.modelName); // return $scope.modelDefn; }; this.getData = function getData() { - return $scope.afFormCtrl.getData($scope.afName); + return $scope.afFormCtrl.getData($scope.modelName); }; this.getName = function() { - return $scope.afName; + return $scope.modelName; } } }; diff --git a/ext/afform/core/ang/af/Form.js b/ext/afform/core/ang/af/Form.js index 2ebd7867fa..a8196bfccd 100644 --- a/ext/afform/core/ang/af/Form.js +++ b/ext/afform/core/ang/af/Form.js @@ -21,8 +21,8 @@ $scope.myCtrl = this; this.registerEntity = function registerEntity(entity) { - schema[entity.afName] = entity; - data[entity.afName] = entity.data || {}; + schema[entity.modelName] = entity; + data[entity.modelName] = entity.data || {}; }; this.registerField = function(entityName, fieldName) { schema[entityName].fields.push(fieldName); diff --git a/ext/afform/core/ang/af/Model.js b/ext/afform/core/ang/af/Model.js index 21e442dfa2..b7390a43ff 100644 --- a/ext/afform/core/ang/af/Model.js +++ b/ext/afform/core/ang/af/Model.js @@ -1,13 +1,13 @@ (function(angular, $, _) { // "afModel" is a basic skeletal directive. - // Example usage: ... ... + // Example usage: ... ... angular.module('af').directive('afModel', function() { // Whitelist of all allowed properties of an af-fieldset // (at least the ones we care about client-side - other's can be added for server-side processing and we'll just ignore them) var modelProps = { type: '@', data: '=', - afName: '@', + modelName: '@name', label: '@', autofill: '@' }; diff --git a/ext/afform/core/ang/afBlock/ContactEmail.html b/ext/afform/core/ang/afBlock/ContactEmail.html index 0a451eb5b8..295dcbada0 100644 --- a/ext/afform/core/ang/afBlock/ContactEmail.html +++ b/ext/afform/core/ang/afBlock/ContactEmail.html @@ -1 +1 @@ -
{{ts('Contact email block for a model of type %1 named %2', {1: afFieldset.getDefn().type, 2: afFieldset.getDefn().afName})}}
+
{{ts('Contact email block for a model of type %1 named %2', {1: afFieldset.getDefn().type, 2: afFieldset.getDefn().modelName})}}
diff --git a/ext/afform/core/ang/afBlock/ContactName.html b/ext/afform/core/ang/afBlock/ContactName.html index f991556625..541edcc84d 100644 --- a/ext/afform/core/ang/afBlock/ContactName.html +++ b/ext/afform/core/ang/afBlock/ContactName.html @@ -1 +1 @@ -
{{ts('Contact name block for a model of type %1 named %2', {1: afFieldset.getDefn().type, 2: afFieldset.getDefn().afName})}}
+
{{ts('Contact name block for a model of type %1 named %2', {1: afFieldset.getDefn().type, 2: afFieldset.getDefn().modelName})}}
diff --git a/ext/afform/core/ang/afBlock/ContactName.js b/ext/afform/core/ang/afBlock/ContactName.js index da68c0b45b..46cb104419 100644 --- a/ext/afform/core/ang/afBlock/ContactName.js +++ b/ext/afform/core/ang/afBlock/ContactName.js @@ -1,5 +1,5 @@ (function(angular, $, _) { - // Example usage: + // Example usage: angular.module('afBlock').directive('afBlockContactName', function() { return { restrict: 'AE', diff --git a/ext/afform/core/ang/afField/afField.js b/ext/afform/core/ang/afField/afField.js index fb618405af..4a3c9b1a96 100644 --- a/ext/afform/core/ang/afField/afField.js +++ b/ext/afform/core/ang/afField/afField.js @@ -1,5 +1,5 @@ (function(angular, $, _) { - // Example usage: + // Example usage: angular.module('afField').directive('afField', function() { return { restrict: 'E', @@ -13,7 +13,7 @@ var ts = $scope.ts = CRM.ts('afform'); $scope.afFieldset = ctrls[0]; var modelList = ctrls[1]; - $scope.fieldId = $scope.afFieldset.getDefn().afName + '-' + $scope.fieldName; + $scope.fieldId = $scope.afFieldset.getDefn().modelName + '-' + $scope.fieldName; $scope.getData = $scope.afFieldset.getData; $scope.getOptions = function() { diff --git a/ext/afform/docs/sandbox/planning-v0.3.md b/ext/afform/docs/sandbox/planning-v0.3.md index d7daf040cc..cce1eb4601 100644 --- a/ext/afform/docs/sandbox/planning-v0.3.md +++ b/ext/afform/docs/sandbox/planning-v0.3.md @@ -42,17 +42,17 @@ ```html
- + - + - + @@ -65,17 +65,17 @@ - + - + - + @@ -88,24 +88,24 @@ - + - + @@ -114,7 +114,7 @@ Your spouse should go to the gym.

- + @@ -133,11 +133,11 @@ - + - + @@ -150,13 +150,13 @@ @@ -164,14 +164,14 @@ - + - + @@ -183,7 +183,7 @@ Your spouse should go to the gym.

- + diff --git a/ext/afform/mock/ang/afex.aff.html b/ext/afform/mock/ang/afex.aff.html index edbd2b3bae..3a6af79182 100644 --- a/ext/afform/mock/ang/afex.aff.html +++ b/ext/afform/mock/ang/afex.aff.html @@ -1,28 +1,28 @@ - - - + + + - + - + - + - + -- 2.25.1