Skip to content

Commit

Permalink
Afform - Fix saving and editing entity blocks
Browse files Browse the repository at this point in the history
Fixes dev/core#3120
Regression caused by civicrm#21218
Also fixes undefined variable errors when editing a block.
  • Loading branch information
colemanw committed Mar 17, 2022
1 parent 64e1d54 commit 1c2bf8e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
11 changes: 7 additions & 4 deletions ext/afform/admin/ang/afGuiEditor/afGuiEditor.component.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@
};

this.getEntityDefn = function(entity) {
if (entity.type === 'Contact' && entity.data.contact_type) {
if (entity.type === 'Contact' && entity.data && entity.data.contact_type) {
return editor.meta.entities[entity.data.contact_type];
}
return editor.meta.entities[entity.type];
Expand All @@ -203,12 +203,15 @@
this.scrollToEntity = function(entityName) {
var $canvas = $('#afGuiEditor-canvas-body'),
$entity = $('.af-gui-container-type-fieldset[data-entity="' + entityName + '"]').first(),
scrollValue, maxScroll;
if ($entity.length) {
// Scrolltop value needed to place entity's fieldset at top of canvas
scrollValue = $canvas.scrollTop() + ($entity.offset().top - $canvas.offset().top),
scrollValue = $canvas.scrollTop() + ($entity.offset().top - $canvas.offset().top);
// Maximum possible scrollTop (height minus contents height, adjusting for padding)
maxScroll = $('#afGuiEditor-canvas-body > *').height() - $canvas.height() + 20;
// Exceeding the maximum scrollTop breaks the animation so keep it under the limit
$canvas.animate({scrollTop: scrollValue > maxScroll ? maxScroll : scrollValue}, 500);
// Exceeding the maximum scrollTop breaks the animation so keep it under the limit
$canvas.animate({scrollTop: scrollValue > maxScroll ? maxScroll : scrollValue}, 500);
}
};

this.getAfform = function() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,15 +242,14 @@
layout: ctrl.node['#children']
};
if (ctrl.join) {
model.join = ctrl.join;
model.join_entity = ctrl.join;
}
if ($scope.block && $scope.block.original) {
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.getFieldEntityType();
model.entity_type = ctrl.getFieldEntityType();
}
dialogService.open('saveBlockDialog', '~/afGuiEditor/saveBlock.html', model, options)
.then(function(block) {
Expand Down

0 comments on commit 1c2bf8e

Please sign in to comment.