Completed
Push — master ( 7a7fba...3207da )
by Song
14:14
created

Expand::display()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 21

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 21
rs 9.584
c 0
b 0
f 0
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($callback = null)
10
    {
11
        $callback = $callback->bindTo($this->row);
12
13
        $html = call_user_func_array($callback, [$this->row]);
14
15
        $this->setupScript();
16
17
        $key = $this->getKey();
18
19
        return <<<EOT
20
<span class="grid-expand" 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>&nbsp;&nbsp;{$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 setupScript()
32
    {
33
        $script = <<<EOT
34
35
$('.grid-expand').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
        Admin::script($script);
52
    }
53
}