Skip to content

Commit

Permalink
Property Panel doesn't move target when changing between Elements (#2401
Browse files Browse the repository at this point in the history
  • Loading branch information
maurofmferrao committed Mar 6, 2024
1 parent 8dff00d commit da16dda
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 28 deletions.
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

0 comments on commit da16dda

Please sign in to comment.