reportbro-designer
Version:
Designer to create pdf and excel report layouts. The reports can be generated with reportbro-lib (a Python package) on the server.
70 lines (63 loc) • 2.44 kB
JavaScript
import Command from './Command';
import DocElement from '../elements/DocElement';
/**
* Command to move a menu panel item. In case the item is moved to a different container
* (e.g. from content to header band) the corresponding doc element is moved to the new container as well.
* @class
*/
export default class MovePanelItemCmd extends Command {
constructor(panelItem, moveToParentPanel, moveToPosition, rb) {
super();
this.objId = panelItem.getId();
this.moveToParentId = moveToParentPanel.getId();
this.moveToPosition = moveToPosition;
this.oldParentId = panelItem.getParent().getId();
this.oldPosition = panelItem.getSiblingPosition();
this.oldContainerId = null;
this.moveToContainerId = null;
if (panelItem.getData() instanceof DocElement) {
let docElement = panelItem.getData();
this.oldContainerId = docElement.getValue('containerId');
let moveToContainer = rb.getMainPanel().getContainerByItem(moveToParentPanel);
if (moveToContainer !== null) {
this.moveToContainerId = moveToContainer.getId();
}
}
this.rb = rb;
}
getName() {
return 'Move panel item';
}
do() {
let pos = this.moveToPosition;
if (this.moveToParentId === this.oldParentId && this.oldPosition < pos) {
pos--;
}
this.moveTo(
this.moveToParentId, pos,
(this.moveToContainerId !== this.oldContainerId) ? this.moveToContainerId : null);
}
undo() {
this.moveTo(
this.oldParentId, this.oldPosition,
(this.moveToContainerId !== this.oldContainerId) ? this.oldContainerId : null);
}
moveTo(toParentId, toPosition, toContainerId) {
let obj = this.rb.getDataObject(this.objId);
let parent = this.rb.getDataObject(toParentId);
if (obj !== null && parent !== null) {
obj.getPanelItem().moveToPosition(parent.getPanelItem(), toPosition);
obj.getPanelItem().openParentItems();
this.rb.notifyEvent(obj, Command.operation.move);
}
}
/**
* Returns class name.
* This can be useful for introspection when the class names are mangled
* due to the webpack uglification process.
* @returns {string}
*/
getClassName() {
return 'MovePanelItemCmd';
}
}