From 27350e133a0df8ac2d10d569d52a090183594d49 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Thu, 17 Mar 2022 14:16:44 -0400 Subject: [PATCH] Afform - Fix saving and editing entity blocks Fixes dev/core#3120 Regression caused by #21218 Also fixes undefined variable errors when editing a block. --- .../admin/ang/afGuiEditor/afGuiEditor.component.js | 11 +++++++---- .../afGuiEditor/elements/afGuiContainer.component.js | 5 ++--- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/ext/afform/admin/ang/afGuiEditor/afGuiEditor.component.js b/ext/afform/admin/ang/afGuiEditor/afGuiEditor.component.js index 6e62c1fcccb3..5aa0a4494403 100644 --- a/ext/afform/admin/ang/afGuiEditor/afGuiEditor.component.js +++ b/ext/afform/admin/ang/afGuiEditor/afGuiEditor.component.js @@ -192,7 +192,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]; @@ -202,12 +202,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() { diff --git a/ext/afform/admin/ang/afGuiEditor/elements/afGuiContainer.component.js b/ext/afform/admin/ang/afGuiEditor/elements/afGuiContainer.component.js index af68e05108e9..0d0d8cac973a 100644 --- a/ext/afform/admin/ang/afGuiEditor/elements/afGuiContainer.component.js +++ b/ext/afform/admin/ang/afGuiEditor/elements/afGuiContainer.component.js @@ -268,15 +268,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) {