Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Afform - Fix saving and editing entity blocks #22963

Merged
merged 1 commit into from
Mar 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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