Skip to content

Commit 93e6271

Browse files
committed
optimize
1 parent 65fa37d commit 93e6271

File tree

7 files changed

+191
-284
lines changed

7 files changed

+191
-284
lines changed
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
<div class="dropdown pull-right column-selector">
2+
<button type="button" class="btn btn-sm btn-instagram dropdown-toggle" data-toggle="dropdown">
3+
<i class="fa fa-table"></i>
4+
&nbsp;
5+
<span class="caret"></span>
6+
</button>
7+
<ul class="dropdown-menu" role="menu">
8+
<li>
9+
<ul>
10+
@foreach($columns as $key => $label)
11+
@php
12+
if (empty($visible)) {
13+
$checked = 'checked';
14+
} else {
15+
$checked = in_array($key, $visible) ? 'checked' : '';
16+
}
17+
@endphp
18+
19+
<li class="checkbox icheck">
20+
<label>
21+
<input type="checkbox" class="column-select-item" value="{{ $key }}" {{ $checked }}/>&nbsp;&nbsp;&nbsp;{{ $label }}
22+
</label>
23+
</li>
24+
@endforeach
25+
</ul>
26+
</li>
27+
<li class="divider"></li>
28+
<li class="text-right">
29+
<button class="btn btn-sm btn-default column-select-all">{{ __('admin.all') }}</button>&nbsp;&nbsp;
30+
<button class="btn btn-sm btn-primary column-select-submit">{{ __('admin.submit') }}</button>
31+
</li>
32+
</ul>
33+
</div>
34+
35+
<style>
36+
.column-selector {
37+
margin-right: 10px;
38+
}
39+
40+
.column-selector .dropdown-menu {
41+
padding: 10px;
42+
height: auto;
43+
max-height: 500px;
44+
overflow-x: hidden;
45+
}
46+
47+
.column-selector .dropdown-menu ul {
48+
padding: 0;
49+
}
50+
51+
.column-selector .dropdown-menu ul li {
52+
margin: 0;
53+
}
54+
55+
.column-selector .dropdown-menu label {
56+
width: 100%;
57+
padding: 3px;
58+
}
59+
</style>
60+
61+
<script>
62+
$('.column-select-submit').on('click', function () {
63+
64+
var defaults = @json($defaults);
65+
var selected = [];
66+
67+
$('.column-select-item:checked').each(function () {
68+
selected.push($(this).val());
69+
});
70+
71+
if (selected.length == 0) {
72+
return;
73+
}
74+
75+
var url = new URL(location);
76+
77+
if (selected.sort().toString() == defaults.sort().toString()) {
78+
url.searchParams.delete('_columns_');
79+
} else {
80+
url.searchParams.set('_columns_', selected.join());
81+
}
82+
83+
$.pjax({container:'#pjax-container', url: url.toString()});
84+
});
85+
86+
$('.column-select-all').on('click', function () {
87+
$('.column-select-item').iCheck('check');
88+
return false;
89+
});
90+
91+
$('.column-select-item').iCheck({
92+
checkboxClass:'icheckbox_minimal-blue'
93+
});
94+
</script>

resources/views/filter/button.blade.php

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
@if($scopes->isNotEmpty())
77
<button type="button" class="btn btn-sm btn-dropbox dropdown-toggle" data-toggle="dropdown">
88

9-
<span>{{ $current_label }}</span>
9+
<span>{{ $label }}</span>
1010
<span class="caret"></span>
1111
<span class="sr-only">Toggle Dropdown</span>
1212
</button>
@@ -15,7 +15,20 @@
1515
{!! $scope->render() !!}
1616
@endforeach
1717
<li role="separator" class="divider"></li>
18-
<li><a href="{{ $url_no_scopes }}">{{ trans('admin.cancel') }}</a></li>
18+
<li><a href="{{ $cancel }}">{{ trans('admin.cancel') }}</a></li>
1919
</ul>
2020
@endif
21-
</div>
21+
</div>
22+
23+
<script>
24+
var $btn = $('.{{ $btn_class }}');
25+
var $filter = $('#{{ $filter_id }}');
26+
27+
$btn.unbind('click').click(function (e) {
28+
if ($filter.is(':visible')) {
29+
$filter.addClass('hide');
30+
} else {
31+
$filter.removeClass('hide');
32+
}
33+
});
34+
</script>

resources/views/grid/batch-actions.blade.php

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
{{--<input type="checkbox" class="{{ $selectAllName }}" />&nbsp;--}}
2-
3-
@if(!$isHoldSelectAllCheckbox)
4-
<div class="btn-group {{$selectAllName}}-btn" style="display:none;margin-right: 5px;">
1+
@if(!$holdAll)
2+
<div class="btn-group {{ $all }}-btn" style="display:none;margin-right: 5px;">
53
<a class="btn btn-sm btn-default hidden-xs"><span class="selected"></span></a>
64
<button type="button" class="btn btn-sm btn-default dropdown-toggle" data-toggle="dropdown">
75
<span class="caret"></span>
@@ -19,4 +17,36 @@
1917
</ul>
2018
@endif
2119
</div>
22-
@endif
20+
@endif
21+
22+
<script>
23+
$('.{{ $all }}').iCheck({checkboxClass:'icheckbox_minimal-blue'});
24+
25+
$('.{{ $all }}').on('ifChanged', function(event) {
26+
if (this.checked) {
27+
$('.{{ $row }}-checkbox').iCheck('check');
28+
} else {
29+
$('.{{ $row }}-checkbox').iCheck('uncheck');
30+
}
31+
}).on('ifClicked', function () {
32+
if (this.checked) {
33+
$.admin.grid.selects = {};
34+
} else {
35+
$('.{{ $row }}-checkbox').each(function () {
36+
var id = $(this).data('id');
37+
$.admin.grid.select(id);
38+
});
39+
}
40+
41+
var selected = $.admin.grid.selected().length;
42+
43+
if (selected > 0) {
44+
$('.{{ $all }}-btn').show();
45+
} else {
46+
$('.{{ $all }}-btn').hide();
47+
}
48+
49+
$('.{{ $all }}-btn .selected')
50+
.html("{{ trans('admin.grid_items_selected') }}".replace('{n}', selected));
51+
});
52+
</script>

resources/views/grid/fixed-table.blade.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
<div class="box-body table-responsive no-padding">
2929
<div class="tables-container">
3030
<div class="table-wrap table-main">
31-
<table class="table " id="{{ $grid->tableID }}">
31+
<table class="table grid-table" id="{{ $grid->tableID }}">
3232
<thead>
3333
<tr>
3434
@foreach($grid->visibleColumns() as $column)
@@ -57,7 +57,7 @@
5757

5858
@if($grid->leftVisibleColumns()->isNotEmpty())
5959
<div class="table-wrap table-fixed table-fixed-left">
60-
<table class="table ">
60+
<table class="table grid-table">
6161
<thead>
6262
<tr>
6363
@foreach($grid->leftVisibleColumns() as $column)
@@ -89,7 +89,7 @@
8989

9090
@if($grid->rightVisibleColumns()->isNotEmpty())
9191
<div class="table-wrap table-fixed table-fixed-right">
92-
<table class="table ">
92+
<table class="table grid-table">
9393
<thead>
9494
<tr>
9595
@foreach($grid->rightVisibleColumns() as $column)

src/Grid/Tools/BatchActions.php

Lines changed: 11 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class BatchActions extends AbstractTool
2020
/**
2121
* @var bool
2222
*/
23-
private $isHoldSelectAllCheckbox = false;
23+
private $holdAll = false;
2424

2525
/**
2626
* BatchActions constructor.
@@ -63,7 +63,7 @@ public function disableDeleteAndHodeSelectAll()
6363
{
6464
$this->enableDelete = false;
6565

66-
$this->isHoldSelectAllCheckbox = true;
66+
$this->holdAll = true;
6767

6868
return $this;
6969
}
@@ -100,65 +100,17 @@ public function add($title, BatchAction $action = null)
100100
*
101101
* @return void
102102
*/
103-
protected function setUpScripts()
103+
protected function addActionScripts()
104104
{
105-
Admin::script($this->script());
106-
107-
foreach ($this->actions as $action) {
105+
$this->actions->each(function ($action) {
108106
$action->setGrid($this->grid);
109107

110108
if (method_exists($action, 'script')) {
111109
Admin::script($action->script());
112110
}
113-
}
114-
}
115-
116-
/**
117-
* Scripts of BatchActions button groups.
118-
*
119-
* @return string
120-
*/
121-
protected function script()
122-
{
123-
$allName = $this->grid->getSelectAllName();
124-
$rowName = $this->grid->getGridRowName();
125-
126-
$selected = trans('admin.grid_items_selected');
127-
128-
return <<<EOT
129-
130-
$('.{$allName}').iCheck({checkboxClass:'icheckbox_minimal-blue'});
131-
132-
$('.{$allName}').on('ifChanged', function(event) {
133-
if (this.checked) {
134-
$('.{$rowName}-checkbox').iCheck('check');
135-
} else {
136-
$('.{$rowName}-checkbox').iCheck('uncheck');
137-
}
138-
}).on('ifClicked', function () {
139-
if (this.checked) {
140-
$.admin.grid.selects = {};
141-
} else {
142-
$('.{$rowName}-checkbox').each(function () {
143-
var id = $(this).data('id');
144-
$.admin.grid.select(id);
145111
});
146112
}
147113

148-
var selected = $.admin.grid.selected().length;
149-
150-
if (selected > 0) {
151-
$('.{$allName}-btn').show();
152-
} else {
153-
$('.{$allName}-btn').hide();
154-
}
155-
156-
$('.{$allName}-btn .selected').html("{$selected}".replace('{n}', selected));
157-
});
158-
159-
EOT;
160-
}
161-
162114
/**
163115
* Render BatchActions button groups.
164116
*
@@ -170,14 +122,13 @@ public function render()
170122
$this->actions->shift();
171123
}
172124

173-
$this->setUpScripts();
174-
175-
$data = [
176-
'actions' => $this->actions,
177-
'selectAllName' => $this->grid->getSelectAllName(),
178-
'isHoldSelectAllCheckbox' => $this->isHoldSelectAllCheckbox,
179-
];
125+
$this->addActionScripts();
180126

181-
return view('admin::grid.batch-actions', $data)->render();
127+
return Admin::component('admin::grid.batch-actions', [
128+
'all' => $this->grid->getSelectAllName(),
129+
'row' => $this->grid->getGridRowName(),
130+
'actions' => $this->actions,
131+
'holdAll' => $this->holdAll,
132+
]);
182133
}
183134
}

0 commit comments

Comments
 (0)