ResizableColumnsBehavior   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 5
dl 0
loc 52
ccs 0
cts 11
cp 0
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A registerClientScript() 0 16 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\ResizableColumnsBundle;
13
use dosamigos\grid\contracts\RegistersClientScriptInterface;
14
use yii\base\Behavior;
15
use yii\grid\GridView;
16
use yii\helpers\Json;
17
18
class ResizableColumnsBehavior extends Behavior implements RegistersClientScriptInterface
19
{
20
    /**
21
     * @var array $clientOptions the options for the underlying resizable jquery plugin. Sets by default the store
22
     * option. These are the options available and its defaults (translated from its js code):
23
     *
24
     * ```
25
     * [
26
     *  'selector' => new JsExpression('function selector($table) {... see js code ...}'),
27
     *  'store' => new JsExpression('window.store'),
28
     *  'syncHandlers' => true,
29
     *  'resizeFromBody' => true,
30
     *  'maxWidth' => new JsExpression('null'),
31
     *  'minWidth' => 0.01
32
     * ]
33
     * ```
34
     *
35
     * It also has the options for you to configure the callback functions when triggering events. The events are:
36
     *
37
     * - start: When plugin starts resizing
38
     * - resize: When plugin is resizing
39
     * - stop: When plugin ends resizing
40
     *
41
     * To configure do:
42
     *
43
     * ```
44
     * [
45
     *  'start' => new JsExpression('function(){ console.log("resizing...");}')
46
     * ]
47
     */
48
    public $clientOptions = [];
49
50
    /**
51
     * @inheritdoc
52
     */
53
    public function registerClientScript()
54
    {
55
        /** @var GridView $owner */
56
        $owner = $this->owner;
57
58
        $id = $owner->getId();
59
        $view = $owner->getView();
60
61
        ResizableColumnsBundle::register($view);
62
63
        $options = !empty($this->clientOptions)
64
            ? Json::encode($this->clientOptions)
65
            : '';
66
67
        $view->registerJs(";jQuery('#$id > table.da-grid-view-table').resizableColumns($options);");
68
    }
69
}
70