I need to know when a model has been sorted using the Sortable trait, to update another model for synchronisation.
I dont fgind any event in the Sortable trait, is there any other way to accomplish that please?
i tried to liste for the afterSave event, but it does fire since the trait do a direct sql update in the database.
have you tried with some js ?
the modules\backend\assets\js\october.treelist.js gives the opportunity to use event `move.oc.treelist’ which is triggered when a node on the tree is moved.
/*
* TreeList Widget
*
* Supported options:
* - handle - class name to use as a handle
* - nested - set to false if sorting should be kept within each OL container, if using
* a handle it should be focused enough to exclude nested handles.
*
* Events:
* - move.oc.treelist - triggered when a node on the tree is moved.
*
* Dependences:
* - Sortable Plugin (october.sortable.js)
*/
I found a way using php and extending the trait method in the model, because we dont want to copy/paste the trait method executing the reordeering.
in the model.php
use \October\Rain\Database\Traits\Sortable {
setSortableOrder as public traitSetSortableOrder;
}
...
/**
* extends sortable method
*/
public function setSortableOrder($itemIds, $referencePool = null)
{
// execute the trait method
$this->traitSetSortableOrder($itemIds, $referencePool = null);
// then do our stuff here
}