|
@@ -15,6 +15,10 @@ trait HasActionHandler
|
|
|
* @var Response
|
|
|
*/
|
|
|
protected $response;
|
|
|
+
|
|
|
+ private $confirmString;
|
|
|
+
|
|
|
+ private $paramString;
|
|
|
|
|
|
/**
|
|
|
* @return Response
|
|
@@ -70,14 +74,32 @@ trait HasActionHandler
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * @return void
|
|
|
+ * @return string
|
|
|
*/
|
|
|
- protected function addHandlerScript()
|
|
|
+ protected function normalizeConfirmData()
|
|
|
{
|
|
|
- $data = json_encode($this->parameters());
|
|
|
+ if ($this->confirmString !== null) {
|
|
|
+ return $this->confirmString;
|
|
|
+ }
|
|
|
+
|
|
|
$confirm = $this->confirm();
|
|
|
- $confirm = $confirm ? admin_javascript_json((array) $confirm) : 'false';
|
|
|
|
|
|
+ return $this->confirmString = ($confirm ? admin_javascript_json((array) $confirm) : 'false');
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @return string
|
|
|
+ */
|
|
|
+ protected function normalizeParameters()
|
|
|
+ {
|
|
|
+ return $this->paramString ?: ($this->paramString = json_encode($this->parameters()));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @return void
|
|
|
+ */
|
|
|
+ protected function addHandlerScript()
|
|
|
+ {
|
|
|
$script = <<<JS
|
|
|
Dcat.Action({
|
|
|
selector: '{$this->selector()}',
|
|
@@ -85,8 +107,8 @@ Dcat.Action({
|
|
|
method: '{$this->method()}',
|
|
|
key: '{$this->getKey()}',
|
|
|
url: '{$this->handlerRoute()}',
|
|
|
- data: {$data},
|
|
|
- confirm: {$confirm},
|
|
|
+ data: {$this->normalizeParameters()},
|
|
|
+ confirm: {$this->normalizeConfirmData()},
|
|
|
calledClass: '{$this->makeCalledClass()}',
|
|
|
before: {$this->actionScript()},
|
|
|
html: {$this->handleHtmlResponse()},
|