Last active
June 25, 2018 09:01
-
-
Save joseph-montanez/d05a12449e2ffca921a74b381e86228f to your computer and use it in GitHub Desktop.
jsReload Accept URL
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$grid_reload = new \atk4\ui\jsReload($grid); | |
$grid_reload->url = '/admin/users/list'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace atk4\ui; | |
/** | |
* This class generates action, that will be able to loop-back to the callback method. | |
*/ | |
class jsReload implements jsExpressionable | |
{ | |
/** | |
* Specifies which url to reload. | |
* | |
* @var string | |
*/ | |
public $url = null; | |
/** | |
* Specifies which view to reload. Use constructor to set. | |
* | |
* @var View | |
*/ | |
public $view = null; | |
/** | |
* A Js function to execute after reload is complete and onSuccess is execute. | |
* | |
* @var jsExpression | |
*/ | |
public $afterSuccess = null; | |
/** | |
* 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 = []; | |
public function __construct($view, $args = [], $afterSuccess = null) | |
{ | |
$this->view = $view; | |
$this->args = $args; | |
$this->afterSuccess = $afterSuccess; | |
} | |
public function jsRender() | |
{ | |
$page = ['__atk_reload'=>$this->view->name]; | |
//-- If there is a custom URL set, then reload from that URL | |
if ($this->url !== null) { | |
array_unshift($page, $this->url); | |
} | |
$final = (new jQuery($this->view)) | |
->atkReloadView( | |
[ | |
'uri' => $this->view->jsURL($page), | |
'uri_options' => $this->args, | |
'afterSuccess' => $this->afterSuccess ? $this->afterSuccess->jsRender() : null, | |
] | |
); | |
return $final->jsRender(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment