Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
z-song committed Jun 15, 2020
1 parent 8f0aefe commit 6f5bb38
Show file tree
Hide file tree
Showing 5 changed files with 112 additions and 93 deletions.
59 changes: 59 additions & 0 deletions resources/views/components/column-modal.blade.php
@@ -0,0 +1,59 @@
<span data-toggle="modal" data-target="#grid-modal-{{ $name }}" data-key="{{ $key }}">
<a href="javascript:void(0)"><i class="fa fa-clone"></i>&nbsp;&nbsp;{{ $value }}</a>
</span>

<div class="modal grid-modal fade" id="grid-modal-{{ $name }}" tabindex="-1" role="dialog">
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content" style="border-radius: 5px;">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<h4 class="modal-title">{{ $title }}</h4>
</div>
<div class="modal-body">
{{ $html }}
</div>
</div>
</div>
</div>

@if($grid)
<style>
.box.grid-box {
box-shadow: none;
border-top: none;
}
.grid-box .box-header:first-child {
display: none;
}
</style>
@endif

@if($async)
<script>
var modal = $('.grid-modal');
var modalBody = modal.find('.modal-body');
var load = function (url) {
modalBody.html("<div class='loading text-center' style='height:200px;'>\
<i class='fa fa-spinner fa-pulse fa-3x fa-fw' style='margin-top: 80px;'></i>\
</div>");
$.get(url, function (data) {
modalBody.html(data);
});
};
modal.on('show.bs.modal', function (e) {
var key = $(e.relatedTarget).data('key');
load('{{ $url }}'+'&key='+key);
}).on('click', '.page-item a, .filter-box a', function (e) {
load($(this).attr('href'));
e.preventDefault();
}).on('submit', '.box-header form', function (e) {
load($(this).attr('action')+'&'+$(this).serialize());
return false;
});
</script>
@endif
24 changes: 24 additions & 0 deletions src/Grid/Column.php
Expand Up @@ -588,6 +588,30 @@ public function replace(array $replacements)
});
}

/**
* @param string|Closure $input
* @param string $seperator
*
* @return $this
*/
public function repeat($input, $seperator = '')
{
if (is_string($input)) {
$input = function () use ($input) {
return $input;
};
}

if ($input instanceof Closure) {
return $this->display(function ($value) use ($input, $seperator) {
$callable = $input->bindTo($this);
return join($seperator, array_fill(0, (int) $value, $callable($value)));
});
}

return $this;
}

/**
* Render this column with the given view.
*
Expand Down
16 changes: 8 additions & 8 deletions src/Grid/Displayers/ContextMenuActions.php
Expand Up @@ -17,31 +17,31 @@ protected function addScript()
;(function () {
$("body").on("contextmenu", "table#{$this->grid->tableID} tr", function(e) {
$('#grid-context-menu .dropdown-menu').hide();
var menu = $(this).find('td.column-__actions__ .dropdown-menu');
var index = $(this).index();
if (menu.length) {
menu.attr('index', index).detach().appendTo('#grid-context-menu');
} else {
menu = $('#grid-context-menu .dropdown-menu[index='+index+']');
}
var height = 0;
if (menu.height() > (document.body.clientHeight - e.pageY)) {
menu.css({left: e.pageX+10, top: e.pageY - menu.height()}).show();
} else {
menu.css({left: e.pageX+10, top: e.pageY-10}).show();
}
return false;
});
$(document).on('click',function(){
$('#grid-context-menu .dropdown-menu').hide();
})
$('#grid-context-menu').click('a', function () {
$('#grid-context-menu .dropdown-menu').hide();
});
Expand All @@ -57,7 +57,7 @@ protected function addScript()
public function display($callback = null)
{
Admin::html('<div id="grid-context-menu"></div>');
Admin::style('.column-__actions__ {display: none !important;}');
Admin::style("#{$this->grid->tableID} .column-__actions__ {display: none !important;}");

return parent::display($callback);
}
Expand Down
102 changes: 19 additions & 83 deletions src/Grid/Displayers/Modal.php
Expand Up @@ -25,57 +25,11 @@ protected function getLoadUrl()
return route('admin.handle-renderable', compact('renderable'));
}

protected function addRenderableModalScript()
{
$script = <<<SCRIPT
;(function () {
var modal = $('.grid-modal');
var modalBody = modal.find('.modal-body');
var load = function (url) {
modalBody.html("<div class='loading text-center' style='height:200px;'>\
<i class='fa fa-spinner fa-pulse fa-3x fa-fw' style='margin-top: 80px;'></i>\
</div>");
$.get(url, function (data) {
modalBody.html(data);
});
};
modal.on('show.bs.modal', function (e) {
var key = $(e.relatedTarget).data('key');
load('{$this->getLoadUrl()}'+'&key='+key);
}).on('click', '.page-item a, .filter-box a', function (e) {
load($(this).attr('href'));
e.preventDefault();
}).on('submit', '.box-header form', function (e) {
load($(this).attr('action')+'&'+$(this).serialize());
return false;
});
})();
SCRIPT;

Admin::script($script);
}

protected function addGridStyle()
{
$style = <<<STYLE
.box.grid-box {
box-shadow: none;
border-top: none;
}
.grid-box .box-header:first-child {
display: none;
}
STYLE;

Admin::style($style);
}

/**
* @param \Closure|string $callback
*
* @return mixed|string
*/
public function display($callback = null)
{
if (func_num_args() == 2) {
Expand All @@ -84,41 +38,23 @@ public function display($callback = null)
$title = $this->trans('title');
}

if (is_subclass_of($callback, Renderable::class)) {
$html = '';
$this->renderable = $callback;
$this->addRenderableModalScript();

if (is_subclass_of($callback, Simple::class)) {
$this->addGridStyle();
}
$html = '';

if ($async = is_subclass_of($callback, Renderable::class)) {
$this->renderable = $callback;
} else {
$callback = $callback->bindTo($this->row);
$html = call_user_func_array($callback, [$this->row]);
$html = call_user_func_array($callback->bindTo($this->row), [$this->row]);
}

$key = $this->getKey().'-'.str_replace('.', '_', $this->getColumn()->getName());

return <<<EOT
<span data-toggle="modal" data-target="#grid-modal-{$key}" data-key="{$this->getKey()}">
<a href="javascript:void(0)"><i class="fa fa-clone"></i>&nbsp;&nbsp;{$this->value}</a>
</span>
<div class="modal grid-modal fade" id="grid-modal-{$key}" tabindex="-1" role="dialog">
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content" style="border-radius: 5px;">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<h4 class="modal-title">{$title}</h4>
</div>
<div class="modal-body">
{$html}
</div>
</div>
</div>
</div>
EOT;
return Admin::component('admin::components.column-modal', [
'url' => $this->getLoadUrl(),
'async' => $async,
'grid' => is_subclass_of($callback, Simple::class),
'title' => $title,
'html' => $html,
'key' => $this->getKey(),
'value' => $this->value,
'name' => $this->getKey() . '-' . str_replace('.', '_', $this->getColumn()->getName()),
]);
}
}
4 changes: 2 additions & 2 deletions src/Grid/Selectable.php
Expand Up @@ -81,7 +81,7 @@ public function render()
$this->appendRemoveBtn(true);
}

$this->paginate($this->perPage)->expandFilter()->disableFeatures();
$this->disableFeatures()->paginate($this->perPage)->expandFilter();

$displayer = $this->multiple ? Checkbox::class : Radio::class;

Expand Down Expand Up @@ -111,7 +111,7 @@ public function renderFormGrid($values)

$this->model()->whereKey(Arr::wrap($values));

$this->disableFilter()->disableFeatures();
$this->disableFeatures()->disableFilter();

if (!$this->multiple) {
$this->disablePagination();
Expand Down

0 comments on commit 6f5bb38

Please sign in to comment.