mirror of
				https://github.com/invoiceninja/invoiceninja.git
				synced 2025-10-31 12:27:31 -04:00 
			
		
		
		
	
		
			
				
	
	
		
			94 lines
		
	
	
		
			2.0 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			94 lines
		
	
	
		
			2.0 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
| <?php
 | |
| 
 | |
| namespace App\Ninja\Datatables;
 | |
| 
 | |
| class EntityDatatable
 | |
| {
 | |
|     public $entityType;
 | |
|     public $isBulkEdit;
 | |
|     public $hideClient;
 | |
|     public $sortCol = 1;
 | |
| 
 | |
|     public function __construct($isBulkEdit = true, $hideClient = false, $entityType = false)
 | |
|     {
 | |
|         $this->isBulkEdit = $isBulkEdit;
 | |
|         $this->hideClient = $hideClient;
 | |
| 
 | |
|         if ($entityType) {
 | |
|             $this->entityType = $entityType;
 | |
|         }
 | |
|     }
 | |
| 
 | |
|     public function columns()
 | |
|     {
 | |
|         return [];
 | |
|     }
 | |
| 
 | |
|     public function actions()
 | |
|     {
 | |
|         return [];
 | |
|     }
 | |
| 
 | |
|     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")',
 | |
|             ],
 | |
|         ];
 | |
|     }
 | |
| 
 | |
|     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;
 | |
|     }
 | |
| 
 | |
|     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;
 | |
|     }
 | |
| }
 |