Skip to content

Commit

Permalink
Merge pull request #98 from DissNik/patch_checkbox_mass_actions
Browse files Browse the repository at this point in the history
  • Loading branch information
lee-to committed Feb 12, 2023
2 parents a7fd4e0 + fa9a584 commit a834cff
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 3 deletions.
8 changes: 7 additions & 1 deletion resources/views/base/index/foot.blade.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@if(!$resource->isPreviewMode())
@if($resource->isMassAction())
<tr>
<td class="px-6 py-3 text-left text-xs leading-4 font-medium uppercase tracking-wider"
colspan="{{ count($resource->indexFields())+2 }}"
Expand Down Expand Up @@ -74,6 +74,12 @@ function actionBarHandler() {
}
}
if(document.querySelector('.actionBarCheckboxRow:not(:checked)') != null) {
document.querySelector('.actionBarCheckboxMain').checked = false;
} else {
document.querySelector('.actionBarCheckboxMain').checked = true;
}
if(document.querySelector('.actionBarCheckboxRow:checked') != null) {
this.actionBarOpen = true;
} else {
Expand Down
2 changes: 1 addition & 1 deletion resources/views/base/index/head.blade.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<tr>
@if(!$resource->isPreviewMode())
@if($resource->isMassAction())
<th class="px-6 py-3 text-left text-xs leading-4 font-medium uppercase tracking-wider">
<input type="checkbox" @change="actionBar('main')" class="actionBarCheckboxMain" value="1" />
</th>
Expand Down
2 changes: 1 addition & 1 deletion resources/views/base/index/items.blade.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@foreach($items as $item)
<tr style="{{ $resource->trStyles($item, $loop->index) }}">
@if(!$resource->isPreviewMode())
@if($resource->isMassAction())
<td class="px-6 py-4 whitespace-nowrap" style="{{ $resource->tdStyles($item, $loop->index, 0) }}">
<input class="actionBarCheckboxRow" @change='actionBar("item")' name="items[{{ $item->getKey() }}]"
type="checkbox" value="{{ $item->getKey() }}"/>
Expand Down
9 changes: 9 additions & 0 deletions src/Resources/Resource.php
Original file line number Diff line number Diff line change
Expand Up @@ -898,6 +898,15 @@ public function renderFormComponent(HtmlViewable $formComponent, Model $item): F
]);
}

public function isMassAction(): bool
{
return ! $this->isPreviewMode() && (
count($this->bulkActions()) || (
$this->can('massDelete') && in_array('delete', $this->getActiveActions())
)
);
}

protected function _render(HtmlViewable $field, Model $item, int $level = 0): Factory|View|Application
{
if ($field->hasRelationship() && ($field->belongToOne() || $field->manyToMany())) {
Expand Down

0 comments on commit a834cff

Please sign in to comment.