From e91ee81da963972dce7f592808c8677ee9ee9028 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Mon, 11 Jan 2021 13:27:07 -0500 Subject: [PATCH 1/6] Afform - add option group for afform types --- ext/afform/core/managed/AfformType.mgd.php | 74 ++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 ext/afform/core/managed/AfformType.mgd.php diff --git a/ext/afform/core/managed/AfformType.mgd.php b/ext/afform/core/managed/AfformType.mgd.php new file mode 100644 index 000000000000..e0865d731c64 --- /dev/null +++ b/ext/afform/core/managed/AfformType.mgd.php @@ -0,0 +1,74 @@ + 'AfformType', + 'entity' => 'OptionGroup', + 'params' => [ + 'name' => 'afform_type', + 'title' => 'Afform Type', + ], + ], + [ + 'name' => 'AfformType:form', + 'entity' => 'OptionValue', + 'params' => [ + 'option_group_id' => 'afform_type', + 'name' => 'form', + 'value' => 'form', + 'label' => 'Custom Form', + 'weight' => 0, + 'icon' => 'fa-list-alt', + ], + ], + [ + 'name' => 'AfformType:block', + 'entity' => 'OptionValue', + 'params' => [ + 'option_group_id' => 'afform_type', + 'name' => 'block', + 'value' => 'block', + 'label' => 'Field Block', + 'weight' => 20, + 'icon' => 'fa-th-large', + ], + ], + [ + 'name' => 'AfformType:system', + 'entity' => 'OptionValue', + 'params' => [ + 'option_group_id' => 'afform_type', + 'name' => 'system', + 'value' => 'system', + 'label' => 'System Form', + 'weight' => 50, + 'icon' => 'fa-lock', + ], + ], +]; + +try { + $search = civicrm_api3('Extension', 'getsingle', [ + 'full_name' => "org.civicrm.search", + ]); + if ($search['status'] === 'installed') { + $mgd[] = [ + 'name' => 'AfformType:search', + 'entity' => 'OptionValue', + 'params' => [ + 'option_group_id' => 'afform_type', + 'name' => 'search', + 'value' => 'search', + 'label' => 'Search Display', + 'weight' => 10, + 'icon' => 'fa-search', + ], + ]; + } +} +catch (Exception $e) { + // ¯\_(ツ)_/¯ +} + +return $mgd; From 23fd8685d6afec45c44cf89b5a052084fb8f1228 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Mon, 11 Jan 2021 14:35:25 -0500 Subject: [PATCH 2/6] Afform GUI - Rename service from afAdmin to afGiu --- ext/afform/admin/ang/afGuiEditor.js | 2 +- .../ang/afGuiEditor/afGuiEditor.component.js | 20 +++++------ .../ang/afGuiEditor/afGuiEntity.component.js | 18 +++++----- .../afGuiMenuItemBackground.component.js | 6 ++-- .../afGuiMenuItemBorder.component.js | 6 ++-- .../elements/afGuiButton.component.js | 8 ++--- .../elements/afGuiContainer.component.js | 36 +++++++++---------- .../elements/afGuiField.component.js | 6 ++-- .../elements/afGuiText.component.js | 10 +++--- 9 files changed, 56 insertions(+), 56 deletions(-) diff --git a/ext/afform/admin/ang/afGuiEditor.js b/ext/afform/admin/ang/afGuiEditor.js index d604e57fb368..2acf4f7322a8 100644 --- a/ext/afform/admin/ang/afGuiEditor.js +++ b/ext/afform/admin/ang/afGuiEditor.js @@ -2,7 +2,7 @@ "use strict"; angular.module('afGuiEditor', CRM.angRequires('afGuiEditor')) - .service('afAdmin', function(crmApi4, $parse, $q) { + .service('afGui', function(crmApi4, $parse, $q) { // Parse strings of javascript that php couldn't interpret function evaluate(collection) { diff --git a/ext/afform/admin/ang/afGuiEditor/afGuiEditor.component.js b/ext/afform/admin/ang/afGuiEditor/afGuiEditor.component.js index 7cdc06b35e89..428b903684f2 100644 --- a/ext/afform/admin/ang/afGuiEditor/afGuiEditor.component.js +++ b/ext/afform/admin/ang/afGuiEditor/afGuiEditor.component.js @@ -8,12 +8,12 @@ name: '<' }, controllerAs: 'editor', - controller: function($scope, crmApi4, afAdmin, $parse, $timeout, $location) { + controller: function($scope, crmApi4, afGui, $parse, $timeout, $location) { var ts = $scope.ts = CRM.ts('afform'); $scope.afform = null; $scope.saving = false; $scope.selectedEntityName = null; - this.meta = afAdmin.meta; + this.meta = afGui.meta; var editor = this; var newForm = { title: '', @@ -27,7 +27,7 @@ this.$onInit = function() { // Fetch the current form plus all blocks - afAdmin.initialize(editor.name) + afGui.initialize(editor.name) .then(initializeForm); }; @@ -42,12 +42,12 @@ } $scope.canvasTab = 'layout'; $scope.layoutHtml = ''; - editor.layout = afAdmin.findRecursive($scope.afform.layout, {'#tag': 'af-form'})[0]; - $scope.entities = afAdmin.findRecursive(editor.layout['#children'], {'#tag': 'af-entity'}, 'name'); + editor.layout = afGui.findRecursive($scope.afform.layout, {'#tag': 'af-form'})[0]; + $scope.entities = afGui.findRecursive(editor.layout['#children'], {'#tag': 'af-entity'}, 'name'); if (editor.name == '0') { editor.addEntity('Individual'); - editor.layout['#children'].push(afAdmin.meta.elements.submit.element); + editor.layout['#children'].push(afGui.meta.elements.submit.element); } // Set changesSaved to true on initial load, false thereafter whenever changes are made to the model @@ -69,7 +69,7 @@ }; this.addEntity = function(type) { - var meta = afAdmin.meta.entities[type], + var meta = afGui.meta.entities[type], num = 1; // Give this new entity a unique name while (!!$scope.entities[type + num]) { @@ -85,7 +85,7 @@ var pos = 1 + _.findLastIndex(editor.layout['#children'], {'#tag': 'af-entity'}); editor.layout['#children'].splice(pos, 0, $scope.entities[type + num]); // Create a new af-fieldset container for the entity - var fieldset = _.cloneDeep(afAdmin.meta.elements.fieldset.element); + var fieldset = _.cloneDeep(afGui.meta.elements.fieldset.element); fieldset['af-fieldset'] = type + num; fieldset['#children'][0]['#children'][0]['#text'] = meta.label + ' ' + num; // Add default contact name block @@ -104,8 +104,8 @@ this.removeEntity = function(entityName) { delete $scope.entities[entityName]; - afAdmin.removeRecursive(editor.layout['#children'], {'#tag': 'af-entity', name: entityName}); - afAdmin.removeRecursive(editor.layout['#children'], {'af-fieldset': entityName}); + afGui.removeRecursive(editor.layout['#children'], {'#tag': 'af-entity', name: entityName}); + afGui.removeRecursive(editor.layout['#children'], {'af-fieldset': entityName}); this.selectEntity(null); }; diff --git a/ext/afform/admin/ang/afGuiEditor/afGuiEntity.component.js b/ext/afform/admin/ang/afGuiEditor/afGuiEntity.component.js index 37a141614d21..4c5c8d8a470c 100644 --- a/ext/afform/admin/ang/afGuiEditor/afGuiEntity.component.js +++ b/ext/afform/admin/ang/afGuiEditor/afGuiEntity.component.js @@ -8,7 +8,7 @@ entity: '<' }, require: {editor: '^^afGuiEditor'}, - controller: function ($scope, $timeout, afAdmin) { + controller: function ($scope, $timeout, afGui) { var ts = $scope.ts = CRM.ts(); var ctrl = this; $scope.controls = {}; @@ -23,10 +23,10 @@ } $scope.getMeta = function() { - return afAdmin.meta.entities[getEntityType()]; + return afGui.meta.entities[getEntityType()]; }; - $scope.getField = afAdmin.getField; + $scope.getField = afGui.getField; $scope.valuesFields = function() { var fields = _.transform($scope.getMeta().fields, function(fields, field) { @@ -55,7 +55,7 @@ fields: filterFields($scope.getMeta().fields) }); - _.each(afAdmin.meta.entities, function(entity, entityName) { + _.each(afGui.meta.entities, function(entity, entityName) { if (check(ctrl.editor.layout['#children'], {'af-join': entityName})) { $scope.fieldList.push({ entityName: ctrl.entity.name + '-join-' + entityName, @@ -81,7 +81,7 @@ function buildBlockList(search) { $scope.blockList.length = 0; $scope.blockTitles.length = 0; - _.each(afAdmin.meta.blocks, function(block, directive) { + _.each(afGui.meta.blocks, function(block, directive) { if ((!search || _.contains(directive, search) || _.contains(block.name.toLowerCase(), search) || _.contains(block.title.toLowerCase(), search)) && (block.block === '*' || block.block === ctrl.entity.type || (ctrl.entity.type === 'Contact' && block.block === ctrl.entity.data.contact_type)) ) { @@ -106,7 +106,7 @@ function buildElementList(search) { $scope.elementList.length = 0; $scope.elementTitles.length = 0; - _.each(afAdmin.meta.elements, function(element, name) { + _.each(afGui.meta.elements, function(element, name) { if (!search || _.contains(name, search) || _.contains(element.title.toLowerCase(), search)) { var node = _.cloneDeep(element.element); if (name === 'fieldset') { @@ -144,7 +144,7 @@ if (block['af-join']) { return check(ctrl.editor.layout['#children'], {'af-join': block['af-join']}); } - var fieldsInBlock = _.pluck(afAdmin.findRecursive(afAdmin.meta.blocks[block['#tag']].layout, {'#tag': 'af-field'}), 'name'); + var fieldsInBlock = _.pluck(afGui.findRecursive(afGui.meta.blocks[block['#tag']].layout, {'#tag': 'af-field'}), 'name'); return check(ctrl.editor.layout['#children'], function(item) { return item['#tag'] === 'af-field' && _.includes(fieldsInBlock, item.name); }); @@ -170,8 +170,8 @@ check(item['#children'], criteria, found); } // Recurse into block directives - else if (item['#tag'] && item['#tag'] in afAdmin.meta.blocks) { - check(afAdmin.meta.blocks[item['#tag']].layout, criteria, found); + else if (item['#tag'] && item['#tag'] in afGui.meta.blocks) { + check(afGui.meta.blocks[item['#tag']].layout, criteria, found); } } }); diff --git a/ext/afform/admin/ang/afGuiEditor/afGuiMenuItemBackground.component.js b/ext/afform/admin/ang/afGuiEditor/afGuiMenuItemBackground.component.js index 569acf057f70..bc2014588bd4 100644 --- a/ext/afform/admin/ang/afGuiEditor/afGuiMenuItemBackground.component.js +++ b/ext/afform/admin/ang/afGuiEditor/afGuiMenuItemBackground.component.js @@ -8,15 +8,15 @@ bindings: { node: '=' }, - controller: function($scope, afAdmin) { + controller: function($scope, afGui) { var ts = $scope.ts = CRM.ts(), ctrl = this; $scope.getSetBackgroundColor = function(color) { if (!arguments.length) { - return afAdmin.getStyles(ctrl.node)['background-color'] || '#ffffff'; + return afGui.getStyles(ctrl.node)['background-color'] || '#ffffff'; } - afAdmin.setStyle(ctrl.node, 'background-color', color); + afGui.setStyle(ctrl.node, 'background-color', color); }; } }); diff --git a/ext/afform/admin/ang/afGuiEditor/afGuiMenuItemBorder.component.js b/ext/afform/admin/ang/afGuiEditor/afGuiMenuItemBorder.component.js index c8b84cff6a28..e22ec9c84798 100644 --- a/ext/afform/admin/ang/afGuiEditor/afGuiMenuItemBorder.component.js +++ b/ext/afform/admin/ang/afGuiEditor/afGuiMenuItemBorder.component.js @@ -8,7 +8,7 @@ bindings: { node: '=' }, - controller: function($scope, afAdmin) { + controller: function($scope, afGui) { var ts = $scope.ts = CRM.ts(), ctrl = this; @@ -30,11 +30,11 @@ return border[idx]; } border[idx] = val; - afAdmin.setStyle(node, 'border', val ? border.join(' ') : null); + afGui.setStyle(node, 'border', val ? border.join(' ') : null); } function getBorder(node) { - var border = _.map((afAdmin.getStyles(node).border || '').split(' '), _.trim); + var border = _.map((afGui.getStyles(node).border || '').split(' '), _.trim); return border.length > 2 ? border : null; } } diff --git a/ext/afform/admin/ang/afGuiEditor/elements/afGuiButton.component.js b/ext/afform/admin/ang/afGuiEditor/elements/afGuiButton.component.js index 65eb081f60a5..47773ef52250 100644 --- a/ext/afform/admin/ang/afGuiEditor/elements/afGuiButton.component.js +++ b/ext/afform/admin/ang/afGuiEditor/elements/afGuiButton.component.js @@ -8,7 +8,7 @@ node: '=', deleteThis: '&' }, - controller: function($scope, afAdmin) { + controller: function($scope, afGui) { var ts = $scope.ts = CRM.ts(), ctrl = this; @@ -24,13 +24,13 @@ // Getter/setter for ng-model $scope.getSetStyle = function(val) { if (arguments.length) { - return afAdmin.modifyClasses(ctrl.node, _.keys($scope.styles), ['btn', val]); + return afGui.modifyClasses(ctrl.node, _.keys($scope.styles), ['btn', val]); } - return _.intersection(afAdmin.splitClass(ctrl.node['class']), _.keys($scope.styles))[0] || ''; + return _.intersection(afGui.splitClass(ctrl.node['class']), _.keys($scope.styles))[0] || ''; }; $scope.pickIcon = function() { - afAdmin.pickIcon().then(function(val) { + afGui.pickIcon().then(function(val) { ctrl.node['crm-icon'] = val; }); }; diff --git a/ext/afform/admin/ang/afGuiEditor/elements/afGuiContainer.component.js b/ext/afform/admin/ang/afGuiEditor/elements/afGuiContainer.component.js index 5fb23982da1f..7cf73a63f1f4 100644 --- a/ext/afform/admin/ang/afGuiEditor/elements/afGuiContainer.component.js +++ b/ext/afform/admin/ang/afGuiEditor/elements/afGuiContainer.component.js @@ -11,12 +11,12 @@ deleteThis: '&' }, require: {editor: '^^afGuiEditor'}, - controller: function($scope, crmApi4, dialogService, afAdmin) { + controller: function($scope, crmApi4, dialogService, afGui) { var ts = $scope.ts = CRM.ts(), ctrl = this; this.$onInit = function() { - if ((ctrl.node['#tag'] in afAdmin.meta.blocks) || ctrl.join) { + if ((ctrl.node['#tag'] in afGui.meta.blocks) || ctrl.join) { initializeBlockContainer(); } }; @@ -46,7 +46,7 @@ }; $scope.isRepeatable = function() { - return ctrl.node['af-fieldset'] || (block.directive && afAdmin.meta.blocks[block.directive].repeat) || ctrl.join; + return ctrl.node['af-fieldset'] || (block.directive && afGui.meta.blocks[block.directive].repeat) || ctrl.join; }; $scope.toggleRepeat = function() { @@ -92,7 +92,7 @@ }; $scope.pickAddIcon = function() { - afAdmin.pickIcon().then(function(val) { + afGui.pickIcon().then(function(val) { ctrl.node['add-icon'] = val; }); }; @@ -130,7 +130,7 @@ if (!ctrl.node) { return ''; } - return _.intersection(afAdmin.splitClass(ctrl.node['class']), _.keys($scope.layouts))[0] || 'af-layout-rows'; + return _.intersection(afGui.splitClass(ctrl.node['class']), _.keys($scope.layouts))[0] || 'af-layout-rows'; }; $scope.setLayout = function(val) { @@ -138,12 +138,12 @@ if (val !== 'af-layout-rows') { classes.push(val); } - afAdmin.modifyClasses(ctrl.node, _.keys($scope.layouts), classes); + afGui.modifyClasses(ctrl.node, _.keys($scope.layouts), classes); }; $scope.selectBlockDirective = function() { if (block.directive) { - block.layout = _.cloneDeep(afAdmin.meta.blocks[block.directive].layout); + block.layout = _.cloneDeep(afGui.meta.blocks[block.directive].layout); block.original = block.directive; setBlockDirective(block.directive); } @@ -167,7 +167,7 @@ listeners: [] }; - _.each(afAdmin.meta.blocks, function(blockInfo, directive) { + _.each(afGui.meta.blocks, function(blockInfo, directive) { if (directive === ctrl.node['#tag'] || blockInfo.join === ctrl.getFieldEntityType()) { block.options.push({ id: directive, @@ -176,13 +176,13 @@ } }); - if (getBlockNode() && getBlockNode()['#tag'] in afAdmin.meta.blocks) { + if (getBlockNode() && getBlockNode()['#tag'] in afGui.meta.blocks) { block.directive = block.original = getBlockNode()['#tag']; - block.layout = _.cloneDeep(afAdmin.meta.blocks[block.directive].layout); + block.layout = _.cloneDeep(afGui.meta.blocks[block.directive].layout); } block.listeners.push($scope.$watch('block.layout', function (layout, oldVal) { - if (block.directive && layout && layout !== oldVal && !angular.equals(layout, afAdmin.meta.blocks[block.directive].layout)) { + if (block.directive && layout && layout !== oldVal && !angular.equals(layout, afGui.meta.blocks[block.directive].layout)) { overrideBlockContents(block.layout); } }, true)); @@ -204,16 +204,16 @@ model.join = ctrl.join; } if ($scope.block && $scope.block.original) { - model.title = afAdmin.meta.blocks[$scope.block.original].title; - model.name = afAdmin.meta.blocks[$scope.block.original].name; - model.block = afAdmin.meta.blocks[$scope.block.original].block; + model.title = afGui.meta.blocks[$scope.block.original].title; + model.name = afGui.meta.blocks[$scope.block.original].name; + model.block = afGui.meta.blocks[$scope.block.original].block; } else { model.block = ctrl.container.getFieldEntityType() || '*'; } dialogService.open('saveBlockDialog', '~/afGuiEditor/saveBlock.html', model, options) .then(function(block) { - afAdmin.meta.blocks[block.directive_name] = block; + afGui.meta.blocks[block.directive_name] = block; setBlockDirective(block.directive_name); initializeBlockContainer(); }); @@ -234,17 +234,17 @@ if (node['af-join']) { return 'join'; } - if (node['#tag'] && node['#tag'] in afAdmin.meta.blocks) { + if (node['#tag'] && node['#tag'] in afGui.meta.blocks) { return 'container'; } - var classes = afAdmin.splitClass(node['class']), + var classes = afGui.splitClass(node['class']), types = ['af-container', 'af-text', 'af-button', 'af-markup'], type = _.intersection(types, classes); return type.length ? type[0].replace('af-', '') : null; }; this.removeElement = function(element) { - afAdmin.removeRecursive($scope.getSetChildren(), {$$hashKey: element.$$hashKey}); + afGui.removeRecursive($scope.getSetChildren(), {$$hashKey: element.$$hashKey}); }; this.getEntityName = function() { diff --git a/ext/afform/admin/ang/afGuiEditor/elements/afGuiField.component.js b/ext/afform/admin/ang/afGuiEditor/elements/afGuiField.component.js index d04dd5a96c44..107d4684b94b 100644 --- a/ext/afform/admin/ang/afGuiEditor/elements/afGuiField.component.js +++ b/ext/afform/admin/ang/afGuiEditor/elements/afGuiField.component.js @@ -12,7 +12,7 @@ editor: '^^afGuiEditor', container: '^^afGuiContainer' }, - controller: function($scope, afAdmin) { + controller: function($scope, afGui) { var ts = $scope.ts = CRM.ts(), ctrl = this; @@ -23,7 +23,7 @@ ]; this.$onInit = function() { - $scope.meta = afAdmin.meta; + $scope.meta = afGui.meta; }; $scope.getEntity = function() { @@ -31,7 +31,7 @@ }; $scope.getDefn = this.getDefn = function() { - return ctrl.editor ? afAdmin.getField(ctrl.container.getFieldEntityType(), ctrl.node.name) : {}; + return ctrl.editor ? afGui.getField(ctrl.container.getFieldEntityType(), ctrl.node.name) : {}; }; $scope.hasOptions = function() { diff --git a/ext/afform/admin/ang/afGuiEditor/elements/afGuiText.component.js b/ext/afform/admin/ang/afGuiEditor/elements/afGuiText.component.js index 8ce16894c145..6c045edd2f45 100644 --- a/ext/afform/admin/ang/afGuiEditor/elements/afGuiText.component.js +++ b/ext/afform/admin/ang/afGuiEditor/elements/afGuiText.component.js @@ -8,7 +8,7 @@ node: '=', deleteThis: '&' }, - controller: function($scope, afAdmin) { + controller: function($scope, afGui) { var ts = $scope.ts = CRM.ts(), ctrl = this; @@ -31,11 +31,11 @@ }; $scope.getAlign = function() { - return _.intersection(afAdmin.splitClass(ctrl.node['class']), _.keys($scope.alignments))[0] || 'text-left'; + return _.intersection(afGui.splitClass(ctrl.node['class']), _.keys($scope.alignments))[0] || 'text-left'; }; $scope.setAlign = function(val) { - afAdmin.modifyClasses(ctrl.node, _.keys($scope.alignments), val === 'text-left' ? null : val); + afGui.modifyClasses(ctrl.node, _.keys($scope.alignments), val === 'text-left' ? null : val); }; $scope.styles = _.transform(CRM.afGuiEditor.styles, function(styles, val, key) { @@ -45,9 +45,9 @@ // Getter/setter for ng-model $scope.getSetStyle = function(val) { if (arguments.length) { - return afAdmin.modifyClasses(ctrl.node, _.keys($scope.styles), val === 'text-default' ? null : val); + return afGui.modifyClasses(ctrl.node, _.keys($scope.styles), val === 'text-default' ? null : val); } - return _.intersection(afAdmin.splitClass(ctrl.node['class']), _.keys($scope.styles))[0] || 'text-default'; + return _.intersection(afGui.splitClass(ctrl.node['class']), _.keys($scope.styles))[0] || 'text-default'; }; } From 9e58ceedbeba33102e5a02cee135966833337158 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Wed, 13 Jan 2021 10:21:30 -0500 Subject: [PATCH 3/6] Afform - refactor admin page to use routing, add tabbed UI --- .../admin/CRM/AfformAdmin/Page/Base.php | 32 ++++++++++ ext/afform/admin/CRM/AfformAdmin/Utils.php | 17 +++++- ext/afform/admin/ang/afAdmin.aff.html | 7 --- ext/afform/admin/ang/afAdmin.aff.json | 8 --- ext/afform/admin/ang/afAdmin.ang.php | 15 +++++ ext/afform/admin/ang/afAdmin.js | 30 ++++++++++ .../ang/afAdmin/afAdminGui.controller.js | 15 +++++ .../ang/afAdmin/afAdminList.controller.js | 51 ++++++++++++++++ ext/afform/admin/ang/afAdmin/afAdminList.html | 59 +++++++++++++++++++ ext/afform/admin/ang/afAdminList.aff.html | 55 ----------------- ext/afform/admin/ang/afGuiEditor.ang.php | 2 +- .../ang/afGuiEditor/afGuiEditor.component.js | 11 ++-- .../admin/ang/afGuiEditor/afGuiEditor.html | 8 ++- .../templates/CRM/AfformAdmin/Page/Base.tpl | 0 ext/afform/admin/xml/Menu/afform_admin.xml | 8 +++ ext/afform/core/Civi/Api4/Afform.php | 3 + .../core/ang/afblockNameHousehold.aff.json | 1 + .../core/ang/afblockNameIndividual.aff.json | 1 + .../core/ang/afblockNameOrganization.aff.json | 1 + .../core/ang/afjoinAddressDefault.aff.json | 1 + .../core/ang/afjoinEmailDefault.aff.json | 1 + ext/afform/core/ang/afjoinIMDefault.aff.json | 1 + .../core/ang/afjoinPhoneDefault.aff.json | 1 + .../core/ang/afjoinWebsiteDefault.aff.json | 1 + 24 files changed, 249 insertions(+), 80 deletions(-) create mode 100644 ext/afform/admin/CRM/AfformAdmin/Page/Base.php delete mode 100644 ext/afform/admin/ang/afAdmin.aff.html delete mode 100644 ext/afform/admin/ang/afAdmin.aff.json create mode 100644 ext/afform/admin/ang/afAdmin.ang.php create mode 100644 ext/afform/admin/ang/afAdmin.js create mode 100644 ext/afform/admin/ang/afAdmin/afAdminGui.controller.js create mode 100644 ext/afform/admin/ang/afAdmin/afAdminList.controller.js create mode 100644 ext/afform/admin/ang/afAdmin/afAdminList.html delete mode 100644 ext/afform/admin/ang/afAdminList.aff.html create mode 100644 ext/afform/admin/templates/CRM/AfformAdmin/Page/Base.tpl create mode 100644 ext/afform/admin/xml/Menu/afform_admin.xml diff --git a/ext/afform/admin/CRM/AfformAdmin/Page/Base.php b/ext/afform/admin/CRM/AfformAdmin/Page/Base.php new file mode 100644 index 000000000000..31338e5eaf53 --- /dev/null +++ b/ext/afform/admin/CRM/AfformAdmin/Page/Base.php @@ -0,0 +1,32 @@ + ts('Forms'), + 'url' => CRM_Utils_System::url('civicrm/admin/afform', NULL, FALSE, '/'), + ]; + CRM_Utils_System::appendBreadCrumb([$breadCrumb]); + + // Load angular module + $loader = new Civi\Angular\AngularLoader(); + $loader->setPageName('civicrm/admin/afform'); + $loader->useApp(); + $loader->load(); + parent::run(); + } + +} diff --git a/ext/afform/admin/CRM/AfformAdmin/Utils.php b/ext/afform/admin/CRM/AfformAdmin/Utils.php index 00cf47ba82b5..5233a295d112 100644 --- a/ext/afform/admin/CRM/AfformAdmin/Utils.php +++ b/ext/afform/admin/CRM/AfformAdmin/Utils.php @@ -3,12 +3,27 @@ class CRM_AfformAdmin_Utils { + /** + * @return array + */ + public static function getAdminSettings() { + return [ + 'afform_type' => \Civi\Api4\OptionValue::get(FALSE) + ->addSelect('name', 'label', 'icon') + ->addWhere('is_active', '=', TRUE) + ->addWhere('option_group_id:name', '=', 'afform_type') + ->addOrderBy('weight', 'ASC') + ->execute(), + ]; + } + /** * Loads metadata for the gui editor. * * FIXME: This is a prototype and should get broken out into separate callbacks with hooks, events, etc. + * @return array */ - public static function getAngularSettings() { + public static function getGuiSettings() { $getFieldParams = [ 'checkPermissions' => FALSE, 'includeCustom' => TRUE, diff --git a/ext/afform/admin/ang/afAdmin.aff.html b/ext/afform/admin/ang/afAdmin.aff.html deleted file mode 100644 index ad443fe3e60b..000000000000 --- a/ext/afform/admin/ang/afAdmin.aff.html +++ /dev/null @@ -1,7 +0,0 @@ -
- -
- -
- -
diff --git a/ext/afform/admin/ang/afAdmin.aff.json b/ext/afform/admin/ang/afAdmin.aff.json deleted file mode 100644 index 22078f8bed53..000000000000 --- a/ext/afform/admin/ang/afAdmin.aff.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "title": "Afform Administration", - "server_route": "civicrm/admin/afform", - "permission": "administer CiviCRM", - "requires": [ - "afGuiEditor" - ] -} diff --git a/ext/afform/admin/ang/afAdmin.ang.php b/ext/afform/admin/ang/afAdmin.ang.php new file mode 100644 index 000000000000..818a6f4ca052 --- /dev/null +++ b/ext/afform/admin/ang/afAdmin.ang.php @@ -0,0 +1,15 @@ + [ + 'ang/afAdmin.js', + 'ang/afAdmin/*.js', + 'ang/afAdmin/*/*.js', + ], + 'css' => [], + 'partials' => ['ang/afAdmin'], + 'requires' => ['api4', 'afGuiEditor', 'crmRouteBinder'], + 'settingsFactory' => ['CRM_AfformAdmin_Utils', 'getAdminSettings'], + 'basePages' => ['civicrm/admin/afform'], + 'bundles' => ['bootstrap3'], +]; diff --git a/ext/afform/admin/ang/afAdmin.js b/ext/afform/admin/ang/afAdmin.js new file mode 100644 index 000000000000..1284b00bb7dc --- /dev/null +++ b/ext/afform/admin/ang/afAdmin.js @@ -0,0 +1,30 @@ +(function(angular, $, _) { + "use strict"; + angular.module('afAdmin', CRM.angRequires('afAdmin')) + + .config(function($routeProvider) { + $routeProvider.when('/', { + controller: 'afAdminList', + reloadOnSearch: false, + templateUrl: '~/afAdmin/afAdminList.html', + resolve: { + // Load data for lists + afforms: function(crmApi4) { + return crmApi4('Afform', 'get', { + select: ['name', 'title', 'type', 'is_public', 'server_route', 'has_local', 'has_base'], + orderBy: {title: 'ASC'} + }); + } + } + }); + $routeProvider.when('/create/:type', { + controller: 'afAdminGui', + template: '', + }); + $routeProvider.when('/edit/:name', { + controller: 'afAdminGui', + template: '', + }); + }); + +})(angular, CRM.$, CRM._); diff --git a/ext/afform/admin/ang/afAdmin/afAdminGui.controller.js b/ext/afform/admin/ang/afAdmin/afAdminGui.controller.js new file mode 100644 index 000000000000..a7713e31b876 --- /dev/null +++ b/ext/afform/admin/ang/afAdmin/afAdminGui.controller.js @@ -0,0 +1,15 @@ +(function(angular, $, _) { + "use strict"; + + angular.module('afAdmin').controller('afAdminGui', function($scope, $routeParams) { + var ts = $scope.ts = CRM.ts(), + ctrl = $scope.$ctrl = this; + + // Edit mode + this.name = $routeParams.name; + // Create mode + this.type = $routeParams.type; + + }); + +})(angular, CRM.$, CRM._); diff --git a/ext/afform/admin/ang/afAdmin/afAdminList.controller.js b/ext/afform/admin/ang/afAdmin/afAdminList.controller.js new file mode 100644 index 000000000000..682b17aa3321 --- /dev/null +++ b/ext/afform/admin/ang/afAdmin/afAdminList.controller.js @@ -0,0 +1,51 @@ +(function(angular, $, _) { + "use strict"; + + angular.module('afAdmin').controller('afAdminList', function($scope, afforms, crmApi4, crmStatus) { + var ts = $scope.ts = CRM.ts(), + ctrl = $scope.$ctrl = this; + + $scope.crmUrl = CRM.url; + + this.tabs = CRM.afAdmin.afform_type; + + this.afforms = _.transform(afforms, function(afforms, afform) { + var type = afform.type || 'system'; + afforms[type] = afforms[type] || []; + afforms[type].push(afform); + }, {}); + + $scope.$bindToRoute({ + expr: '$ctrl.tab', + param: 'tab', + format: 'raw', + default: ctrl.tabs[0].name + }); + + this.revert = function(afform) { + var index = _.findIndex(ctrl.afforms[ctrl.tab], {name: afform.name}); + if (index > -1) { + var apiOps = [['Afform', 'revert', {where: [['name', '=', afform.name]]}]]; + if (afform.has_base) { + apiOps.push(['Afform', 'get', { + where: [['name', '=', afform.name]], + select: ['name', 'title', 'type', 'is_public', 'server_route', 'has_local', 'has_base'] + }, 0]); + } + var apiCall = crmStatus( + afform.has_base ? {start: ts('Reverting...')} : {start: ts('Deleting...'), success: ts('Deleted')}, + crmApi4(apiOps) + ); + if (afform.has_base) { + afform.has_local = false; + apiCall.then(function(result) { + ctrl.afforms[ctrl.tab][index] = result[1]; + }); + } else { + ctrl.afforms[ctrl.tab].splice(index, 1); + } + } + }; + }); + +})(angular, CRM.$, CRM._); diff --git a/ext/afform/admin/ang/afAdmin/afAdminList.html b/ext/afform/admin/ang/afAdmin/afAdminList.html new file mode 100644 index 000000000000..80af2d876c4d --- /dev/null +++ b/ext/afform/admin/ang/afAdmin/afAdminList.html @@ -0,0 +1,59 @@ +
+

{{:: ts('Configurable Forms') }}

+ + + + + +
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
{{:: ts('Title') }}{{:: ts('Name') }}{{:: ts('Server Route') }}{{:: ts('Frontend?') }}
{{afform.title}} + {{afform.name}} + + + {{afform.server_route}} + + {{afform.is_public ? ts('Frontend') : ts('Backend')}} + {{ ts('Edit') }} + + {{ afform.has_base ? ts('Revert') : ts('Delete') }} + +
+

+ {{:: ts('None Found')}} +

+
+
diff --git a/ext/afform/admin/ang/afAdminList.aff.html b/ext/afform/admin/ang/afAdminList.aff.html deleted file mode 100644 index 8f572b4f8b54..000000000000 --- a/ext/afform/admin/ang/afAdminList.aff.html +++ /dev/null @@ -1,55 +0,0 @@ - - {{:: ts('New Form') }} - -
- -
- {{:: ts('None found.') }} -
- - - - - - - - - - - - - - - - - - - - -
{{:: ts('Name') }}{{:: ts('Title') }}{{:: ts('Server Route') }}{{:: ts('Frontend?') }}
- {{availForm.name}} - {{availForm.title}} - - {{availForm.server_route}} - - {{availForm.is_public ? ts('Frontend') : ts('Backend')}} - - {{:: ts('Revert') }} - {{:: ts('Delete') }} -
- -
diff --git a/ext/afform/admin/ang/afGuiEditor.ang.php b/ext/afform/admin/ang/afGuiEditor.ang.php index 99c6a5e70a21..4cca73306681 100644 --- a/ext/afform/admin/ang/afGuiEditor.ang.php +++ b/ext/afform/admin/ang/afGuiEditor.ang.php @@ -9,7 +9,7 @@ 'css' => ['ang/afGuiEditor.css'], 'partials' => ['ang/afGuiEditor'], 'requires' => ['crmUi', 'crmUtil', 'dialogService', 'api4', 'crmMonaco', 'ui.sortable'], - 'settingsFactory' => ['CRM_AfformAdmin_Utils', 'getAngularSettings'], + 'settingsFactory' => ['CRM_AfformAdmin_Utils', 'getGuiSettings'], 'basePages' => [], 'exports' => [ 'af-gui-editor' => 'E', diff --git a/ext/afform/admin/ang/afGuiEditor/afGuiEditor.component.js b/ext/afform/admin/ang/afGuiEditor/afGuiEditor.component.js index 428b903684f2..5d43f11f4a3a 100644 --- a/ext/afform/admin/ang/afGuiEditor/afGuiEditor.component.js +++ b/ext/afform/admin/ang/afGuiEditor/afGuiEditor.component.js @@ -5,6 +5,7 @@ angular.module('afGuiEditor').component('afGuiEditor', { templateUrl: '~/afGuiEditor/afGuiEditor.html', bindings: { + type: '<', name: '<' }, controllerAs: 'editor', @@ -18,6 +19,7 @@ var newForm = { title: '', permission: 'access CiviCRM', + type: 'form', layout: [{ '#tag': 'af-form', ctrl: 'afform', @@ -36,7 +38,7 @@ $scope.afform = _.findWhere(afforms, {name: editor.name}); if (!$scope.afform) { $scope.afform = _.cloneDeep(newForm); - if (editor.name != '0') { + if (editor.name) { alert('Error: unknown form "' + editor.name + '"'); } } @@ -45,13 +47,13 @@ editor.layout = afGui.findRecursive($scope.afform.layout, {'#tag': 'af-form'})[0]; $scope.entities = afGui.findRecursive(editor.layout['#children'], {'#tag': 'af-entity'}, 'name'); - if (editor.name == '0') { + if (!editor.name) { editor.addEntity('Individual'); editor.layout['#children'].push(afGui.meta.elements.submit.element); } // Set changesSaved to true on initial load, false thereafter whenever changes are made to the model - $scope.changesSaved = editor.name == '0' ? false : 1; + $scope.changesSaved = !editor.name ? false : 1; $scope.$watch('afform', function () { $scope.changesSaved = $scope.changesSaved === 1; }, true); @@ -154,8 +156,7 @@ .then(function (data) { $scope.saving = false; $scope.afform.name = data[0].name; - // FIXME: This causes an unnecessary reload when saving a new form - $location.search('name', data[0].name); + $location.url('/edit/' + data[0].name); }); }; diff --git a/ext/afform/admin/ang/afGuiEditor/afGuiEditor.html b/ext/afform/admin/ang/afGuiEditor/afGuiEditor.html index acd32c00562e..72e4ea3b7b26 100644 --- a/ext/afform/admin/ang/afGuiEditor/afGuiEditor.html +++ b/ext/afform/admin/ang/afGuiEditor/afGuiEditor.html @@ -1,4 +1,6 @@ -
-
-
+
+
+
+
+
diff --git a/ext/afform/admin/templates/CRM/AfformAdmin/Page/Base.tpl b/ext/afform/admin/templates/CRM/AfformAdmin/Page/Base.tpl new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/ext/afform/admin/xml/Menu/afform_admin.xml b/ext/afform/admin/xml/Menu/afform_admin.xml new file mode 100644 index 000000000000..61400dcb2507 --- /dev/null +++ b/ext/afform/admin/xml/Menu/afform_admin.xml @@ -0,0 +1,8 @@ + + + + civicrm/admin/afform + CRM_AfformAdmin_Page_Base + administer CiviCRM + + diff --git a/ext/afform/core/Civi/Api4/Afform.php b/ext/afform/core/Civi/Api4/Afform.php index a69ee5c29207..ae2a328d0ea6 100644 --- a/ext/afform/core/Civi/Api4/Afform.php +++ b/ext/afform/core/Civi/Api4/Afform.php @@ -125,6 +125,9 @@ public static function getFields($checkPermissions = TRUE) { [ 'name' => 'name', ], + [ + 'name' => 'type', + ], [ 'name' => 'requires', ], diff --git a/ext/afform/core/ang/afblockNameHousehold.aff.json b/ext/afform/core/ang/afblockNameHousehold.aff.json index dc0847fc135d..c4eee679c690 100644 --- a/ext/afform/core/ang/afblockNameHousehold.aff.json +++ b/ext/afform/core/ang/afblockNameHousehold.aff.json @@ -1,4 +1,5 @@ { "title": "Household Name (default)", + "type": "block", "block": "Household" } diff --git a/ext/afform/core/ang/afblockNameIndividual.aff.json b/ext/afform/core/ang/afblockNameIndividual.aff.json index 3d05402fb088..51c4596ea683 100644 --- a/ext/afform/core/ang/afblockNameIndividual.aff.json +++ b/ext/afform/core/ang/afblockNameIndividual.aff.json @@ -1,4 +1,5 @@ { "title": "Individual Name (default)", + "type": "block", "block": "Individual" } diff --git a/ext/afform/core/ang/afblockNameOrganization.aff.json b/ext/afform/core/ang/afblockNameOrganization.aff.json index 34ab2fd53d6b..e3ac17c246f4 100644 --- a/ext/afform/core/ang/afblockNameOrganization.aff.json +++ b/ext/afform/core/ang/afblockNameOrganization.aff.json @@ -1,4 +1,5 @@ { "title": "Organization Name (default)", + "type": "block", "block": "Organization" } diff --git a/ext/afform/core/ang/afjoinAddressDefault.aff.json b/ext/afform/core/ang/afjoinAddressDefault.aff.json index 2a26888f4a1f..27775770b667 100644 --- a/ext/afform/core/ang/afjoinAddressDefault.aff.json +++ b/ext/afform/core/ang/afjoinAddressDefault.aff.json @@ -1,5 +1,6 @@ { "title": "Address Block (default)", + "type": "block", "block": "Contact", "join": "Address", "repeat": true diff --git a/ext/afform/core/ang/afjoinEmailDefault.aff.json b/ext/afform/core/ang/afjoinEmailDefault.aff.json index b09da6a075b7..7c50c579dc09 100644 --- a/ext/afform/core/ang/afjoinEmailDefault.aff.json +++ b/ext/afform/core/ang/afjoinEmailDefault.aff.json @@ -1,5 +1,6 @@ { "title": "Email (default)", + "type": "block", "block": "Contact", "join": "Email", "repeat": true diff --git a/ext/afform/core/ang/afjoinIMDefault.aff.json b/ext/afform/core/ang/afjoinIMDefault.aff.json index 2ef6b577cba5..3ec912975b61 100644 --- a/ext/afform/core/ang/afjoinIMDefault.aff.json +++ b/ext/afform/core/ang/afjoinIMDefault.aff.json @@ -1,5 +1,6 @@ { "title": "IM (default)", + "type": "block", "block": "Contact", "join": "IM", "repeat": true diff --git a/ext/afform/core/ang/afjoinPhoneDefault.aff.json b/ext/afform/core/ang/afjoinPhoneDefault.aff.json index c40af8dcb2ca..821d2888408f 100644 --- a/ext/afform/core/ang/afjoinPhoneDefault.aff.json +++ b/ext/afform/core/ang/afjoinPhoneDefault.aff.json @@ -1,5 +1,6 @@ { "title": "Phone (default)", + "type": "block", "block": "Contact", "join": "Phone", "repeat": true diff --git a/ext/afform/core/ang/afjoinWebsiteDefault.aff.json b/ext/afform/core/ang/afjoinWebsiteDefault.aff.json index 4819bc92d848..b39dd9cd7317 100644 --- a/ext/afform/core/ang/afjoinWebsiteDefault.aff.json +++ b/ext/afform/core/ang/afjoinWebsiteDefault.aff.json @@ -1,5 +1,6 @@ { "title": "Website (default)", + "type": "block", "block": "Contact", "join": "Website", "repeat": true From 1a0ba8a6f9a268f21a9babb533c1bb8abb169f70 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Wed, 13 Jan 2021 17:22:30 -0500 Subject: [PATCH 4/6] Afform - Use new APIv4 format for option values --- ext/afform/admin/CRM/AfformAdmin/Utils.php | 15 +-------------- .../ang/afGuiEditor/afGuiEditOptions.component.js | 6 +++--- .../admin/ang/afGuiEditor/afGuiEditOptions.html | 2 +- .../ang/afGuiEditor/afGuiFieldValue.directive.js | 2 +- .../afGuiEditor/elements/afGuiField.component.js | 4 ++-- ext/afform/core/afform.php | 6 +----- ext/afform/core/ang/af/Field.js | 13 +++++-------- ext/afform/core/ang/af/fields/CheckBox.html | 6 +++--- ext/afform/core/ang/af/fields/Radio.html | 4 ++-- ext/afform/mock/ang/testAfform.aff.html | 2 +- 10 files changed, 20 insertions(+), 40 deletions(-) diff --git a/ext/afform/admin/CRM/AfformAdmin/Utils.php b/ext/afform/admin/CRM/AfformAdmin/Utils.php index 5233a295d112..f9fc4d89753f 100644 --- a/ext/afform/admin/CRM/AfformAdmin/Utils.php +++ b/ext/afform/admin/CRM/AfformAdmin/Utils.php @@ -27,7 +27,7 @@ public static function getGuiSettings() { $getFieldParams = [ 'checkPermissions' => FALSE, 'includeCustom' => TRUE, - 'loadOptions' => TRUE, + 'loadOptions' => ['id', 'label'], 'action' => 'create', 'select' => ['name', 'label', 'input_type', 'input_attrs', 'required', 'options', 'help_pre', 'help_post', 'serialize', 'data_type'], 'where' => [['input_type', 'IS NOT NULL']], @@ -150,19 +150,6 @@ public static function getGuiSettings() { ], ]; - // Reformat options - // TODO: Teach the api to return options in this format - foreach ($data['entities'] as $entityName => $entity) { - foreach ($entity['fields'] as $name => $field) { - if (!empty($field['options'])) { - $data['entities'][$entityName]['fields'][$name]['options'] = CRM_Utils_Array::makeNonAssociative($field['options'], 'key', 'label'); - } - else { - unset($data['entities'][$entityName]['fields'][$name]['options']); - } - } - } - $data['styles'] = [ 'default' => E::ts('Default'), 'primary' => E::ts('Primary'), diff --git a/ext/afform/admin/ang/afGuiEditor/afGuiEditOptions.component.js b/ext/afform/admin/ang/afGuiEditor/afGuiEditOptions.component.js index 764b120a1b0c..ac1886ec36ed 100644 --- a/ext/afform/admin/ang/afGuiEditor/afGuiEditOptions.component.js +++ b/ext/afform/admin/ang/afGuiEditor/afGuiEditOptions.component.js @@ -11,12 +11,12 @@ this.$onInit = function() { $scope.options = JSON.parse(angular.toJson(ctrl.field.getOptions())); - var optionKeys = _.map($scope.options, 'key'); + var optionKeys = _.map($scope.options, 'id'); $scope.deletedOptions = _.filter(JSON.parse(angular.toJson(ctrl.field.getDefn().options || [])), function (item) { - return !_.contains(optionKeys, item.key); + return !_.contains(optionKeys, item.id); }); $scope.originalLabels = _.transform(ctrl.field.getDefn().options || [], function (originalLabels, item) { - originalLabels[item.key] = item.label; + originalLabels[item.id] = item.label; }, {}); }; diff --git a/ext/afform/admin/ang/afGuiEditor/afGuiEditOptions.html b/ext/afform/admin/ang/afGuiEditor/afGuiEditOptions.html index 87387636f2a9..cb9677ac12a1 100644 --- a/ext/afform/admin/ang/afGuiEditor/afGuiEditOptions.html +++ b/ext/afform/admin/ang/afGuiEditor/afGuiEditOptions.html @@ -13,7 +13,7 @@

{{:: ts('Customize options') }}

  • -
    {{ option.label }}
    +
    {{ option.label }}
    diff --git a/ext/afform/admin/ang/afGuiEditor/afGuiFieldValue.directive.js b/ext/afform/admin/ang/afGuiEditor/afGuiFieldValue.directive.js index bb3dc7565311..4fa0dd36df90 100644 --- a/ext/afform/admin/ang/afGuiEditor/afGuiFieldValue.directive.js +++ b/ext/afform/admin/ang/afGuiEditor/afGuiFieldValue.directive.js @@ -37,7 +37,7 @@ $el.crmEntityRef({entity: field.fk_entity, select:{multiple: multi}}); } else if (field.options) { var options = _.transform(field.options, function(options, val) { - options.push({id: val.key, text: val.label}); + options.push({id: val.id, text: val.label}); }, []); $el.select2({data: options, multiple: multi}); } else if (dataType === 'Boolean') { diff --git a/ext/afform/admin/ang/afGuiEditor/elements/afGuiField.component.js b/ext/afform/admin/ang/afGuiEditor/elements/afGuiField.component.js index 107d4684b94b..50781e4a989d 100644 --- a/ext/afform/admin/ang/afGuiEditor/elements/afGuiField.component.js +++ b/ext/afform/admin/ang/afGuiEditor/elements/afGuiField.component.js @@ -18,8 +18,8 @@ $scope.editingOptions = false; var yesNo = [ - {key: '1', label: ts('Yes')}, - {key: '0', label: ts('No')} + {id: '1', label: ts('Yes')}, + {id: '0', label: ts('No')} ]; this.$onInit = function() { diff --git a/ext/afform/core/afform.php b/ext/afform/core/afform.php index 49b3ba9f9977..0cecbe4ed11a 100644 --- a/ext/afform/core/afform.php +++ b/ext/afform/core/afform.php @@ -386,7 +386,7 @@ function _af_fill_field_metadata($entityType, DOMElement $afField) { 'action' => 'create', 'where' => [['name', '=', $afField->getAttribute('name')]], 'select' => ['label', 'input_type', 'input_attrs', 'options'], - 'loadOptions' => TRUE, + 'loadOptions' => ['id', 'label'], ]; if (in_array($entityType, CRM_Contact_BAO_ContactType::basicTypes(TRUE))) { $params['values'] = ['contact_type' => $entityType]; @@ -402,10 +402,6 @@ function _af_fill_field_metadata($entityType, DOMElement $afField) { // If it's not an object, don't mess with it. continue; } - // TODO: Teach the api to return options in this format - if (!empty($fieldInfo['options'])) { - $fieldInfo['options'] = CRM_Utils_Array::makeNonAssociative($fieldInfo['options'], 'key', 'label'); - } // Default placeholder for select inputs if ($fieldInfo['input_type'] === 'Select') { $fieldInfo['input_attrs'] = ($fieldInfo['input_attrs'] ?? []) + ['placeholder' => ts('Select')]; diff --git a/ext/afform/core/ang/af/Field.js b/ext/afform/core/ang/af/Field.js index 12c1726ad001..dcd925ff6197 100644 --- a/ext/afform/core/ang/af/Field.js +++ b/ext/afform/core/ang/af/Field.js @@ -14,9 +14,9 @@ var ts = $scope.ts = CRM.ts('afform'), closestController = $($el).closest('[af-fieldset],[af-join],[af-repeat-item]'), afForm = ctrls[0], - boolOptions = [{key: true, label: ts('Yes')}, {key: false, label: ts('No')}], + boolOptions = [{id: true, label: ts('Yes')}, {id: false, label: ts('No')}], // Only used for is_primary radio button - noOptions = [{key: true, label: ''}]; + noOptions = [{id: true, label: ''}]; $scope.dataProvider = closestController.is('[af-repeat-item]') ? ctrls[3] : ctrls[2] || ctrls[1]; $scope.fieldId = afForm.getFormMeta().name + '-' + $scope.fieldName + '-' + id++; @@ -29,7 +29,7 @@ $scope.select2Options = function() { return { results: _.transform($scope.getOptions(), function(result, opt) { - result.push({id: opt.key, text: opt.label}); + result.push({id: opt.id, text: opt.label}); }, []) }; }; @@ -58,16 +58,13 @@ var params = { where: [['name', '=', $scope.fieldName]], select: ['options'], - loadOptions: true, + loadOptions: ['id', 'label'], values: {} }; params.values[$scope.defn.input_attrs.controlField] = val; crmApi4($scope.dataProvider.getEntityType(), 'getFields', params, 0) .then(function(data) { - $scope.defn.options.length = 0; - _.transform(data.options, function(options, label, key) { - options.push({key: key, label: label}); - }, $scope.defn.options); + $scope.defn.options = data.options; }); } }); diff --git a/ext/afform/core/ang/af/fields/CheckBox.html b/ext/afform/core/ang/af/fields/CheckBox.html index 8788043cb98d..4bf900396f57 100644 --- a/ext/afform/core/ang/af/fields/CheckBox.html +++ b/ext/afform/core/ang/af/fields/CheckBox.html @@ -1,7 +1,7 @@
      -
    • - - +
    • + +
    diff --git a/ext/afform/core/ang/af/fields/Radio.html b/ext/afform/core/ang/af/fields/Radio.html index 7237a698c511..7bce6be407bd 100644 --- a/ext/afform/core/ang/af/fields/Radio.html +++ b/ext/afform/core/ang/af/fields/Radio.html @@ -1,4 +1,4 @@ -