2016-07-21 14:35:23 +02:00
|
|
|
<?php namespace App\Ninja\Datatables;
|
2016-05-23 18:52:20 +02:00
|
|
|
|
|
|
|
class EntityDatatable
|
|
|
|
{
|
|
|
|
public $entityType;
|
|
|
|
public $isBulkEdit;
|
|
|
|
public $hideClient;
|
2016-11-24 10:41:11 +01:00
|
|
|
public $sortCol = 1;
|
2016-05-23 18:52:20 +02:00
|
|
|
|
2016-11-24 10:22:37 +01:00
|
|
|
public function __construct($isBulkEdit = true, $hideClient = false, $entityType = false)
|
2016-05-23 18:52:20 +02:00
|
|
|
{
|
|
|
|
$this->isBulkEdit = $isBulkEdit;
|
|
|
|
$this->hideClient = $hideClient;
|
2016-11-24 10:22:37 +01:00
|
|
|
|
|
|
|
if ($entityType) {
|
|
|
|
$this->entityType = $entityType;
|
|
|
|
}
|
2016-05-23 18:52:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function columns()
|
|
|
|
{
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
|
|
|
|
public function actions()
|
|
|
|
{
|
|
|
|
return [];
|
|
|
|
}
|
2016-11-24 10:22:37 +01:00
|
|
|
|
2016-12-14 20:47:22 +01:00
|
|
|
public function bulkActions()
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
[
|
|
|
|
'label' => mtrans($this->entityType, 'archive_'.$this->entityType),
|
|
|
|
'url' => 'javascript:submitForm_'.$this->entityType.'("archive")',
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'label' => mtrans($this->entityType, 'delete_'.$this->entityType),
|
|
|
|
'url' => 'javascript:submitForm_'.$this->entityType.'("delete")',
|
|
|
|
]
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2016-11-24 10:22:37 +01:00
|
|
|
public function columnFields()
|
|
|
|
{
|
|
|
|
$data = [];
|
|
|
|
$columns = $this->columns();
|
|
|
|
|
|
|
|
if ($this->isBulkEdit) {
|
|
|
|
$data[] = 'checkbox';
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($columns as $column) {
|
|
|
|
if (count($column) == 3) {
|
|
|
|
// third column is optionally used to determine visibility
|
|
|
|
if (!$column[2]) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$data[] = $column[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
$data[] = '';
|
|
|
|
|
|
|
|
return $data;
|
|
|
|
}
|
2016-12-25 22:43:57 +01:00
|
|
|
|
|
|
|
public function rightAlignIndices()
|
|
|
|
{
|
|
|
|
return $this->alignIndices(['amount', 'balance', 'cost']);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function centerAlignIndices()
|
|
|
|
{
|
|
|
|
return $this->alignIndices(['status']);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function alignIndices($fields)
|
|
|
|
{
|
|
|
|
$columns = $this->columnFields();
|
|
|
|
$indices = [];
|
|
|
|
|
|
|
|
foreach ($columns as $index => $column) {
|
|
|
|
if (in_array($column, $fields)) {
|
|
|
|
$indices[] = $index + 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $indices;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-05-23 18:52:20 +02:00
|
|
|
}
|