Completed
Push — master ( 3ba3ea...845ba8 )
by Dmitry
08:38
created

GridView   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 113
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 4
c 0
b 0
f 0
lcom 1
cbo 5
dl 0
loc 113
ccs 0
cts 62
cp 0
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
B columns() 0 25 1
A run() 0 6 1
A detailView() 0 5 1
B registerClientScript() 0 35 1
1
<?php
2
/**
3
 * HiPanel core package.
4
 *
5
 * @link      https://hipanel.com/
6
 * @package   hipanel-core
7
 * @license   BSD-3-Clause
8
 * @copyright Copyright (c) 2014-2017, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hipanel\grid;
12
13
use hipanel\helpers\ArrayHelper;
14
use hipanel\modules\client\grid\ClientColumn;
15
use hipanel\modules\client\grid\SellerColumn;
16
use hipanel\widgets\LinkSorter;
17
use hiqdev\assets\datatables\DataTablesAsset;
18
use hiqdev\assets\icheck\iCheckAsset;
19
use Yii;
20
21
/**
22
 * Class GridView.
23
 * HiPanel specific GridView.
24
 */
25
class GridView extends \hiqdev\higrid\GridView
26
{
27
    public $sorter = [
28
        'class' => LinkSorter::class,
29
    ];
30
31
    /**
32
     * {@inheritdoc}
33
     */
34
    public $resizableColumns = [
35
        'resizeFromBody' => false,
36
    ];
37
38
    /**
39
     * {@inheritdoc}
40
     */
41
    public $options = [
42
        'class' => 'dataTables_wrapper form-inline',
43
        'role' => 'grid',
44
    ];
45
46
    /**
47
     * {@inheritdoc}
48
     */
49
    public $layout = "<div class='row'><div class='col-xs-12'>{sorter}</div></div><div class=\"table-responsive\">{items}</div>\n<div class='row'><div class='col-sm-6 col-xs-12'><div class='dataTables_info'>{summary}</div></div>\n<div class='col-sm-6 col-xs-12'><div class='dataTables_paginate paging_bootstrap'>{pager}</div></div></div>";
50
51
    /**
52
     * {@inheritdoc}
53
     */
54
    public function columns()
55
    {
56
        return array_merge(parent::columns(), [
0 ignored issues
show
Bug introduced by
The method columns() does not exist on hiqdev\higrid\GridView. Did you maybe mean column()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
57
            'seller_id' => [
58
                'class' => SellerColumn::class,
59
            ],
60
            'client_id' => [
61
                'class' => ClientColumn::class,
62
            ],
63
            'checkbox' => [
64
                'class' => CheckboxColumn::class,
65
            ],
66
            'seller' => [
67
                'class' => SellerColumn::class,
68
                'attribute' => 'seller_id',
69
            ],
70
            'client' => [
71
                'class' => ClientColumn::class,
72
                'attribute' => 'client_id',
73
            ],
74
            'client_like' => [
75
                'class' => ClientColumn::class,
76
            ],
77
        ]);
78
    }
79
80
    /**
81
     * {@inheritdoc}
82
     */
83
    public function run()
84
    {
85
        $this->tableOptions['class'] .= ' ' . Yii::$app->themeManager->settings->getCssClass('table_condensed');
86
        parent::run();
87
        $this->registerClientScript();
88
    }
89
90
    /**
91
     * {@inheritdoc}
92
     */
93
    public static function detailView(array $config = [])
94
    {
95
        $config = ArrayHelper::merge(['gridOptions' => ['resizableColumns' => ['resizeFromBody' => true]]], $config);
96
        return parent::detailView($config);
97
    }
98
99
    /**
100
     * {@inheritdoc}
101
     */
102
    private function registerClientScript()
103
    {
104
        $view = $this->getView();
105
        DataTablesAsset::register($view);
106
        iCheckAsset::register($view);
107
        $view->registerJs(<<<'JS'
108
$(function () {
109
    var checkAll = $('input.select-on-check-all');
110
    var checkboxes = $('input.icheck');
111
112
    $('input.icheck, input.select-on-check-all ').iCheck({
113
        checkboxClass: 'icheckbox_minimal-blue',
114
        radioClass: 'iradio_minimal-blue'
115
    });
116
117
    checkAll.on('ifChecked ifUnchecked', function(event) {
118
        if (event.type == 'ifChecked') {
119
            checkboxes.iCheck('check');
120
        } else {
121
            checkboxes.iCheck('uncheck');
122
        }
123
    });
124
125
    checkboxes.on('ifChanged', function(event){
126
        if (checkboxes.filter(':checked').length == checkboxes.length) {
127
            checkAll.prop('checked', true);
128
        } else {
129
            checkAll.prop('checked', false);
130
        }
131
        checkAll.iCheck('update');
132
    });
133
});
134
JS
135
            , \yii\web\View::POS_READY);
136
    }
137
}
138