| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171 |
- <?php
- namespace Dcat\Admin\Grid\Displayers;
- use Dcat\Admin\Admin;
- use Dcat\Admin\Support\Helper;
- use Illuminate\Contracts\Support\Arrayable;
- class DialogTree extends AbstractDisplayer
- {
- protected $url;
- protected $title;
- protected $area = ['580px', '600px'];
- protected $options = [
- 'plugins' => ['checkbox', 'types'],
- 'core' => [
- 'check_callback' => true,
- 'themes' => [
- 'name' => 'proton',
- 'responsive' => true,
- ],
- ],
- 'checkbox' => [
- 'keep_selected_style' => false,
- ],
- 'types' => [
- 'default' => [
- 'icon' => false,
- ],
- ],
- ];
- protected $columnNames = [
- 'id' => 'id',
- 'text' => 'name',
- 'parent' => 'parent_id',
- ];
- protected $nodes = [];
- protected $checkAll;
- /**
- * @param array $data exp:
- * {
- * "id": "1",
- * "parent": "#",
- * "text": "Dashboard",
- * // "state": {"selected": true}
- * }
- * @param array $data
- *
- * @return $this
- */
- public function nodes($data)
- {
- if ($data instanceof Arrayable) {
- $data = $data->toArray();
- }
- $this->nodes = &$data;
- return $this;
- }
- public function url(string $source)
- {
- $this->url = admin_url($source);
- return $this;
- }
- public function checkAll()
- {
- $this->checkAll = true;
- return $this;
- }
- /**
- * @param array $options
- *
- * @return $this
- */
- public function options($options = [])
- {
- if ($options instanceof Arrayable) {
- $options = $options->toArray();
- }
- $this->options = array_merge($this->options, $options);
- return $this;
- }
- public function title($title)
- {
- $this->title = $title;
- return $this;
- }
- /**
- * @param string $width
- * @param string $height
- *
- * @return $this
- */
- public function area(string $width, string $height)
- {
- $this->area = [$width, $height];
- return $this;
- }
- public function setIdColumn(string $name)
- {
- $this->columnNames['id'] = $name;
- return $this;
- }
- public function setTitleColumn(string $name)
- {
- $this->columnNames['text'] = $name;
- return $this;
- }
- public function setParentColumn(string $name)
- {
- $this->columnNames['parent'] = $name;
- return $this;
- }
- public function display($callbackOrNodes = null)
- {
- if (is_array($callbackOrNodes) || $callbackOrNodes instanceof Arrayable) {
- $this->nodes($callbackOrNodes);
- } elseif ($callbackOrNodes instanceof \Closure) {
- $callbackOrNodes->call($this->row, $this);
- }
- return Admin::view('admin::grid.displayer.dialogtree', [
- 'value' => $this->format($this->value),
- 'prefix' => $this->getSelectorPrefix(),
- 'nodes' => $this->nodes,
- 'title' => $this->title ?: $this->column->getLabel(),
- 'options' => $this->options,
- 'area' => $this->area,
- 'columnNames' => $this->columnNames,
- 'url' => $this->url,
- 'checkAll' => $this->checkAll,
- ]);
- }
- protected function format($val)
- {
- return implode(',', Helper::array($val, true));
- }
- protected function getSelectorPrefix()
- {
- return $this->grid->getName().'_'.$this->column->getName().'_'.$this->getKey();
- }
- }
|