forked from kartik-v/yii2-dynagrid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Module.php
206 lines (186 loc) · 7.07 KB
/
Module.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
<?php
/**
* @package yii2-dynagrid
* @author Kartik Visweswaran <[email protected]>
* @copyright Copyright © Kartik Visweswaran, Krajee.com, 2015 - 2018
* @version 1.4.8
*/
namespace kartik\dynagrid;
use kartik\grid\GridView;
use Yii;
use yii\helpers\ArrayHelper;
/**
* The dynamic grid module for Yii Framework 2.0.
*
* @author Kartik Visweswaran <[email protected]>
* @since 1.0
*/
class Module extends \kartik\base\Module
{
/**
* Dynagrid module name
*/
const MODULE = 'dynagrid';
/**
* Dynagrid layout type 1
*/
const LAYOUT_1 = "<hr>{dynagrid}<hr>\n{summary}\n{items}\n{pager}";
/**
* Dynagrid layout type 2
*/
const LAYOUT_2 = " ";
/**
* Cookie expiry (used for dynagrid configuration storage)
*/
const COOKIE_EXPIRY = 8640000; // 100 days
/**
* @var array the settings for the cookie to be used in saving the dynagrid setup
* @see \yii\web\Cookie
*/
public $cookieSettings = [];
/**
* @var array the settings for the database table to store the dynagrid setup
* The following parameters are supported:
* - tableName: _string_, the name of the database table, that will store the dynagrid settings.
* Defaults to `tbl_dynagrid`.
* - idAttr: _string_, the attribute name for the configuration id . Defaults to `id`.
* - filterAttr: _string_, the attribute name for the filter setting id. Defaults to `filter_id`.
* - sortAttr: _string_, the attribute name for the filter setting id. Defaults to `sort_id`.
* - dataAttr: _string_, the attribute name for grid column data configuration. Defaults to `data`.
*/
public $dbSettings = [];
/**
* @var array the settings for the detail database table to store the dynagrid filter and sort settings.
* The following parameters are supported:
* - tableName: _string_, the name of the database table, that will store the dynagrid settings.
* Defaults to `tbl_dynagrid_dtl`.
* - idAttr: _string_, the attribute name for the detail configuration id. Defaults to `id`.
* - categoryAttr: _string_, the attribute name for the detail category (values currently possible are 'filter' or
* 'sort'). Defaults to `category`.
* - nameAttr: _string_, the attribute name for the filter or sort name. Defaults to `name`.
* - dataAttr: _string_, the attribute name for grid detail (filter/sort) configuration. Defaults to `data`.
* - dynaGridIdAttr: _string_, the attribute name for the dynagrid identifier. Defaults to `dynagrid_id`.
*/
public $dbSettingsDtl = [];
/**
* @var array the default global configuration for the kartik\dynagrid\DynaGrid widget
*/
public $dynaGridOptions = [];
/**
* @var string the view for displaying and saving the dynagrid configuration
*/
public $configView = 'config';
/**
* @var string the view for displaying and saving the dynagrid detail settings
* for filter and sort
*/
public $settingsView = 'settings';
/**
* @var mixed the action URL for displaying the dynagrid detail configuration settings on the dynagrid detail
* settings form. If this is not set it will default to `<moduleId>/settings/get-config`, where `<moduleId>` is
* the module identifier for the dynagrid module.
*/
public $settingsConfigAction;
/**
* @var array the theme configuration for the gridview
*/
public $themeConfig = [
'simple-default' => [
'panel' => false,
'bordered' => false,
'striped' => false,
'hover' => true,
'layout' => self::LAYOUT_1,
],
'simple-bordered' => ['panel' => false, 'striped' => false, 'hover' => true, 'layout' => self::LAYOUT_1],
'simple-condensed' => [
'panel' => false,
'striped' => false,
'condensed' => true,
'hover' => true,
'layout' => self::LAYOUT_1,
],
'simple-striped' => ['panel' => false, 'layout' => self::LAYOUT_1],
'panel-default' => ['panel' => ['type' => GridView::TYPE_DEFAULT, 'before' => self::LAYOUT_2]],
'panel-primary' => ['panel' => ['type' => GridView::TYPE_PRIMARY, 'before' => self::LAYOUT_2]],
'panel-info' => ['panel' => ['type' => GridView::TYPE_INFO, 'before' => self::LAYOUT_2]],
'panel-danger' => ['panel' => ['type' => GridView::TYPE_DANGER, 'before' => self::LAYOUT_2]],
'panel-success' => ['panel' => ['type' => GridView::TYPE_SUCCESS, 'before' => self::LAYOUT_2]],
'panel-warning' => ['panel' => ['type' => GridView::TYPE_WARNING, 'before' => self::LAYOUT_2]],
];
/**
* @var integer the default theme for the gridview.
*/
public $defaultTheme = 'panel-primary';
/**
* @var integer the default pagesize for the gridview.
*/
public $defaultPageSize = 10;
/**
* @var integer the minimum pagesize for the gridview. Setting pagesize to `0` will display all rows.
*/
public $minPageSize = 0;
/**
* @var integer the maximum pagesize for the gridview.
*/
public $maxPageSize = 50;
/**
* @var string a random salt that will be used to generate a hash signature for tree configuration.
*/
public $configEncryptSalt = 'SET_A_SALT_FOR_YII2_DYNAGRID';
/**
* @inheritdoc
*/
protected $_msgCat = 'kvdynagrid';
/**
* @inheritdoc
*/
public function init()
{
parent::init();
$this->initSettings();
}
/**
* Initialize module level settings
*/
public function initSettings()
{
$this->dbSettings += [
'connection' => 'db',
'tableName' => 'tbl_dynagrid',
'idAttr' => 'id',
'filterAttr' => 'filter_id',
'sortAttr' => 'sort_id',
'dataAttr' => 'data',
];
$this->dbSettingsDtl += [
'connection' => 'db',
'tableName' => 'tbl_dynagrid_dtl',
'idAttr' => 'id',
'categoryAttr' => 'category',
'nameAttr' => 'name',
'dataAttr' => 'data',
'dynaGridIdAttr' => 'dynagrid_id',
];
$this->cookieSettings += [
'httpOnly' => true,
'expire' => time() + self::COOKIE_EXPIRY,
];
$this->dynaGridOptions = ArrayHelper::merge(
[
'storage' => DynaGrid::TYPE_SESSION,
'gridOptions' => [],
'matchPanelStyle' => true,
'toggleButtonGrid' => [],
'options' => [],
'sortableOptions' => [],
'userSpecific' => true,
'columns' => [],
'submitMessage' => Yii::t('kvdynagrid', 'Saving and applying configuration') . ' …',
'deleteMessage' => Yii::t('kvdynagrid', 'Trashing all personalizations') . ' …',
'deleteConfirmation' => Yii::t('kvdynagrid', 'Are you sure you want to delete the setting?'),
'messageOptions' => [],
], $this->dynaGridOptions
);
}
}