2017-01-30 20:40:43 +01: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")',
|
2017-01-30 20:40:43 +01:00
|
|
|
],
|
2016-12-14 20:47:22 +01:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
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
|
2017-01-30 20:40:43 +01:00
|
|
|
if (! $column[2]) {
|
2016-11-24 10:22:37 +01:00
|
|
|
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;
|
|
|
|
}
|
2017-10-14 19:55:37 +02:00
|
|
|
|
|
|
|
public function addNote($str, $note) {
|
|
|
|
if (! $note) {
|
|
|
|
return $str;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $str . ' <span class="fa fa-file-o" data-toggle="tooltip" data-placement="bottom" title="' . e($note) . '"></span>';
|
|
|
|
}
|
2018-01-25 10:42:58 +01:00
|
|
|
|
|
|
|
public function showWithTooltip($str, $max = 60) {
|
|
|
|
$str = e($str);
|
|
|
|
|
|
|
|
if (strlen($str) > $max) {
|
|
|
|
return '<span data-toggle="tooltip" data-placement="bottom" title="' . $str . '">' . trim(substr($str, 0, $max)) . '...' . '</span>';
|
|
|
|
} else {
|
|
|
|
return $str;
|
|
|
|
}
|
|
|
|
}
|
2016-05-23 18:52:20 +02:00
|
|
|
}
|