-
Notifications
You must be signed in to change notification settings - Fork 106
/
JsReload.php
68 lines (58 loc) · 1.77 KB
/
JsReload.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
<?php
declare(strict_types=1);
namespace Atk4\Ui;
/**
* This class generates action, that will be able to loop-back to the callback method.
*/
class JsReload implements JsExpressionable
{
/**
* Specifies which view to reload. Use constructor to set.
*
* @var View
*/
public $view;
/**
* A Js function to execute after reload is complete and onSuccess is execute.
*
* @var JsExpression
*/
public $afterSuccess;
/**
* If defined, they will be added at the end of your URL.
* Value in ARG can be either string or JsExpressionable.
*
* @var array
*/
public $args = [];
/**
* Semantic-ui api settings.
* ex: ['loadingDuration' => 1000].
*
* @var array
*/
public $apiConfig = [];
public $includeStorage = false;
public function __construct($view, $args = [], $afterSuccess = null, $apiConfig = [], $includeStorage = false)
{
$this->view = $view;
$this->args = $args;
$this->afterSuccess = $afterSuccess;
$this->apiConfig = $apiConfig;
$this->includeStorage = $includeStorage;
}
public function jsRender(): string
{
$final = (new Jquery($this->view))
->atkReloadView(
[
'uri' => $this->view->jsUrl(['__atk_reload' => $this->view->name]),
'uri_options' => !empty($this->args) ? $this->args : null,
'afterSuccess' => $this->afterSuccess ? $this->afterSuccess->jsRender() : null,
'apiConfig' => !empty($this->apiConfig) ? $this->apiConfig : null,
'storeName' => $this->includeStorage ? $this->view->name : null,
]
);
return $final->jsRender();
}
}