Skip to content

Commit

Permalink
faked global sticky via _GET filter
Browse files Browse the repository at this point in the history
  • Loading branch information
mvorisek committed Jul 22, 2021
1 parent f85a5ef commit 9b532df
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
6 changes: 2 additions & 4 deletions src/Callback.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ protected function init(): void
public function setUrlTrigger(string $trigger = null)
{
$this->urlTrigger = $trigger ?: $this->name;

$this->getOwner()->stickyGet(self::URL_QUERY_TRIGGER_PREFIX . $this->urlTrigger);
}

public function getUrlTrigger(): string
Expand Down Expand Up @@ -122,7 +120,7 @@ public function canTrigger(): bool
*/
public function getJsUrl(string $value = 'ajax'): string
{
return $this->getOwner()->jsUrl($this->getUrlArguments($value));
return $this->getOwner()->jsUrl($this->getUrlArguments($value), true);
}

/**
Expand All @@ -131,7 +129,7 @@ public function getJsUrl(string $value = 'ajax'): string
*/
public function getUrl(string $value = 'callback'): string
{
return $this->getOwner()->url($this->getUrlArguments($value));
return $this->getOwner()->url($this->getUrlArguments($value), true);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/JsReload.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function jsRender(): string
$final = (new Jquery($this->view))
->atkReloadView(
[
'uri' => $this->view->jsUrl(['__atk_reload' => $this->view->name]),
'uri' => $this->view->jsUrl(['__atk_reload' => $this->view->name], true),
'uri_options' => !empty($this->args) ? $this->args : null,
'afterSuccess' => $this->afterSuccess ? $this->afterSuccess->jsRender() : null,
'apiConfig' => !empty($this->apiConfig) ? $this->apiConfig : null,
Expand Down
20 changes: 16 additions & 4 deletions src/View.php
Original file line number Diff line number Diff line change
Expand Up @@ -597,9 +597,9 @@ public function removeAttr($property)
*
* @return string
*/
public function jsUrl($page = [])
public function jsUrl($page = [], bool $includeRunningCallback = false)
{
return $this->getApp()->jsUrl($page, false, $this->_getStickyArgs());
return $this->getApp()->jsUrl($page, false, array_merge($this->_getStickyArgs(), $includeRunningCallback ? $this->getCallbackArguments() : []));
}

/**
Expand All @@ -611,9 +611,9 @@ public function jsUrl($page = [])
*
* @return string
*/
public function url($page = [])
public function url($page = [], bool $includeRunningCallback = false)
{
return $this->getApp()->url($page, false, $this->_getStickyArgs());
return $this->getApp()->url($page, false, array_merge($this->_getStickyArgs(), $includeRunningCallback ? $this->getCallbackArguments() : []));
}

/**
Expand All @@ -630,6 +630,18 @@ protected function _getStickyArgs(): array
return $stickyArgs;
}

protected function getCallbackArguments(): array
{
$triggers = [];
foreach ($_GET as $k => $get) {
if (str_starts_with($k, Callback::URL_QUERY_TRIGGER_PREFIX)) {
$triggers[$k] = $get;
}
}

return $triggers;
}

/**
* Mark GET argument as sticky. Calling url() on this view or any
* sub-views will embedd the value of this GET argument.
Expand Down

0 comments on commit 9b532df

Please sign in to comment.