forked from kartik-v/yii2-dynagrid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathModule.php
212 lines (189 loc) · 7.15 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
207
208
209
210
211
212
<?php
/**
* @package yii2-dynagrid
* @author Kartik Visweswaran <kartikv2@gmail.com>
* @copyright Copyright © Kartik Visweswaran, Krajee.com, 2015
* @version 1.4.5
*/
namespace kartik\dynagrid;
use Yii;
use kartik\base\Config;
use kartik\grid\GridView;
use yii\helpers\ArrayHelper;
/**
* The dynamic grid module for Yii Framework 2.0.
*
* @author Kartik Visweswaran <kartikv2@gmail.com>
* @since 1.0
*/
class Module extends \kartik\base\Module
{
const MODULE = 'dynagrid';
const LAYOUT_1 = "<hr>{dynagrid}<hr>\n{summary}\n{items}\n{pager}";
const LAYOUT_2 = " ";
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
*/
public $settingsConfigAction = '/dynagrid/settings/get-config';
/**
* @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 int the default theme for the gridview. Defaults to 'panel-primary'.
*/
public $defaultTheme = 'panel-primary';
/**
* @var int the default pagesize for the gridview. Defaults to 10.
*/
public $defaultPageSize = 10;
/**
* @var int the minimum pagesize for the gridview. Defaults to 0.
* Setting pagesize to 0 will display all rows.
*/
public $minPageSize = 0;
/**
* @var int the maximum pagesize for the gridview. Defaults to 50.
*/
public $maxPageSize = 50;
/**
* @var mixed the action (url) used for creating a filter or sort setting
*/
public $createAction = '/dynagrid/settings/create';
/**
* @var mixed the action (url) used for creating a filter or sort setting
*/
public $updateAction = '/dynagrid/settings/update';
/**
* @var mixed the action (url) used for deleting a filter or sort setting
*/
public $deleteAction = '/dynagrid/settings/delete';
/**
* @inheritdoc
*/
public function init()
{
$this->_msgCat = 'kvdynagrid';
parent::init();
$this->initSettings();
}
/**
* Gets the module
*
* @param string $module the module name
*
* @return Module
*/
public static function fetchModule($module = self::MODULE)
{
return Config::getModule($module);
}
/**
* Initialize module level settings
*
* @return void
*/
public function initSettings()
{
$this->dbSettings += [
'tableName' => 'tbl_dynagrid',
'idAttr' => 'id',
'filterAttr' => 'filter_id',
'sortAttr' => 'sort_id',
'dataAttr' => 'data'
];
$this->dbSettingsDtl += [
'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);
}
}