diff --git a/resources/assets/open-admin/js/open-admin-resource.js b/resources/assets/open-admin/js/open-admin-resource.js index 615cd285..391e75bd 100644 --- a/resources/assets/open-admin/js/open-admin-resource.js +++ b/resources/assets/open-admin/js/open-admin-resource.js @@ -33,7 +33,7 @@ let url = resource_url; let data = {_method:'delete'}; admin.ajax.post(url,data,function(data){ - resolve(data); + resolve(data.data); if (navigate_url){ admin.ajax.navigate(navigate_url); }else{ diff --git a/resources/lang/en/admin.php b/resources/lang/en/admin.php index 4bda990b..1492139b 100644 --- a/resources/lang/en/admin.php +++ b/resources/lang/en/admin.php @@ -96,18 +96,25 @@ 'time' => 'Time', 'size' => 'Size', 'listbox' => [ - 'title_available' => 'Available', - 'title_selected' => 'Selected', - 'text_total' => 'Showing all {0}', - 'text_empty' => 'Empty list', - 'filtered' => '{0} / {1}', - 'filter_clear' => 'Show all', - 'filter_placeholder' => 'Filter', + 'title_available' => 'Available', + 'title_selected' => 'Selected', + 'text_total' => 'Showing all {0}', + 'text_empty' => 'Empty list', + 'filtered' => '{0} / {1}', + 'filter_clear' => 'Show all', + 'filter_placeholder' => 'Filter', ], - 'grid_items_selected' => '{n} items selected', + 'grid_items_selected' => '{n} items selected', - 'menu_titles' => [], - 'prev' => 'Prev', - 'next' => 'Next', - 'quick_create' => 'Quick create', + 'menu_titles' => [], + 'prev' => 'Prev', + 'next' => 'Next', + 'quick_create' => 'Quick create', + 'restore_confirm' => 'Are you sure, you want to restore?', + 'yes' => 'Yes', + 'restore_success' => 'Restored Successfully', + 'restore' => 'Restore', + 'batch_restore' => 'Batch Restore', + 'batch_restore_confirm' => 'Are you sure, you want to restore all selected?', + 'recyclebin' => 'Recycle Bin', ]; diff --git a/src/Actions/RowAction.php b/src/Actions/RowAction.php index d51d40f3..d32fd940 100644 --- a/src/Actions/RowAction.php +++ b/src/Actions/RowAction.php @@ -134,16 +134,19 @@ public function display($value) */ public function render() { + $this->attribute('title', $this->name()); + $attributes = $this->formatAttributes(); + $linkClass = ($this->parent->getActionClass() != "OpenAdmin\Admin\Grid\Displayers\Actions\Actions") ? 'dropdown-item' : ''; $icon = $this->getIcon(); if ($href = $this->href()) { - return "{$icon}{$this->name()}"; + return "{$icon}{$this->name()}"; } $this->addScript(); - $attributes = $this->formatAttributes(); + $attributes = $this->formatAttributes(); // fetch again to get script attributes return sprintf( "{$icon}%s", diff --git a/src/Actions/SweatAlert2.php b/src/Actions/SweatAlert2.php index 09cf4a7f..34e973fd 100644 --- a/src/Actions/SweatAlert2.php +++ b/src/Actions/SweatAlert2.php @@ -35,7 +35,7 @@ public function getOptions() { return [ 'swal' => [ - 'type' => $this->type, + 'icon' => $this->type, 'title' => $this->title, ], ]; diff --git a/src/Controllers/HasRecycleBin.php b/src/Controllers/HasRecycleBin.php new file mode 100644 index 00000000..d8251759 --- /dev/null +++ b/src/Controllers/HasRecycleBin.php @@ -0,0 +1,38 @@ +registerHook('alterGrid', function ($controller, $grid) { + $grid->filter(function ($filter) { + $filter->scope('trashed', __('admin.recyclebin'))->onlyTrashed(); + }); + + $grid->actions(function ($actions) { + if (request('_scope_') == 'trashed') { + $actions->add(new Restore()); + $actions->disableView(); + $actions->disableEdit(); + } + + return $actions; + }); + + $grid->batchActions(function ($batch) { + if (request('_scope_') == 'trashed') { + $batch->add(new BatchRestore()); + } + }); + + return $grid; + }); + } +} diff --git a/src/Grid/Actions/Delete.php b/src/Grid/Actions/Delete.php index 7632b413..1a3cb6f4 100644 --- a/src/Grid/Actions/Delete.php +++ b/src/Grid/Actions/Delete.php @@ -21,10 +21,8 @@ public function name() public function addScript() { - $this->attributes = [ - 'onclick' => 'admin.resource.delete(event,this)', - 'data-url'=> "{$this->getResource()}/{$this->getKey()}", - ]; + $this->attribute('onclick', 'admin.resource.delete(event,this)'); + $this->attribute('data-url', "{$this->getResource()}/{$this->getKey()}"); } /* diff --git a/src/Grid/Actions/Restore.php b/src/Grid/Actions/Restore.php new file mode 100644 index 00000000..810c29f5 --- /dev/null +++ b/src/Grid/Actions/Restore.php @@ -0,0 +1,31 @@ +name = __('admin.restore'); + } + + public function handle(Model $model): Response + { + // $model ... + $model->restore(); + + return $this->response()->success(__('admin.restore_success'))->refresh(); + } + + public function dialog() + { + $this->confirm(__('admin.restore_confirm'), '', ['icon'=>'question', 'confirmButtonText'=>__('admin.yes')]); + } +} diff --git a/src/Grid/Concerns/HasActions.php b/src/Grid/Concerns/HasActions.php index ab88e2bc..7f94301f 100644 --- a/src/Grid/Concerns/HasActions.php +++ b/src/Grid/Concerns/HasActions.php @@ -12,7 +12,7 @@ trait HasActions * * @var Closure */ - protected $actionsCallback; + protected $actionsCallback = []; /** * Actions column display class. @@ -31,7 +31,7 @@ trait HasActions public function actions($actions) { if ($actions instanceof Closure) { - $this->actionsCallback = $actions; + $this->actionsCallback[] = $actions; } return $this; @@ -52,7 +52,7 @@ public function getActionClass() return $class; } - return Grid\Displayers\Acions\Actions::class; + return Grid\Displayers\Actions\Actions::class; } /** diff --git a/src/Grid/Displayers/Actions/Actions.php b/src/Grid/Displayers/Actions/Actions.php index 8d86c73f..0d92fed7 100644 --- a/src/Grid/Displayers/Actions/Actions.php +++ b/src/Grid/Displayers/Actions/Actions.php @@ -242,6 +242,14 @@ public function display($callback = null) $callback->call($this, $this); } + if(is_array($callback)) { + foreach ($callback as $instance) { + if($instance instanceof \Closure) { + $instance->call($this, $this); + } + } + } + if ($this->disableAll) { return ''; } diff --git a/src/Grid/Tools/BatchRestore.php b/src/Grid/Tools/BatchRestore.php new file mode 100644 index 00000000..d304d569 --- /dev/null +++ b/src/Grid/Tools/BatchRestore.php @@ -0,0 +1,31 @@ +name = __('admin.batch_restore'); + } + + public function handle(Collection $collection) + { + foreach ($collection as $model) { + $model->restore(); + } + + return $this->response()->success(__('admin.restore_success'))->refresh(); + } + + public function dialog() + { + $this->confirm(__('admin.batch_restore_confirm'), '', ['icon'=>'question', 'confirmButtonText'=>__('admin.yes')]); + } +}