Merge pull request #1116 from madd15/bootstrap-table-experiment
Add base for Licenses with bootstrap tables
This commit is contained in:
@@ -887,32 +887,39 @@ class LicensesController extends AdminController
|
||||
}
|
||||
|
||||
public function getDatatable() {
|
||||
$licenses = License::orderBy('created_at', 'DESC')->get();
|
||||
$licenses = License::select('id','name','serial','purchase_date','seats');
|
||||
|
||||
$actions = new \Chumper\Datatable\Columns\FunctionColumn('actions', function($licenses) {
|
||||
return '<span style="white-space: nowrap;"><a href="'.route('freecheckout/license', $licenses->id).'" class="btn btn-primary btn-sm" style="margin-right:5px;" '.(($licenses->remaincount() > 0) ? '' : 'disabled').'>'.Lang::get('general.checkout').'</a> <a href="'.route('clone/license', $licenses->id).'" class="btn btn-info btn-sm" style="margin-right:5px;" title="Clone asset"><i class="fa fa-files-o"></i></a><a href="'.route('update/license', $licenses->id).'" class="btn btn-warning btn-sm" style="margin-right:5px;"><i class="fa fa-pencil icon-white"></i></a><a data-html="false" class="btn delete-asset btn-danger btn-sm" data-toggle="modal" href="'.route('delete/license', $licenses->id).'" data-content="'.Lang::get('admin/licenses/message.delete.confirm').'" data-title="'.Lang::get('general.delete').' '.htmlspecialchars($licenses->name).'?" onClick="return false;"><i class="fa fa-trash icon-white"></i></a></span>';
|
||||
});
|
||||
if (Input::has('search')) {
|
||||
$licenses = $licenses->TextSearch(Input::get('search'));
|
||||
}
|
||||
|
||||
return Datatable::collection($licenses)
|
||||
->addColumn('name', function($licenses) {
|
||||
return link_to('/admin/licenses/'.$licenses->id.'/view', $licenses->name);
|
||||
})
|
||||
->addColumn('serial', function($licenses) {
|
||||
return link_to('/admin/licenses/'.$licenses->id.'/view', mb_strimwidth($licenses->serial, 0, 50, "..."));
|
||||
})
|
||||
->addColumn('totalSeats', function($licenses) {
|
||||
return $licenses->totalSeatsByLicenseID();
|
||||
})
|
||||
->addColumn('remaining', function($licenses) {
|
||||
return $licenses->remaincount();
|
||||
})
|
||||
->addColumn('purchase_date', function($licenses) {
|
||||
return $licenses->purchase_date;
|
||||
})
|
||||
->addColumn($actions)
|
||||
->searchColumns('name','serial','totalSeats','remaining','purchase_date','actions')
|
||||
->orderColumns('name','serial','totalSeats','remaining','purchase_date','actions')
|
||||
->make();
|
||||
$allowed_columns = ['name'];
|
||||
$order = Input::get('order') === 'asc' ? 'asc' : 'desc';
|
||||
$sort = in_array(Input::get('sort'), $allowed_columns) ? Input::get('sort') : 'created_at';
|
||||
|
||||
$licenses = $licenses->orderBy($sort, $order);
|
||||
|
||||
$licenseCount = $licenses->count();
|
||||
$licenses = $licenses->skip(Input::get('offset'))->take(Input::get('limit'))->get();
|
||||
|
||||
$rows = array();
|
||||
|
||||
foreach ($licenses as $license) {
|
||||
$actions = '<span style="white-space: nowrap;"><a href="'.route('freecheckout/license', $license->id).'" class="btn btn-primary btn-sm" style="margin-right:5px;" '.(($license->remaincount() > 0) ? '' : 'disabled').'>'.Lang::get('general.checkout').'</a> <a href="'.route('clone/license', $license->id).'" class="btn btn-info btn-sm" style="margin-right:5px;" title="Clone asset"><i class="fa fa-files-o"></i></a><a href="'.route('update/license', $license->id).'" class="btn btn-warning btn-sm" style="margin-right:5px;"><i class="fa fa-pencil icon-white"></i></a><a data-html="false" class="btn delete-asset btn-danger btn-sm" data-toggle="modal" href="'.route('delete/license', $license->id).'" data-content="'.Lang::get('admin/licenses/message.delete.confirm').'" data-title="'.Lang::get('general.delete').' '.htmlspecialchars($license->name).'?" onClick="return false;"><i class="fa fa-trash icon-white"></i></a></span>';
|
||||
|
||||
$rows[] = array(
|
||||
'name' => link_to('/admin/licenses/'.$license->id.'/view', $license->name),
|
||||
'serial' => link_to('/admin/licenses/'.$license->id.'/view', mb_strimwidth($license->serial, 0, 50, "...")),
|
||||
'totalSeats' => $license->totalSeatsByLicenseID(),
|
||||
'remaining' => $license->remaincount(),
|
||||
'purchase_date' => ($license->purchase_date) ? $license->purchase_date : '',
|
||||
'actions' => $actions
|
||||
);
|
||||
}
|
||||
|
||||
$data = array('total' => $licenseCount, 'rows' => $rows);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function getFreeLicense($licenseId) {
|
||||
|
||||
@@ -176,4 +176,21 @@ public function freeSeat()
|
||||
->get();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Query builder scope to search on text
|
||||
*
|
||||
* @param Illuminate\Database\Query\Builder $query Query builder instance
|
||||
* @param text $search Search term
|
||||
*
|
||||
* @return Illuminate\Database\Query\Builder Modified query builder
|
||||
*/
|
||||
public function scopeTextSearch($query, $search)
|
||||
{
|
||||
|
||||
return $query->where(function($query) use ($search)
|
||||
{
|
||||
$query->where('name', 'LIKE', '%'.$search.'%');
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,39 +17,46 @@
|
||||
</div>
|
||||
|
||||
<div class="row form-wrapper">
|
||||
{{ Datatable::table()
|
||||
->addColumn(Lang::get('admin/licenses/table.title'),
|
||||
Lang::get('admin/licenses/table.serial'),
|
||||
Lang::get('admin/licenses/form.seats'),
|
||||
Lang::get('admin/licenses/form.remaining_seats'),
|
||||
Lang::get('admin/licenses/table.purchase_date'),
|
||||
Lang::get('table.actions'))
|
||||
->setOptions(
|
||||
array(
|
||||
'language' => array(
|
||||
'search' => Lang::get('general.search'),
|
||||
'lengthMenu' => Lang::get('general.page_menu'),
|
||||
'loadingRecords' => Lang::get('general.loading'),
|
||||
'zeroRecords' => Lang::get('general.no_results'),
|
||||
'info' => Lang::get('general.pagination_info'),
|
||||
'processing' => Lang::get('general.processing'),
|
||||
'paginate'=> array(
|
||||
'first'=>Lang::get('general.first'),
|
||||
'previous'=>Lang::get('general.previous'),
|
||||
'next'=>Lang::get('general.next'),
|
||||
'last'=>Lang::get('general.last'),
|
||||
),
|
||||
),
|
||||
'sAjaxSource'=>route('api.licenses.list'),
|
||||
'dom' =>'CT<"clear">lfrtip',
|
||||
'colVis'=> array('showAll'=>'Show All','restore'=>'Restore','exclude'=>array(5),'activate'=>'mouseover'),
|
||||
'columnDefs'=> array(
|
||||
array('bSortable'=>false,'targets'=>array(5)),
|
||||
array('width'=>'20%','targets'=>array(5)),
|
||||
),
|
||||
'order'=>array(array(0,'asc')),
|
||||
)
|
||||
)
|
||||
->render() }}
|
||||
<table name="licenses" id="table" data-url="{{route('api.licenses.list')}}">
|
||||
<thead>
|
||||
<tr>
|
||||
<th data-field="name">{{Lang::get('admin/licenses/table.title')}}</th>
|
||||
<th data-field="serial">{{Lang::get('admin/licenses/table.serial')}}</th>
|
||||
<th data-field="totalSeats">{{Lang::get('admin/licenses/form.seats')}}</th>
|
||||
<th data-field="remaining">{{Lang::get('admin/licenses/form.remaining_seats')}}</th>
|
||||
<th data-field="purchase_date">{{Lang::get('admin/licenses/table.purchase_date')}}</th>
|
||||
<th data-field="actions">{{Lang::get('table.actions')}}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<script type="text/javascript">
|
||||
$('#table').bootstrapTable({
|
||||
classes: 'table table-hover table-no-bordered',
|
||||
undefinedText: 'undefined',
|
||||
iconsPrefix: 'fa',
|
||||
showRefresh: true,
|
||||
search: true,
|
||||
pageSize: {{{ Setting::getSettings()->per_page }}},
|
||||
pagination: true,
|
||||
sidePagination: 'server',
|
||||
sortable: true,
|
||||
mobileResponsive: true,
|
||||
showExport: true,
|
||||
showColumns: false,
|
||||
maintainSelected: true,
|
||||
paginationFirstText: "@lang('general.first')",
|
||||
paginationLastText: "@lang('general.last')",
|
||||
paginationPreText: "@lang('general.previous')",
|
||||
paginationNextText: "@lang('general.next')",
|
||||
pageList: ['10','25','50','100','150','200'],
|
||||
icons: {
|
||||
paginationSwitchDown: 'fa-caret-square-o-down',
|
||||
paginationSwitchUp: 'fa-caret-square-o-up',
|
||||
columns: 'fa-columns',
|
||||
refresh: 'fa-refresh'
|
||||
},
|
||||
});
|
||||
</script>
|
||||
@stop
|
||||
|
||||
Reference in New Issue
Block a user