From f3913aef2436b3199f647f09aa23ade86d172767 Mon Sep 17 00:00:00 2001 From: Pavel Mironchik Date: Tue, 12 Jan 2021 19:30:36 +0600 Subject: [PATCH] Allow to use the script component with modules' custom scripts. --- app/View/Components/Documents/Script.php | 19 ++++++++++++++++++- .../components/documents/script.blade.php | 2 +- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/app/View/Components/Documents/Script.php b/app/View/Components/Documents/Script.php index 2922ceead..705927b7c 100644 --- a/app/View/Components/Documents/Script.php +++ b/app/View/Components/Documents/Script.php @@ -15,6 +15,9 @@ class Script extends Component /** @var string */ public $scriptFile; + /** @var string */ + public $version; + public $items; public $currencies; @@ -26,10 +29,11 @@ class Script extends Component * * @return void */ - public function __construct(string $type = '', string $scriptFile = '', $items = [], $currencies = [], $taxes = []) + public function __construct(string $type = '', string $scriptFile = '', string $version = '', $items = [], $currencies = [], $taxes = []) { $this->type = $type; $this->scriptFile = ($scriptFile) ? $scriptFile : 'public/js/common/documents.js'; + $this->version = $this->getVersion($version); $this->items = $items; $this->currencies = $this->getCurrencies($currencies); $this->taxes = $this->getTaxes($taxes); @@ -45,6 +49,19 @@ class Script extends Component return view('components.documents.script'); } + protected function getVersion($version) + { + if (!empty($version)) { + return $version; + } + + if ($alias = config('type.' . $this->type . '.alias')) { + return module_version($alias); + } + + return version('short'); + } + protected function getCurrencies($currencies) { if (!empty($currencies)) { diff --git a/resources/views/components/documents/script.blade.php b/resources/views/components/documents/script.blade.php index b7500dfad..3904335bc 100644 --- a/resources/views/components/documents/script.blade.php +++ b/resources/views/components/documents/script.blade.php @@ -15,4 +15,4 @@ var document_taxes = {!! $taxes !!}; - +