Skip to content

Commit

Permalink
Add set url ability for HookTrait
Browse files Browse the repository at this point in the history
  • Loading branch information
tafid committed Nov 16, 2020
1 parent b644888 commit 0289b23
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/widgets/HookTrait.php
Expand Up @@ -3,17 +3,21 @@
namespace hipanel\widgets;

use hipanel\actions\Action;
use yii\helpers\Json;
use yii\web\View;

trait HookTrait
{
public ?string $url = null;

public function registerJsHook(string $reqHeaderParamName): void
{
$id = $this->getId();
$headerName = Action::EXPECTED_AJAX_RESPONSE_HEADER_NAME;
$url = $this->url ? Json::encode($this->url) : 'document.URL';
$this->view->registerJs("$.ajax({
type: 'GET',
url: document.URL,
url: {$url},
beforeSend: xhr => {
xhr.setRequestHeader('{$headerName}', '{$reqHeaderParamName}');
},
Expand Down

0 comments on commit 0289b23

Please sign in to comment.