diff --git a/src/actions/Action.php b/src/actions/Action.php
index d45a274f..cb35f8e9 100644
--- a/src/actions/Action.php
+++ b/src/actions/Action.php
@@ -31,6 +31,7 @@ class Action extends \yii\base\Action
const EVENT_BEFORE_LOAD = 'beforeLoad';
const EVENT_BEFORE_PERFORM = 'beforePerform';
const EVENT_AFTER_PERFORM = 'afterPerform';
+ const EXPECTED_AJAX_RESPONSE_HEADER_NAME = 'X-Expected-Ajax-Response';
/**
* @var Controller the controller that owns this action
diff --git a/src/actions/RenderSummaryAction.php b/src/actions/RenderSummaryAction.php
deleted file mode 100644
index 09fe08ef..00000000
--- a/src/actions/RenderSummaryAction.php
+++ /dev/null
@@ -1,28 +0,0 @@
-summary, $this);
- }
-}
diff --git a/src/actions/VariantsAction.php b/src/actions/VariantsAction.php
new file mode 100644
index 00000000..0097c7a6
--- /dev/null
+++ b/src/actions/VariantsAction.php
@@ -0,0 +1,34 @@
+controller->request->headers->get(self::EXPECTED_AJAX_RESPONSE_HEADER_NAME);
+ foreach ($this->variants as $expected => $variant) {
+ if ($expected === $headerName) {
+ return $variant($this);
+ }
+ }
+ Yii::$app->end();
+ }
+}
diff --git a/src/base/SearchModelTrait.php b/src/base/SearchModelTrait.php
index f79b5d92..f770866d 100644
--- a/src/base/SearchModelTrait.php
+++ b/src/base/SearchModelTrait.php
@@ -12,7 +12,7 @@
use hiqdev\hiart\ActiveQuery;
use hiqdev\hiart\ActiveRecord;
-use yii\data\ActiveDataProvider;
+use hiqdev\hiart\ActiveDataProvider;
use yii\helpers\ArrayHelper;
/**
diff --git a/src/widgets/CountEnabler.php b/src/widgets/CountEnabler.php
new file mode 100644
index 00000000..673793a9
--- /dev/null
+++ b/src/widgets/CountEnabler.php
@@ -0,0 +1,26 @@
+dataProvider->enableCount();
+ $grid = Yii::createObject([
+ 'class' => GridView::class,
+ 'dataProvider' => $this->dataProvider,
+ ]);
+
+ return call_user_func($this->content, $grid);
+ }
+}
diff --git a/src/widgets/HookInterface.php b/src/widgets/HookInterface.php
new file mode 100644
index 00000000..0d5e768a
--- /dev/null
+++ b/src/widgets/HookInterface.php
@@ -0,0 +1,8 @@
+getId();
+ $headerName = Action::EXPECTED_AJAX_RESPONSE_HEADER_NAME;
+ $this->view->registerJs("$.ajax({
+ type: 'GET',
+ url: document.URL,
+ beforeSend: xhr => {
+ xhr.setRequestHeader('{$headerName}', '{$reqHeaderParamName}');
+ },
+ success: html => {
+ $('#{$id}').html(html);
+ }
+ });", View::POS_LOAD);
+ }
+}
diff --git a/src/widgets/PagerHook.php b/src/widgets/PagerHook.php
new file mode 100644
index 00000000..8887bf32
--- /dev/null
+++ b/src/widgets/PagerHook.php
@@ -0,0 +1,31 @@
+registerJsHook('pager');
+ }
+
+ public function run()
+ {
+ return Html::tag($this->tag, $this->content ?? $this->getLoader(), array_merge(['id' => $this->getId()], $this->options));
+ }
+
+ private function getLoader(): string
+ {
+ return Html::tag('span', null, ['class' => 'fa fa-spinner fa-pulse', 'style' => 'margin-right: .7rem;']) . Yii::t('hipanel', 'loading pager...');
+ }
+}
\ No newline at end of file
diff --git a/src/widgets/SummaryHook.php b/src/widgets/SummaryHook.php
index cb1f6451..07548cc6 100644
--- a/src/widgets/SummaryHook.php
+++ b/src/widgets/SummaryHook.php
@@ -5,10 +5,11 @@
use Yii;
use yii\base\Widget;
use yii\helpers\Html;
-use yii\web\View;
-class SummaryHook extends Widget
+class SummaryHook extends Widget implements HookInterface
{
+ use HookTrait;
+
public string $tag = 'div';
public array $options = [];
@@ -18,22 +19,16 @@ class SummaryHook extends Widget
public function init()
{
parent::init();
- $this->registerJs();
+ $this->registerJsHook('summary');
}
public function run()
{
- return Html::tag($this->tag, $this->content ?? $this->getLoader(), array_merge(['id' => $this->getId(), 'class' => 'summary'], $this->options));
- }
-
- private function registerJs(): void
- {
- $id = $this->getId();
- $this->view->registerJs("$.get(document.URL, summary => { $('#{$id}').html(summary) });", View::POS_LOAD);
+ return Html::tag($this->tag, $this->content ?? $this->getLoader(), array_merge(['id' => $this->getId()], $this->options));
}
private function getLoader(): string
{
- return Html::tag('span', null, ['class' => 'fa fa-spinner fa-pulse', 'style' => 'margin-right: .7rem;']) . Yii::t('hipanel', 'loading summary...');
+ return Html::tag('span', null, ['class' => 'fa fa-spinner fa-pulse', 'style' => 'margin: .7rem; 0 1rem']) . Yii::t('hipanel', 'loading summary...');
}
}
diff --git a/src/widgets/SummaryWidget.php b/src/widgets/SummaryWidget.php
index 80c64089..19e8c86b 100644
--- a/src/widgets/SummaryWidget.php
+++ b/src/widgets/SummaryWidget.php
@@ -31,8 +31,9 @@ public function run()
$locals = $this->getSumsString($this->local_sums ?? []);
$totals = $this->getSumsString($this->total_sums ?? []);
- return ($totals !== '' ? Yii::t('hipanel:stock', 'TOTAL: {sum}', ['sum' => $totals]) : null) .
- ($locals !== '' ? '
' . Yii::t('hipanel:stock', 'on screen: {sum}', ['sum' => $locals]) . '' : null);
+ return '