|
|
@@ -2,10 +2,9 @@
|
|
|
|
|
|
namespace Dcat\Admin\Grid\Displayers;
|
|
|
|
|
|
-use Dcat\Admin\Admin;
|
|
|
+use Dcat\Admin\Widgets\Modal as WidgetModal;
|
|
|
use Dcat\Admin\Support\Helper;
|
|
|
use Dcat\Admin\Support\LazyRenderable;
|
|
|
-use Illuminate\Support\Str;
|
|
|
|
|
|
class Modal extends AbstractDisplayer
|
|
|
{
|
|
|
@@ -16,45 +15,9 @@ class Modal extends AbstractDisplayer
|
|
|
$this->title = $title;
|
|
|
}
|
|
|
|
|
|
- protected function generateElementId()
|
|
|
+ protected function setUpLazyRenderable(LazyRenderable $renderable)
|
|
|
{
|
|
|
- $key = Str::random(8);
|
|
|
-
|
|
|
- return 'grid-modal-'.$this->grid->getName().$key;
|
|
|
- }
|
|
|
-
|
|
|
- protected function addRenderableScript(string $modalId, string $url)
|
|
|
- {
|
|
|
- $script = <<<JS
|
|
|
-(function () {
|
|
|
- var modal = $('#{$modalId}');
|
|
|
-
|
|
|
- modal.on('show.bs.modal', function (e) {
|
|
|
- modal.find('.modal-body').html('<div style="min-height:150px"></div>');
|
|
|
-
|
|
|
- modal.find('.modal-body').loading();
|
|
|
-
|
|
|
- $.ajax('{$url}').then(function (data) {
|
|
|
- var html = Dcat.assets.executeScripts(data, function () {
|
|
|
- Dcat.triggerReady();
|
|
|
- }).render();
|
|
|
-
|
|
|
- modal.find('.modal-body').html(html);
|
|
|
- });
|
|
|
- })
|
|
|
-})();
|
|
|
-JS;
|
|
|
-
|
|
|
- Admin::script($script);
|
|
|
- }
|
|
|
-
|
|
|
- protected function setUpLazyRenderable(string $modalId, LazyRenderable $renderable)
|
|
|
- {
|
|
|
- $renderable->with('key', $this->getKey());
|
|
|
-
|
|
|
- $this->addRenderableScript($modalId, $renderable->getUrl());
|
|
|
-
|
|
|
- $renderable::collectAssets();
|
|
|
+ return $renderable->with('key', $this->getKey());
|
|
|
}
|
|
|
|
|
|
public function display($callback = null)
|
|
|
@@ -65,7 +28,6 @@ JS;
|
|
|
}
|
|
|
|
|
|
$html = $this->value;
|
|
|
- $id = $this->generateElementId();
|
|
|
|
|
|
if ($callback instanceof \Closure) {
|
|
|
$callback = $callback->call($this->row, $this);
|
|
|
@@ -77,37 +39,24 @@ JS;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- if (is_string($callback) && is_subclass_of($callback, LazyRenderable::class)) {
|
|
|
- $html = '';
|
|
|
-
|
|
|
- $this->setUpLazyRenderable($id, $callback::make());
|
|
|
- } elseif ($callback instanceof LazyRenderable) {
|
|
|
- $html = '';
|
|
|
+ if ($callback && is_string($callback) && is_subclass_of($callback, LazyRenderable::class)) {
|
|
|
+ $html = $this->setUpLazyRenderable($callback::make());
|
|
|
|
|
|
- $this->setUpLazyRenderable($id, $callback);
|
|
|
+ } elseif ($callback && $callback instanceof LazyRenderable) {
|
|
|
+ $html = $this->setUpLazyRenderable($callback);
|
|
|
}
|
|
|
|
|
|
$title = $this->title ?: $title;
|
|
|
|
|
|
- return <<<EOT
|
|
|
-<span class="grid-expand" data-toggle="modal" data-target="#{$id}">
|
|
|
- <a href="javascript:void(0)"><i class="fa fa-clone"></i> {$this->value}</a>
|
|
|
-</span>
|
|
|
-
|
|
|
-<div class="modal fade" id="{$id}" role="dialog">
|
|
|
- <div class="modal-dialog modal-lg">
|
|
|
- <div class="modal-content">
|
|
|
- <div class="modal-header">
|
|
|
- <h4 class="modal-title">{$title}</h4>
|
|
|
- <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
|
|
|
- </div>
|
|
|
- <div class="modal-body">
|
|
|
- {$html}
|
|
|
- </div>
|
|
|
- </div>
|
|
|
- </div>
|
|
|
-</div>
|
|
|
+ return WidgetModal::make()
|
|
|
+ ->lg()
|
|
|
+ ->title($title)
|
|
|
+ ->body($html)
|
|
|
+ ->button($this->renderButton());
|
|
|
+ }
|
|
|
|
|
|
-EOT;
|
|
|
+ protected function renderButton()
|
|
|
+ {
|
|
|
+ return "<a href=\"javascript:void(0)\"><i class=\"fa fa-clone\"></i> {$this->value}</a>";
|
|
|
}
|
|
|
}
|