true,
'edit' => true,
'quickEdit' => false,
'delete' => true,
];
/**
* @var string
*/
protected $resource;
/**
* Append a action.
*
* @param string|Renderable|Action|Htmlable $action
*
* @return $this
*/
public function append($action)
{
$this->prepareAction($action);
array_push($this->appends, $action);
return $this;
}
/**
* Prepend a action.
*
* @param string|Renderable|Action|Htmlable $action
*
* @return $this
*/
public function prepend($action)
{
$this->prepareAction($action);
array_unshift($this->prepends, $action);
return $this;
}
/**
* @param mixed $action
*
* @return void
*/
protected function prepareAction(&$action)
{
if ($action instanceof RowAction) {
$action->setGrid($this->grid)
->setColumn($this->column)
->setRow($this->row);
}
}
public function view(bool $value = true)
{
return $this->setAction('view', $value);
}
/**
* Disable view action.
*
* @param bool $disable
*
* @return $this
*/
public function disableView(bool $disable = true)
{
return $this->setAction('view', ! $disable);
}
public function delete(bool $value = true)
{
return $this->setAction('delete', $value);
}
/**
* Disable delete.
*
* @param bool $disable
*
* @return $this.
*/
public function disableDelete(bool $disable = true)
{
return $this->setAction('delete', ! $disable);
}
public function edit(bool $value = true)
{
return $this->setAction('edit', $value);
}
/**
* Disable edit.
*
* @param bool $disable
*
* @return $this.
*/
public function disableEdit(bool $disable = true)
{
return $this->setAction('edit', ! $disable);
}
public function quickEdit(bool $value = true)
{
return $this->setAction('quickEdit', $value);
}
/**
* Disable quick edit.
*
* @param bool $disable
*
* @return $this.
*/
public function disableQuickEdit(bool $disable = true)
{
return $this->setAction('quickEdit', ! $disable);
}
/**
* @param string $key
* @param bool $disable
*
* @return $this
*/
protected function setAction(string $key, bool $value)
{
$this->actions[$key] = $value;
return $this;
}
/**
* Set resource of current resource.
*
* @param $resource
*
* @return $this
*/
public function setResource($resource)
{
$this->resource = $resource;
return $this;
}
/**
* Get resource of current resource.
*
* @return string
*/
public function resource()
{
return $this->resource ?: parent::resource();
}
/**
* @return void
*/
protected function resetsetActions()
{
$this->view($this->grid->option('view_button'));
$this->edit($this->grid->option('edit_button'));
$this->quickEdit($this->grid->option('quick_edit_button'));
$this->delete($this->grid->option('delete_button'));
}
/**
* @param array $callbacks
*
* @return void
*/
protected function call(array $callbacks = [])
{
foreach ($callbacks as $callback) {
if ($callback instanceof \Closure) {
$callback->call($this->row, $this);
}
}
}
/**
* {@inheritdoc}
*/
public function display(array $callbacks = [])
{
$this->resetsetActions();
$this->call($callbacks);
$toString = [Helper::class, 'render'];
$prepends = array_map($toString, $this->prepends);
$appends = array_map($toString, $this->appends);
foreach ($this->actions as $action => $enable) {
if ($enable) {
$method = 'render'.ucfirst($action);
array_push($prepends, $this->{$method}());
}
}
return implode('', array_merge($prepends, $appends));
}
/**
* Render view action.
*
* @return string
*/
protected function renderView()
{
$label = trans('admin.show');
return Show::make(
" "
)
->setGrid($this->grid)
->setRow($this->row)
->render();
}
/**
* Render edit action.
*
* @return string
*/
protected function renderEdit()
{
$label = trans('admin.edit');
return Edit::make(
" "
)
->setGrid($this->grid)
->setRow($this->row)
->render();
}
/**
* @return string
*/
protected function renderQuickEdit()
{
if (! static::$resolvedDialog) {
static::$resolvedDialog = true;
[$width, $height] = $this->grid->option('dialog_form_area');
Form::dialog(trans('admin.edit'))
->click(".{$this->grid->getRowName()}-edit")
->dimensions($width, $height)
->success('Dcat.reload()');
}
$label = trans('admin.quick_edit');
return QuickEdit::make(
" "
)
->setGrid($this->grid)
->setRow($this->row)
->render();
}
/**
* Render delete action.
*
* @return string
*/
protected function renderDelete()
{
$label = trans('admin.delete');
return Delete::make(
" "
)
->setGrid($this->grid)
->setRow($this->row)
->render();
}
}