| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- <?php
- namespace Dcat\Admin\Show;
- use Dcat\Admin\Grid;
- use Dcat\Admin\Show;
- use Illuminate\Support\Fluent;
- class Relation extends Field
- {
- /**
- * Relation name.
- *
- * @var string
- */
- protected $name;
- /**
- * Relation panel builder.
- *
- * @var \Closure
- */
- protected $builder;
- /**
- * Relation panel title.
- *
- * @var string
- */
- protected $title;
- /**
- * Parent model.
- *
- * @var Fluent
- */
- protected $model;
- /**
- * Relation constructor.
- *
- * @param string $name
- * @param \Closure $builder
- * @param string $title
- */
- public function __construct($name, $builder, $title = '')
- {
- $this->name = $name;
- $this->builder = $builder;
- $this->title = $this->formatLabel($title);
- }
- /**
- * Set parent model for relation.
- *
- * @param Fluent $model
- *
- * @return $this
- */
- public function setModel(Fluent $model)
- {
- $this->model = $model;
- return $this;
- }
- /**
- * Render this relation panel.
- *
- * @return string
- */
- public function render()
- {
- $view = call_user_func($this->builder, $this->model);
- if ($view instanceof Show) {
- return $this->renderTitle().$view->render();
- }
- if (!$view instanceof Grid) {
- return $this->renderTitle().$view;
- }
- $view->setName($this->name)
- ->disableFilterButton()
- ->disableBatchDelete()
- ->disableFilter();
- $filter = $view->getFilter()
- ->expand()
- ->withoutInputBorder()
- ->hiddenResetButtonText()
- ->expand()
- ->style('padding:0 0 5px;left:-5px;');
- $filter = "<div class='row'><div class='col-md-12'>{$filter->render()}</div></div>";
- return $this->renderTitle().$filter.$view->render();
- }
- /**
- * @return string
- */
- protected function renderTitle()
- {
- return <<<EOF
- <div class="row">
- <div class="col-md-12" style="margin-bottom:.75rem;font-size:18px;text-transform:uppercase">
- <span class="show-relation-grid-title">{$this->title}</span>
- </div>
- </div>
- EOF;
- }
- }
|