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

Property Panel doesn't move target when changing between Elements #2401

Merged
merged 1 commit into from
Mar 6, 2024
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
32 changes: 23 additions & 9 deletions ui/src/editor-core/properties-panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ const PropertiesPanel = function(parent, container) {
this.actionForm = {};

this.toSave = false;
this.toSaveElementCallback = null;
};

/**
Expand Down Expand Up @@ -388,6 +389,9 @@ PropertiesPanel.prototype.saveElement = function(
}
}

// Mark to save as false
this.toSaveElementCallback = null;

// Save elements to the widget
return parentWidget.saveElements().then((_res) => {
// Update element position
Expand Down Expand Up @@ -1031,7 +1035,7 @@ PropertiesPanel.prototype.render = function(
);

// Save element
const saveElement = function(target) {
const saveElementProperty = function(target) {
const $target = $(target);
let containerChanged = false;
// If the property is common, save it to the element
Expand Down Expand Up @@ -1073,18 +1077,26 @@ PropertiesPanel.prototype.render = function(
}

// Save the element
self.saveElement(
targetAux,
self.DOMObject.find(
'[name].element-property:not(.element-common-property)',
),
containerChanged,
// only if we have form properties
const formProperties = self.DOMObject.find(
'[name].element-property:not(.element-common-property)',
);
if (formProperties.length > 0) {
self.saveElement(
targetAux,
self.DOMObject.find(
'[name].element-property:not(.element-common-property)',
),
containerChanged,
);
}
};

const saveDebounced = _.wrap(
_.memoize(
() => _.debounce(saveElement.bind(self), 250), _.property('id'),
() => _.debounce(
saveElementProperty.bind(self), 250,
), _.property('id'),
),
(getMemoizedFunc, obj) => getMemoizedFunc(obj)(obj),
);
Expand All @@ -1111,7 +1123,9 @@ PropertiesPanel.prototype.render = function(
'.xibo-form-input.element-name-input',
).length === 0
) {
self.toSave = true;
self.toSaveElementCallback = function() {
saveElementProperty(_ev.currentTarget);
};
}
},
});
Expand Down
61 changes: 42 additions & 19 deletions ui/src/layout-editor/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -527,26 +527,49 @@ lD.selectObject =
(
oldSelectedId != newSelectedId ||
oldSelectedType != newSelectedType
) && this.propertiesPanel.toSave
) && (
this.propertiesPanel.toSave ||
this.propertiesPanel.toSaveElementCallback != null
)
) {
// Set flag back to false
this.propertiesPanel.toSave = false;

// Save previous element
this.propertiesPanel.save({
target: this.selectedObject, // Save previous object
callbackNoWait: function() {
// Select object again, with the same params
lD.selectObject({
target: target,
forceSelect: forceSelect,
clickPosition: clickPosition,
refreshEditor: refreshEditor,
reloadViewer: reloadViewer,
reloadPropertiesPanel: reloadPropertiesPanel,
});
},
});
// Select previous object
const selectPrevious = function() {
// Select object again, with the same params
lD.selectObject({
target: target,
forceSelect: forceSelect,
clickPosition: clickPosition,
refreshEditor: refreshEditor,
reloadViewer: reloadViewer,
reloadPropertiesPanel: reloadPropertiesPanel,
});
};

// Save elements
if (this.propertiesPanel.toSaveElementCallback != null) {
// Set flag back to false
this.propertiesPanel.toSaveElement = false;

// Run callback to save element property
this.propertiesPanel.toSaveElementCallback();

// Set callback back to null
this.propertiesPanel.toSaveElementCallback = null;

// Select object again
selectPrevious();
} else if (this.propertiesPanel.toSave) {
// Save normal form fields

// Set flag back to false
this.propertiesPanel.toSave = false;

// Save previous object
this.propertiesPanel.save({
target: this.selectedObject, // Save previous object
callbackNoWait: selectPrevious,
});
}

// Prevent select to continue
return;
Expand Down