Completed
Push — master ( 135efe...6a79a8 )
by Antonio
03:22
created

LoadingBehavior::registerClientScript()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 15
ccs 0
cts 10
cp 0
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 8
nc 1
nop 0
crap 2
1
<?php
2
3
/*
4
 * This file is part of the 2amigos/yii2-grid-view-library project.
5
 * (c) 2amigOS! <http://2amigos.us/>
6
 * For the full copyright and license information, please view
7
 * the LICENSE file that was distributed with this source code.
8
 */
9
10
namespace dosamigos\grid\behaviors;
11
12
use dosamigos\grid\bundles\LoadingAsset;
13
use dosamigos\grid\contracts\RegistersClientScriptInterface;
14
use yii\base\Behavior;
15
use yii\grid\GridView;
16
17
class LoadingBehavior extends Behavior implements RegistersClientScriptInterface
18
{
19
    /**
20
     * @var string the type of loading gif to display. Currently supports 'bars', 'reload' and 'spinner'. Defaults to
21
     * 'spinner'.
22
     */
23
    public $type = 'spinner';
24
25
    /**
26
     * @inheritdoc
27
     */
28
    public function registerClientScript()
29
    {
30
        /** @var GridView $owner */
31
        $owner = $this->owner;
32
33
        $view = $owner->getView();
34
35
        LoadingAsset::register($view);
36
37
        $id = $owner->getId();
38
        $type = $this->type;
39
        $hash = hash('crc32', $id.$type);
40
41
        $view->registerJs(";dosamigos.loadingGrid.registerHandler('#$id', '$type', '$hash');");
42
    }
43
}
44