grid = $grid; $this->tools = new Collection(); $this->appendDefaultTools(); } /** * Append default tools. */ protected function appendDefaultTools() { $this->append(new BatchActions()) ->append(new RefreshButton()) ->append(new FilterButton()); } /** * Append tools. * * @param AbstractTool|string|\Closure|Renderable|Htmlable $tool * * @return $this */ public function append($tool) { $this->tools->push($tool); return $this; } /** * Prepend a tool. * * @param AbstractTool|string|\Closure|Renderable|Htmlable $tool * * @return $this */ public function prepend($tool) { $this->tools->prepend($tool); return $this; } public function has() { return ! $this->tools->isEmpty(); } /** * Disable filter button. * * @return void */ public function disableFilterButton(bool $disable = true) { $this->tools = $this->tools->map(function ($tool) use ($disable) { if ($tool instanceof FilterButton) { return $tool->disable($disable); } return $tool; }); } /** * Disable refresh button. * * @return void */ public function disableRefreshButton(bool $disable = true) { $this->tools = $this->tools->map(function ($tool) use ($disable) { if ($tool instanceof RefreshButton) { return $tool->disable($disable); } return $tool; }); } /** * Disable batch actions. * * @return void */ public function disableBatchActions(bool $disable = true) { $this->tools = $this->tools->map(function ($tool) use ($disable) { if ($tool instanceof BatchActions) { return $tool->disable($disable); } return $tool; }); } /** * @param \Closure $closure */ public function batch(\Closure $closure) { call_user_func($closure, $this->tools->first(function ($tool) { return $tool instanceof BatchActions; })); } /** * Render header tools bar. * * @return string */ public function render() { return $this->tools->map(function ($tool) { if ($tool instanceof AbstractTool) { if (! $tool->allowed()) { return ''; } return $tool->setGrid($this->grid)->render(); } return Helper::render($tool); })->implode(' '); } }