Skip to content

Commit

Permalink
#34: Fix delete user
Browse files Browse the repository at this point in the history
  • Loading branch information
agungsugiarto committed Mar 26, 2020
1 parent 59f999f commit e7afbcb
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/Controllers/Users/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function index()

if ($this->request->isAJAX()) {
return $this->respond([
'data' => $this->users->get()->getResultObject(),
'data' => $this->users->asObject()->findAll(),
]);
}

Expand Down Expand Up @@ -256,6 +256,11 @@ public function update($id)
*/
public function delete($id)
{
if (!$found = $this->users->where('id', $id)->delete()) {
return $this->fail('fail deleted');
}

return $this->respondDeleted($found);
}

private function listAllUser()
Expand Down
31 changes: 31 additions & 0 deletions src/Views/User/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,37 @@
]
});

$(document).on('click', '.btn-delete', function(e) {
Swal.fire({
title: '<?= lang('global.title') ?>',
text: "<?= lang('global.text') ?>",
icon: 'warning',
showCancelButton: true,
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
confirmButtonText: '<?= lang('global.confirm_delete') ?>'
})
.then((result) => {
if (result.value) {
$.ajax({
url: `<?= route_to('admin/user/manage') ?>/${$(this).attr('data-id')}`,
method: 'DELETE',
}).done((data, textStatus) => {
Toast.fire({
icon: 'success',
title: textStatus,
});
tableUser.ajax.reload();
}).fail((error) => {
Toast.fire({
icon: 'error',
title: error.responseJSON.messages.error,
});
})
}
})
});

tableUser.on('order.dt search.dt', () => {
tableUser.column(0, {search:'applied', order:'applied'}).nodes().each( function (cell, i) {
cell.innerHTML = i+1;
Expand Down

0 comments on commit e7afbcb

Please sign in to comment.