How to avoid moving child object when parent is moved? - typo3

Is it possible to avoid moving inline child objects of parent when parent record is moved?
My use case:
There is TYPO3 record (parent) of type X which has inline relation to record of type Y (child).
Following configuration is loaded:
TCAdefaults.Y {
pid = 129
}
I am adding new X record on page 1 and inline relation of type Y. X
is created with pid = 1 and Y is created with pid = 129. So far
good.
Now I am moving record X to page 2. Both X and Y have pid 2 now. How can
I avoid that? I don't want inline record Y to change pid when X is moved in backend (example cut and paste functionality).

There is a TCA configuration for this purpose. Add this to your TCA inline field configuration:
'behavior' => [
'disableMovingChildrenWithParent' => true
],
The docs: https://docs.typo3.org/typo3cms/TCAReference/ColumnsConfig/Type/Inline.html#disablemovingchildrenwithparent

Related

Count total rows excluding children rows

I have a requirement for display only row count of parent rows in tree data mode. I am using getDisplayedRowCount api it gives me all the row count i.e parent + child (if expanded). Is there any way to do it?
For example
If we have rows like below where 2 row has child and 1 row has no child then just count as 3 . dont count children. Just count parent row and row without children
Result count : 3 of 3
Parent row 1
--- Child row
Parent row 2
--- child row
Row without child
For example, if we have tree structure like in the example . How to only count A, C and E? and show count as 3 on top of grid
https://www.ag-grid.com/example-runner/grid-react.php?section=javascript-grid-tree-data&example=filler-nodes&generated=1&clientside=1&rowgrouping=1&enterprise=1&grid=%7B%22noStyle%22%3A0%2C%22height%22%3A%22100%25%22%2C%22width%22%3A%22100%25%22%2C%22enterprise%22%3Atrue%7D
https://www.ag-grid.com/javascript-grid-tree-data/
One possible solution would be to rely on the fact that the parent node of the nodes A, C & E (in your given example) is the root node - note that this is not documented in the official documentation, however it is the simplest solution I can think of.
If a node has the root node as the parent, then we can call it a parent node.
You can verify this by adding this code and look at the nodes which are printed:
gridOptions.api.forEachNode((node) => {
if (node.parent.id == 'ROOT_NODE_ID') {
console.log(node.key);
}
});
I've put together an example showing this at the click of a button

pyqt how to swap text in

I have a QTable Widget of one column populated with several rows, and I would like to be able to drag and drop so i can re order them.
I am able to do setDragDropMode with Internal Move, but when i move cell (0,1) to (0,3)
the (0,3) get the text correctly, but cell (0,1) is now empty. I would like to swap the text of the cell when I drop it.
class myList(QtGui.QTableWidget):
def __init__(self,parent):
super(myList,self).__init__(parent)
# self.setAcceptDrops(True)
self.setDragDropMode(QtGui.QAbstractItemView.InternalMove)
You can override the dropEvent callback to alter the default action. Here is a first version that writes the value in both cells.
class TableSwitcher(QtGui.QTableWidget):
def dropEvent(self, dropEvent):
item_src = self.selectedItems()[0]
item_dest = self.itemAt(dropEvent.pos())
src_value = item_src.text()
item_src.setText(item_dest.text())
item_dest.setText(src_value)
You can also let Qt performs the default behavior (move the dragged QTableWidgetItem, and delete the one you drop on) through super call , here you face the challenge that the default action will alter the state of widgets.
class TableSwitcher(QtGui.QTableWidget):
def dropEvent(self, dropEvent):
item_src = self.selectedItems()[0]
item_dest = self.itemAt(dropEvent.pos())
src_row = item_src.row()
src_col = item_src.column()
dest_value = item_dest.text()
super(TableSwitcher,self).dropEvent(dropEvent)
self.setItem(src_row,src_col, QtGui.QTableWidgetItem(dest_value))
Here is an example code using this class.
app = QtGui.QApplication(sys.argv)
table = TableSwitcher()
n = 5
table.setRowCount(n)
table.setColumnCount(1)
table.setDragDropMode(QtGui.QAbstractItemView.InternalMove)
for i in range(n):
table.setItem(i,0,QtGui.QTableWidgetItem(str(i)))
table.show()
app.exec_()

jquery ui sortable temporary element swapping during drag

I need to implement temporary drag replacement in a size-limited jquery ui sortable list.
I have 2 sortable lists:
A "slot" with only 1 spot to hold a single element
A "bucket" that holds several elements from which the user can pick any to fill the "slot"
The user has to drag an element from the bucket into the slot. While the user is holding the element with the mouse over the slot, if the slot is already occupied, the current slotted element should be moved into the bucket to visually make room for the dragged element. Then the user has 2 options:
If the user drops the new element: insert the new element into the slot
If the user cancels the drop: move the previously slotted element back into the slot (as it was originally)
This behaviour should repeat until the user has either cancelled the drag or dropped the element into the slot or the bucket.
To visually limit the slot to a single element, I have limited it to the exact height of a single element and setted its overflow to hidden.
Unfortunately, I have not been able to produce the effect while keeping a single element in the slot at all time.
EDIT 1: Here is an example of what I have so far
$(".slot").bind("sortchange", function (event, ui) {
var slot = $(event.target);
var bucket = $(".bucket");
// Move any element already in the slot (other than the currently
// dragged element) into the bucket
var slotElements = slot.children(".item").not(ui.item);
if (slotElements.length > 0) {
for (var idx = 0; idx < slotElements.length; idx += 1) {
var element = $(slotElements[idx]);
moveAnimate(element, bucket);
}
}
});

Setting up some properties for a combobox (scroll, edit, jump)

There are 3 properties that I want to set for some VBA form comboboxes and I don't know if it's possible.
I don't want to let the combobox editable. Right now if the user types something in it that it submits the form it will send that value... I want to let him choose only from the values I added in the Combobox.
I want to make the list of items in the combobox scroll-able. Right now I'm able to scroll through the list if I use the scroll-bar but I don't know why I can't scroll with the mouse scroll.
And I want to jump to some item if I start typing. Let's say I have the months of the year in one combobox... if I start to type mar I want it to jump to march. I know that for the html forms this properties is by default but I don't know about VBA forms...
Thanks a lot
Of the behaviours you want, some are possible with settings on the Combo, others you will need to code
List of Months: Put a list of entries on a (hidden) sheet and name the range. Set .RowSource to that range
Match as you type: Set properties .MatchEntry = fmMatchEntryComplete and .MatchRequired = True
Reject non list entries: A Combo with these settings will allow you to type an invalid entry, but will reject it with an error message popup when you commit. If you want to silently reject invalid data as you type, you will need to code it.
If you want the selected value returned to a sheet, set .ControlSource to a cell address (preferable a named range)
By "...scroll with the mouse scroll..." I assume you mean the mouse wheel. Unfortunatley Forms don't support mouse wheel scroll. You will have to code it yourself. There is a Microsoft patch for this at here (not tried it myself yet)
Sample code to silently reject invalid entries
Private Sub cmbMonth_Change()
Static idx As Long
Dim Match As Boolean
Dim i As Long
If cmbMonth.Value = "" Then Exit Sub
If idx = 0 Then idx = 1
i = idx
Match = False
For i = 0 To cmbMonth.ListCount
If cmbMonth.List((i + idx - 1) Mod cmbMonth.ListCount) Like cmbMonth.Value & "*" Then
cmbMonth.ListIndex = (i + idx - 1) Mod cmbMonth.ListCount
Match = True
Exit For
End If
Next
If Not Match Then
cmbMonth.Value = Left(cmbMonth.Value, Len(cmbMonth.Value) - 1)
End If
End Sub
Set the propertie MatchEntry of combobox to 1 (fmMatchEntryComplete) and MatchRequired to true for example
combobox1.MatchEntry=1
combobox1.MatchRequired=True
[]'s

how to get the drop target from gwt-dnd

I have a vertical panel containing two rows, say row 1 and row 2, each
row contains couple of widgets, now i need to allow the user to drag
and drop widgets between row 1 and row 2, here is what i did
_handler = new DragHandler() { .... };
_widgetDragController = new PickupDragController(boundaryPanel, false);
_widgetDragController.setBehaviorMultipleSelection(false);
_widgetDragController.addDragHandler(_handler);
then for each row, create panel to hold widgets and assign a drop controller:
VerticalPanelWithSpacer vPanel = new VerticalPanelWithSpacer();
// initialize a widget drop controller for the current column VerticalPanelDropController
widgetDropController = new VerticalPanelDropController(vPanel);
_widgetDragController.registerDropController(widgetDropController);
how can i find the drop target (namely which row) when i dnd widgets between row 1 and row 2? is there any way the _widgetDragController can tell which drop controller got involved and then i can further call getDropTarget() from the drop controller?
You could implement the functionality in VerticalPanelDropController.onDrop(DragContext), which gets called when the users drop on that drop controller. The drop controller knows the VerticalPanelWithSpacer it belongs to, and the dragContext contains information such as the x, y coordinates. You could use this information (the y coordinate & the coordinates of the widget) to calculate the row which should be added (although you might need to take scrolling etc into account, which makes it a bit more tricky). Hope that helps :-)