|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Encore\Admin\Grid\Displayers; |
|
4
|
|
|
|
|
5
|
|
|
use Encore\Admin\Admin; |
|
6
|
|
|
|
|
7
|
|
|
class Expand extends AbstractDisplayer |
|
8
|
|
|
{ |
|
9
|
|
|
public function display(\Closure $callback = null, $isExpand = false) |
|
10
|
|
|
{ |
|
11
|
|
|
$callback = $callback->bindTo($this->row); |
|
12
|
|
|
|
|
13
|
|
|
$html = call_user_func_array($callback, [$this->row]); |
|
14
|
|
|
|
|
15
|
|
|
$this->addScript($isExpand); |
|
16
|
|
|
|
|
17
|
|
|
$key = $this->column->getName().'-'.$this->getKey(); |
|
18
|
|
|
|
|
19
|
|
|
return <<<EOT |
|
20
|
|
|
<span class="{$this->getElementClass()}" data-inserted="0" data-key="{$key}" data-toggle="collapse" data-target="#grid-collapse-{$key}"> |
|
21
|
|
|
<a href="javascript:void(0)"><i class="fa fa-angle-double-down"></i> {$this->value}</a> |
|
22
|
|
|
</span> |
|
23
|
|
|
<template class="grid-expand-{$key}"> |
|
24
|
|
|
<div id="grid-collapse-{$key}" class="collapse"> |
|
25
|
|
|
<div style="padding: 10px 10px 0 10px;">$html</div> |
|
26
|
|
|
</div> |
|
27
|
|
|
</template> |
|
28
|
|
|
EOT; |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
protected function addScript($isExpand) |
|
32
|
|
|
{ |
|
33
|
|
|
$script = <<<EOT |
|
34
|
|
|
|
|
35
|
|
|
$('.{$this->getElementClass()}').on('click', function () { |
|
36
|
|
|
|
|
37
|
|
|
if ($(this).data('inserted') == '0') { |
|
38
|
|
|
|
|
39
|
|
|
var key = $(this).data('key'); |
|
40
|
|
|
var row = $(this).closest('tr'); |
|
41
|
|
|
var html = $('template.grid-expand-'+key).html(); |
|
42
|
|
|
|
|
43
|
|
|
row.after("<tr style='background-color: #ecf0f5;'><td colspan='"+(row.find('td').length)+"' style='padding:0 !important; border:0;'>"+html+"</td></tr>"); |
|
44
|
|
|
|
|
45
|
|
|
$(this).data('inserted', 1); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
$("i", this).toggleClass("fa-angle-double-down fa-angle-double-up"); |
|
49
|
|
|
}); |
|
50
|
|
|
EOT; |
|
51
|
|
|
|
|
52
|
|
|
if($isExpand) { |
|
53
|
|
|
$script .= "$('.{$this->getElementClass()}').trigger('click');"; |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
Admin::script($script); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* @return string |
|
61
|
|
|
*/ |
|
62
|
|
|
protected function getElementClass() |
|
63
|
|
|
{ |
|
64
|
|
|
return "grid-expand-{$this->grid->getGridRowName()}"; |
|
65
|
|
|
} |
|
66
|
|
|
} |
|
67
|
|
|
|