Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit86cc8ad

Browse files
committed
Updates
- Reverted `isJavascriptFunction` check.- Added docblocks.- Did some refactoring.
1 parentf1d63cf commit86cc8ad

File tree

2 files changed

+46
-37
lines changed

2 files changed

+46
-37
lines changed

‎src/Html/Builder.php‎

Lines changed: 43 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,11 @@ public function __construct(Repository $config, Factory $view, HtmlBuilder $html
7676
$this->tableAttributes =$this->config->get('datatables-html.table', []);
7777
}
7878

79+
/**
80+
* Sets the smart datatable class name.
81+
*
82+
* @var this
83+
*/
7984
publicfunctionsetSmartDataTable($className)
8085
{
8186
$this->smartDataTable =$className;
@@ -112,12 +117,38 @@ public function generateScripts()
112117
);
113118
}
114119

120+
/**
121+
* Get the "url" from the ajax attribute.
122+
*
123+
* @return string
124+
*/
115125
publicfunctiongetAjaxUrl()
116126
{
117127
returnis_array($this->ajax) ?$this->ajax['url'] :$this->ajax;
118128
}
119129

120-
publicfunctiongetQueryString()
130+
/**
131+
* Set the "url" of the ajax attribute.
132+
*
133+
* @return this
134+
*/
135+
publicfunctionsetAjaxUrl($url)
136+
{
137+
if (is_array($this->ajax)) {
138+
$this->ajax['url'] =$url;
139+
}else {
140+
$this->ajax =$url;
141+
}
142+
143+
return$this;
144+
}
145+
146+
/**
147+
* Prepares the query string to use on ajax.
148+
*
149+
* @return string
150+
*/
151+
publicfunctionprepareQueryString()
121152
{
122153
if ($this->hasCustomTableId()) {
123154
$separator =str_contains($this->getAjaxUrl(),'?') ?'&' :'?';
@@ -136,17 +167,16 @@ public function getQueryString()
136167
return'';
137168
}
138169

139-
publicfunctionbuildAjax()
170+
/**
171+
* Builds the ajax url with the required query string parameters.
172+
*
173+
* @return void
174+
*/
175+
publicfunctionprepareAjax()
140176
{
141-
$queryString =$this->getQueryString();
142-
143-
if (is_array($this->ajax)) {
144-
$this->ajax['url'] =$this->ajax['url'].$queryString;
145-
}else {
146-
$this->ajax =$this->ajax.$queryString;
147-
}
177+
$queryString =$this->prepareQueryString();
148178

149-
return$this->ajax;
179+
$this->setAjaxUrl($queryString);
150180
}
151181

152182
/**
@@ -156,8 +186,6 @@ public function buildAjax()
156186
*/
157187
publicfunctiongenerateJson()
158188
{
159-
$this->buildAjax();
160-
161189
$args =array_merge(
162190
$this->attributes, [
163191
'ajax' =>$this->ajax,
@@ -186,9 +214,8 @@ public function parameterize($attributes = [])
186214
$values = [];
187215
$replacements = [];
188216

189-
190217
foreach (array_dot($parameters)as$key =>$value) {
191-
if ($this->isCallbackFunction($value,$key) ||$this->isJavascriptFunction($value,$key)) {
218+
if ($this->isCallbackFunction($value,$key)) {
192219
$values[] =trim($value);
193220
array_set($parameters,$key,'%' .$key .'%');
194221
$replacements[] ='"%' .$key .'%"';
@@ -218,18 +245,6 @@ protected function isCallbackFunction($value, $key)
218245
return Str::startsWith(trim($value),'function') || Str::contains($key,'editor');
219246
}
220247

221-
/**
222-
* Check if given key & value is a valid callback js function.
223-
*
224-
* @param string $value
225-
* @param string $key
226-
* @return bool
227-
*/
228-
protectedfunctionisJavascriptFunction($value,$key)
229-
{
230-
return Str::startsWith(trim($value), ['$','$.','function']);
231-
}
232-
233248
/**
234249
* Get javascript template to use.
235250
*
@@ -587,6 +602,8 @@ public function ajax($attributes = '')
587602
{
588603
$this->ajax =$attributes;
589604

605+
$this->prepareAjax();
606+
590607
return$this;
591608
}
592609

‎src/Middleware/SmartDataTables.php‎

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,10 @@ public function handle($request, Closure $next)
2020
return$next($request);
2121
}
2222

23-
$dataTable =app($request->smartDataTable);
23+
$dataTable =app($request->get('smartDataTable'));
2424

25-
if ($request->ajax() &&$request->wantsJson()) {
26-
returnapp()->call([$dataTable,'ajax']);
27-
}
28-
29-
if ($action =$dataTable->request()->get('action')andin_array($action,$dataTable->getActions())) {
30-
if ($action =='print') {
31-
returnapp()->call([$dataTable,'printPreview']);
32-
}
33-
34-
returnapp()->call([$dataTable,$action]);
25+
if ($response =$dataTable->render()) {
26+
return$response;
3527
}
3628

3729
return$next($request);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp