From d229fb287ec50e0aef94eb31cd33c3f49794d2cc Mon Sep 17 00:00:00 2001 From: Sam Georges Date: Wed, 28 May 2014 22:07:00 +1000 Subject: [PATCH] Fixes #216 - hasMany related models can now be deleted --- modules/backend/behaviors/RelationController.php | 13 ++++++++++++- .../relationcontroller/partials/_button_delete.htm | 1 + 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/modules/backend/behaviors/RelationController.php b/modules/backend/behaviors/RelationController.php index 231e44354..2c659d919 100644 --- a/modules/backend/behaviors/RelationController.php +++ b/modules/backend/behaviors/RelationController.php @@ -422,7 +422,18 @@ class RelationController extends ControllerBehavior public function onRelationManageDelete() { - // @todo + $this->beforeAjax(); + + if (($checkedIds = post('checked')) && is_array($checkedIds)) { + foreach ($checkedIds as $relationId) { + if (!$obj = $this->relationObject->find($relationId)) + continue; + + $obj->delete(); + } + } + + return ['#'.$this->relationGetId('view') => $this->relationRenderView()]; } public function onRelationManageCreate() diff --git a/modules/backend/behaviors/relationcontroller/partials/_button_delete.htm b/modules/backend/behaviors/relationcontroller/partials/_button_delete.htm index 81645b1f0..274a686b0 100644 --- a/modules/backend/behaviors/relationcontroller/partials/_button_delete.htm +++ b/modules/backend/behaviors/relationcontroller/partials/_button_delete.htm @@ -5,6 +5,7 @@ })" disabled="disabled" data-request="onRelationManageDelete" + data-request-confirm="Are you sure?" data-trigger-type="enable" data-trigger="#relationGetId('view') ?> .control-list input[type=checkbox]" data-trigger-condition="checked"