button = $button; } public function display($callbackOrButton = null) { $html = $this->value; $remoteUrl = ''; if ($callbackOrButton && $callbackOrButton instanceof \Closure) { $callbackOrButton = $callbackOrButton->call($this->row, $this); if (! $callbackOrButton instanceof LazyRenderable) { $html = Helper::render($callbackOrButton); $callbackOrButton = null; } } if ($callbackOrButton instanceof LazyRenderable) { $html = '
'; $remoteUrl = $callbackOrButton->getUrl(); } elseif (is_string($callbackOrButton) && is_subclass_of($callbackOrButton, LazyRenderable::class)) { $html = '
'; $renderable = $callbackOrButton::make(); $remoteUrl = $renderable->getUrl(); } elseif ($callbackOrButton && is_string($callbackOrButton)) { $this->button = $callbackOrButton; } $this->addScript(); $key = $this->getDataKey(); $button = is_null($this->button) ? $this->value : $this->button; return << $button EOT; } /** * @return string */ protected function getDataKey() { $key = $this->getKey() ?: Str::random(8); static::$counter++; return $this->grid->getName().$key.'-'.static::$counter; } protected function addScript() { $script = <<<'JS' $('.grid-expand').off('click').on('click', function () { var _th = $(this), url = _th.data('url'); if ($(this).data('inserted') == '0') { var key = _th.data('key'); var row = _th.closest('tr'); var html = $('template.grid-expand-'+key).html(); var id = 'expand-'+key+Dcat.helpers.random(10); var rowKey = _th.data('id'); $(this).attr('data-expand', '#'+id); row.after(""+html+""); if (url) { var collapse = $('#grid-collapse-'+key); collapse.find('div').loading(); $('.dcat-loading').css({position: 'inherit', 'padding-top': '70px'}); Dcat.helpers.asyncRender(url+'&key='+rowKey, function (html) { collapse.html(html); }) } $(this).data('inserted', 1); } else { if ($("i", this).hasClass('icon-chevrons-right')) { $(_th.data('expand')).show(); } else { setTimeout(function() { $(_th.data('expand')).hide(); }, 250); } } $("i", this).toggleClass("icon-chevrons-right icon-chevrons-down"); }); JS; Admin::script($script); } }