1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-13 22:54:25 +01:00
invoiceninja/app/Ninja/Datatables/EntityDatatable.php

112 lines
2.6 KiB
PHP
Raw Normal View History

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
public function __construct($isBulkEdit = true, $hideClient = false, $entityType = false)
2016-05-23 18:52:20 +02:00
{
$this->isBulkEdit = $isBulkEdit;
$this->hideClient = $hideClient;
if ($entityType) {
$this->entityType = $entityType;
}
2016-05-23 18:52:20 +02:00
}
public function columns()
{
return [];
}
public function actions()
{
return [];
}
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
];
}
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]) {
continue;
}
}
$data[] = $column[0];
}
$data[] = '';
return $data;
}
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 . '&nbsp; <span class="fa fa-file-o" data-toggle="tooltip" data-placement="bottom" title="' . e($note) . '"></span>';
}
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
}