Consider the reorder column if present when adding and deleting new rows

This commit is contained in:
Kevin MacMartin 2018-05-01 20:14:00 -04:00
parent 734268c1dd
commit 3a3ddd09d3

View file

@ -167,6 +167,10 @@ class DashboardController extends Controller {
if ($model_class != null) {
if ($request['id'] == 'new') {
$item = new $model_class;
if ($model_class::$dashboard_reorder) {
$item->{$model_class::$dashboard_sort_column} = $model_class::count();
}
} else {
$item = $model_class::find($request['id']);
@ -297,6 +301,14 @@ class DashboardController extends Controller {
}
}
// update the order of the remaining rows if $dashboard_reorder is true
if ($model_class::$dashboard_reorder) {
foreach ($model_class::getDashboardData() as $index => $item) {
$item->{$model_class::$dashboard_sort_column} = $index;
$item->save();
}
}
// Return a success
return 'success';
} else {