Completed
Push — master ( 6de3cf...c386e0 )
by Song
03:18
created

Fieldset::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Encore\Admin\Form\Field;
4
5
use Encore\Admin\Admin;
6
7
class Fieldset
8
{
9
    protected $name = '';
10
11
    public function __construct()
12
    {
13
        $this->name = uniqid('fieldset-');
14
    }
15
16
    public function start($title)
17
    {
18
        $script = <<<SCRIPT
19
$('.{$this->name}-title').click(function () {
20
    $("i", this).toggleClass("fa-angle-double-down fa-angle-double-up");
21
});
22
SCRIPT;
23
24
        Admin::script($script);
25
26
        return <<<HTML
27
<div>
28
    <div style="height: 20px; border-bottom: 1px solid #eee; text-align: center;margin-top: 20px;margin-bottom: 20px;">
29
      <span style="font-size: 16px; background-color: #ffffff; padding: 0 10px;">
30
        <a data-toggle="collapse" href="#{$this->name}" class="{$this->name}-title">
31
          <i class="fa fa-angle-double-up"></i>&nbsp;&nbsp;{$title}
32
        </a>
33
      </span>
34
    </div>
35
    <div class="collapse in" id="{$this->name}">
36
HTML;
37
    }
38
39
    public function end()
40
    {
41
        return '</div></div>';
42
    }
43
44
    public function collapsed()
45
    {
46
        $script = <<<SCRIPT
47
$("#{$this->name}").removeClass("in");
48
$(".{$this->name}-title i").toggleClass("fa-angle-double-down fa-angle-double-up");
49
SCRIPT;
50
51
        Admin::script($script);
52
53
        return $this;
54
    }
55
}