Permalink
Browse files

Change users filter and pagination

  • Loading branch information...
bestmomo committed Oct 25, 2015
1 parent cc94723 commit 1c7b2f8256664fce980d1f019730d97a8024ff5e
Showing with 28 additions and 47 deletions.
  1. +1 −21 app/Http/Controllers/UserController.php
  2. +20 −0 app/helpers.php
  3. +7 −26 resources/views/back/users/index.blade.php
@@ -49,7 +49,7 @@ public function __construct(
*/
public function index()
{
return $this->indexGo('total');
return $this->indexSort('total');
}
/**
@@ -59,32 +59,12 @@ public function index()
* @return Response
*/
public function indexSort($role)
{
return $this->indexGo($role, true);
}
/**
* Display a listing of the resource.
*
* @param string $role
* @param bool $ajax
* @return Response
*/
private function indexGo($role, $ajax = false)
{
$counts = $this->user_gestion->counts();
$users = $this->user_gestion->index(4, $role);
$links = $users->setPath('')->render();
$roles = $this->role_gestion->all();
if($ajax)
{
return response()->json([
'view' => view('back.users.table', compact('users', 'links', 'counts', 'roles'))->render(),
'links' => str_replace('/sort/total', '', $links)
]);
}
return view('back.users.index', compact('users', 'links', 'counts', 'roles'));
}
View
@@ -18,4 +18,24 @@ function classActiveSegment($segment, $value)
}
return '';
}
}
if (!function_exists('classActiveOnlyPath')) {
function classActiveOnlyPath($path)
{
return Request::is($path) ? ' active' : '';
}
}
if (!function_exists('classActiveOnlySegment')) {
function classActiveOnlySegment($segment, $value)
{
if(!is_array($value)) {
return Request::segment($segment) == $value ? ' active' : '';
}
foreach ($value as $v) {
if(Request::segment($segment) == $v) return ' active';
}
return '';
}
}
@@ -18,9 +18,13 @@
@include('back.partials.entete', ['title' => trans('back/users.dashboard') . link_to_route('user.create', trans('back/users.add'), [], ['class' => 'btn btn-info pull-right']), 'icone' => 'user', 'fil' => trans('back/users.users')])
<div id="tri" class="btn-group btn-group-sm">
<a href="#" type="button" name="total" class="btn btn-default active">{{ trans('back/users.all') }} <span class="badge">{{ $counts['total'] }}</span></a>
<a href="{!! url('user') !!}" type="button" name="total" class="btn btn-default {{ classActiveOnlyPath('user') }}">{{ trans('back/users.all') }}
<span class="badge">{{ $counts['total'] }}</span>
</a>
@foreach ($roles as $role)
<a href="#" type="button" name="{!! $role->slug !!}" class="btn btn-default">{{ $role->title . 's' }} <span class="badge">{{ $counts[$role->slug] }}</span></a>
<a href="{!! url('user/sort/' . $role->slug) !!}" type="button" name="{!! $role->slug !!}" class="btn btn-default {{ classActiveOnlySegment(3, $role->slug) }}">{{ $role->title . 's' }}
<span class="badge">{{ $counts[$role->slug] }}</span>
</a>
@endforeach
</div>
@@ -63,7 +67,7 @@
$(this).hide().parent().append('<i class="fa fa-refresh fa-spin"></i>');
var token = $('input[name="_token"]').val();
$.ajax({
url: 'userseen/' + this.value,
url: '{!! url('userseen') !!}' + '/' + this.value,
type: 'PUT',
data: "seen=" + this.checked + "&_token=" + token
})
@@ -79,29 +83,6 @@
});
});
// Sorting gestion
$('#tri').find('a').click(function(e) {
e.preventDefault();
// Wait icon
$('.breadcrumb li').append('<span id="tempo" class="fa fa-refresh fa-spin"></span>');
// Buttons aspect
$('#tri').find('a').removeClass('active');
// Send ajax
$.ajax({
url: 'user/sort/' + $(this).attr('name'),
type: 'GET',
dataType: 'json'
})
.done(function(data) {
$('tbody').html(data.view);
$('.link').html(data.links);
$('#tempo').remove();
})
.fail(function() {
alert('{{ trans('back/users.fail') }}');
});
});
});
</script>

0 comments on commit 1c7b2f8

Please sign in to comment.