| 1: | <?php |
| 2: | |
| 3: | declare(strict_types=1); |
| 4: | |
| 5: | namespace Atk4\Ui\Js; |
| 6: | |
| 7: | use Atk4\Core\WarnDynamicPropertyTrait; |
| 8: | use Atk4\Ui\View; |
| 9: | |
| 10: | |
| 11: | |
| 12: | |
| 13: | class JsReload implements JsExpressionable |
| 14: | { |
| 15: | use WarnDynamicPropertyTrait; |
| 16: | |
| 17: | |
| 18: | public View $view; |
| 19: | |
| 20: | |
| 21: | public $afterSuccess; |
| 22: | |
| 23: | |
| 24: | public array $args = []; |
| 25: | |
| 26: | |
| 27: | |
| 28: | |
| 29: | |
| 30: | public array $apiConfig = []; |
| 31: | |
| 32: | |
| 33: | public $includeStorage = false; |
| 34: | |
| 35: | |
| 36: | |
| 37: | |
| 38: | public function __construct(View $view, array $args = [], JsExpressionable $afterSuccess = null, array $apiConfig = [], bool $includeStorage = false) |
| 39: | { |
| 40: | $this->view = $view; |
| 41: | $this->args = $args; |
| 42: | $this->afterSuccess = $afterSuccess; |
| 43: | $this->apiConfig = $apiConfig; |
| 44: | $this->includeStorage = $includeStorage; |
| 45: | } |
| 46: | |
| 47: | #[\Override] |
| 48: | public function jsRender(): string |
| 49: | { |
| 50: | $final = (new Jquery($this->view)) |
| 51: | ->atkReloadView( |
| 52: | [ |
| 53: | 'url' => $this->view->jsUrl(['__atk_reload' => $this->view->name]), |
| 54: | 'urlOptions' => $this->args !== [] ? $this->args : null, |
| 55: | 'afterSuccess' => $this->afterSuccess ? $this->afterSuccess->jsRender() : null, |
| 56: | 'apiConfig' => $this->apiConfig !== [] ? $this->apiConfig : null, |
| 57: | 'storeName' => $this->includeStorage ? $this->view->name : null, |
| 58: | ] |
| 59: | ); |
| 60: | |
| 61: | return $final->jsRender(); |
| 62: | } |
| 63: | } |
| 64: | |