-
Notifications
You must be signed in to change notification settings - Fork 5
/
EasyuiAsset.php
151 lines (131 loc) · 4.13 KB
/
EasyuiAsset.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
<?php
/**
* Created by PhpStorm.
* User: sansusan
* Date: 12.03.2015
* Time: 13:26
*/
namespace sansusan\easyui;
use Yii;
use yii\web\AssetBundle;
use yii\web\View;
class EasyuiAsset extends AssetBundle
{
public $sourcePath = '@sansusan/easyui/assets/jquery-easyui-1.4.4';
public $css = [
'themes/icon.css',
'themes/color.css'
];
public $js = [
'jquery.easyui.min.js',
];
public $depends = [
// 'yii\web\YiiAsset',
'yii\web\JqueryAsset',
];
/**
* @var string
*/
public static $theme = 'default';
/**
* @var string
*/
public static $locale = 'easyui-lang-ru';
/**
* @var array
*/
public static $extensions = [];
/**
* @inheritdoc
*/
public function init()
{
$this->applyTheme();
$this->applyLocale();
$this->applyExtensions();
parent::init();
}
protected function applyTheme()
{
if (!empty(self::$theme) && is_string(self::$theme))
$theme = self::$theme;
else
$theme = 'default';
array_unshift($this->css, strtr('themes/{theme}/easyui.css', ['{theme}' => $theme]));
}
protected function applyLocale()
{
if (!empty(self::$locale) && is_string(self::$locale))
$locale = self::$locale;
else
$locale = 'easyui-lang-ru';
array_push($this->js, strtr('locale/{locale}.js', ['{locale}' => $locale]));
}
protected function applyExtensions()
{
foreach (self::$extensions as $ex) {
if (is_string($ex)) {
$folder = '';
switch (trim($ex)) {
case 'datagrid-bufferview':
case 'datagrid-defaultview':
case 'datagrid-detailview':
case 'datagrid-scrollview':
case 'datagrid-groupview':
$folder = 'jquery-easyui-datagridview';
break;
case 'datagrid-dnd':
case 'datagrid-filter':
case 'treegrid-dnd':
$folder = $ex;
break;
case 'dwrloader':
$folder = 'jquery-easyui-dwrloader';
break;
case 'jquery.edatagrid':
$folder = 'jquery-easyui-edatagrid';
break;
case 'jquery.etree':
case 'jquery.etree.lang':
$folder = 'jquery-easyui-etree';
break;
case 'jquery.pivotgrid':
$folder = 'jquery-easyui-pivotgrid';
break;
case 'jquery.portal':
$folder = 'jquery-easyui-portal';
break;
case 'jquery.ribbon':
$folder = 'jquery-easyui-ribbon';
break;
case 'easyui-rtl':
$folder = 'jquery-easyui-rtl';
break;
case 'columns-ext':
$folder = 'columns-ext';
break;
case 'datagrid-cellediting':
$folder = 'datagrid-celleditingt';
break;
}
if (!empty($folder))
array_push($this->js, strtr('extensions/{folder}/{ex}.js', ['{folder}' => $folder, '{ex}' => $ex]));
}
}
}
/**
* @param \yii\web\View $view
* @param array $options
* @param array $extensions
* @return static
*/
public static function register($view, $options = [], $extensions = [])
{
if (is_array($options)) {
if (array_key_exists('theme', $options)) self::$theme = $options['theme'];
if (array_key_exists('locale', $options)) self::$locale = $options['locale'];
}
if (is_array($extensions) && !empty($extensions)) self::$extensions = $extensions;
return parent::register($view);
}
}