-
Notifications
You must be signed in to change notification settings - Fork 258
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New column type: action. Use it to add custom buttons to the tablevie…
…w. See documentation for details
- Loading branch information
1 parent
8c0ad0c
commit 8b3f4c8
Showing
7 changed files
with
290 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
CHANGELOG | ||
========= | ||
|
||
2014-11-04, v1.1.0 | ||
------------------ | ||
|
||
* New column type: action. Use it to add custom buttons to the tableview. See documentation for details | ||
|
||
2014-10-29, v1.0.10 | ||
------------------ | ||
|
||
* Bugfix: Administrator username maximum length reduced to 190 to support utf8mb4 charset. Fix issue #1 | ||
|
||
2014-10-20, v1.0.9 | ||
------------------ | ||
|
||
* Bugfix: Fixed bug with wrong date format | ||
|
||
2014-10-20, v1.0.8 | ||
------------------ | ||
|
||
* New way to add validation rules to form elements and combine it with old method | ||
|
||
2014-10-16, v1.0.7 | ||
------------------ | ||
|
||
* New exception when "intl" extension not installed | ||
|
||
2014-10-16, v1.0.6 | ||
------------------ | ||
|
||
* Bugfix: Default admin credentials seeding fixed | ||
|
||
2014-10-16, v1.0.5 | ||
------------------ | ||
|
||
* PHP 5.4 support added | ||
|
||
2014-10-16, v1.0.4 | ||
------------------ | ||
|
||
* ValidationException handler moved to service provider | ||
* Bugfix: Menu with subitems icon problem solved | ||
|
||
2014-10-15, v1.0.3 | ||
------------------ | ||
|
||
* Image info speed improvements | ||
* Model compiler template update | ||
* Added user-friendly error message for missing getList method | ||
|
||
2014-10-15, v1.0.2 | ||
------------------ | ||
|
||
* Global validation exception handler added | ||
|
||
2014-10-13, v1.0.0 | ||
------------------ | ||
|
||
* Initial Version |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,171 @@ | ||
<?php namespace SleepingOwl\Admin\Columns\Column; | ||
|
||
use SleepingOwl\Admin\Admin; | ||
use SleepingOwl\Html\FormBuilder; | ||
use Lang; | ||
use SleepingOwl\Models\Interfaces\ModelWithOrderFieldInterface; | ||
|
||
class Action extends BaseColumn | ||
{ | ||
/** | ||
* @var \SleepingOwl\Admin\Router | ||
*/ | ||
protected $router; | ||
/** | ||
* @var FormBuilder | ||
*/ | ||
protected $formBuilder; | ||
/** | ||
* @var string | ||
*/ | ||
protected $icon = null; | ||
/** | ||
* @var string | ||
*/ | ||
protected $style = 'long'; | ||
/** | ||
* @var string|\Closure | ||
*/ | ||
protected $url; | ||
/** | ||
* @var \Closure | ||
*/ | ||
protected $callback; | ||
/** | ||
* @var string | ||
*/ | ||
protected $target; | ||
|
||
/** | ||
* | ||
*/ | ||
function __construct($name, $label = null) | ||
{ | ||
parent::__construct($name, $label); | ||
$this->sortable = false; | ||
$admin = Admin::instance(); | ||
$this->router = $admin->router; | ||
$this->formBuilder = $admin->formBuilder; | ||
} | ||
|
||
public function renderHeader() | ||
{ | ||
return $this->htmlBuilder->tag('th', $this->getAttributesForHeader()); | ||
} | ||
|
||
/** | ||
* @param $instance | ||
* @param int $totalCount | ||
* @return string | ||
*/ | ||
public function render($instance, $totalCount) | ||
{ | ||
$buttons = []; | ||
$buttons[] = $this->button($instance); | ||
return $this->htmlBuilder->tag('td', ['class' => 'text-right'], implode(' ', $buttons)); | ||
} | ||
|
||
/** | ||
* @param $instance | ||
* @return string | ||
*/ | ||
protected function button($instance) | ||
{ | ||
if ( ! is_null($this->url)) | ||
{ | ||
if (is_callable($this->url)) | ||
{ | ||
$callback = $this->url; | ||
$url = $callback($instance); | ||
} else | ||
{ | ||
$url = strtr($this->url, [':id' => $instance->id]); | ||
} | ||
} else | ||
{ | ||
$url = $this->router->routeToTable($this->modelItem->getAlias(), [ | ||
'action' => $this->name, | ||
'id' => $instance->id | ||
]); | ||
} | ||
$attributes = [ | ||
'class' => 'btn btn-default btn-sm', | ||
'href' => $url, | ||
'data-toggle' => 'tooltip', | ||
]; | ||
$content = ''; | ||
if ( ! is_null($this->icon)) | ||
{ | ||
$content .= '<i class="fa ' . $this->icon . '"></i>'; | ||
} | ||
if ($this->style === 'long') | ||
{ | ||
$content .= ' ' . $this->label; | ||
} else | ||
{ | ||
$attributes['title'] = $this->label; | ||
} | ||
if ( ! is_null($this->target)) | ||
{ | ||
$attributes['target'] = $this->target; | ||
} | ||
return $this->htmlBuilder->tag('a', $attributes, $content); | ||
} | ||
|
||
/** | ||
* @param string $icon | ||
* @return $this | ||
*/ | ||
public function icon($icon) | ||
{ | ||
$this->icon = $icon; | ||
return $this; | ||
} | ||
|
||
/** | ||
* @param string $style | ||
* @return $this | ||
*/ | ||
public function style($style) | ||
{ | ||
$this->style = $style; | ||
return $this; | ||
} | ||
|
||
/** | ||
* @param string|\Closure $url | ||
* @return $this | ||
*/ | ||
public function url($url) | ||
{ | ||
$this->url = $url; | ||
return $this; | ||
} | ||
|
||
/** | ||
* @param callable $callback | ||
* @return $this | ||
*/ | ||
public function callback($callback) | ||
{ | ||
$this->callback = $callback; | ||
return $this; | ||
} | ||
|
||
public function call($instance) | ||
{ | ||
$callback = $this->callback; | ||
return $callback($instance); | ||
} | ||
|
||
/** | ||
* @param string $target | ||
* @return $this | ||
*/ | ||
public function target($target) | ||
{ | ||
$this->target = $target; | ||
return $this; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters