From f28a47c95b34fbd2d16979a8defc730f757cbece Mon Sep 17 00:00:00 2001 From: Zechy Date: Sat, 29 Oct 2016 17:09:43 +0200 Subject: [PATCH] =?UTF-8?q?Mo=C5=BEnost=20p=C5=99id=C3=A1vat=20vlastn?= =?UTF-8?q?=C3=AD=20=C5=A1ablonu.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/FileUploadControl.php | 26 +++++++++++++++++++++++++- src/Model/UploadController.php | 13 +++++-------- 2 files changed, 30 insertions(+), 9 deletions(-) diff --git a/src/FileUploadControl.php b/src/FileUploadControl.php index 586ec7a..66a2a06 100644 --- a/src/FileUploadControl.php +++ b/src/FileUploadControl.php @@ -171,6 +171,14 @@ public static function getScripts($basePath) { * @var string */ private $token; + + /** + * @var array + */ + private $uiTemplates = [ + self::UI_FULL => __DIR__ . "/Template/full.latte", + self::UI_MINIMAL => __DIR__ . "/Template/minimal.latte" + ]; /** * FileUploadControl constructor. @@ -191,7 +199,23 @@ public function __construct($name, $maxFiles, $maxFileSize = NULL) { $this->controller = new Model\UploadController($this); $this->token = uniqid(); } - + + /** + * @param int $type + * @return int|NULL + */ + public function getUiTemplate($type) { + return isset($this->uiTemplates[$type]) ? $this->uiTemplates[$type] : NULL; + } + + /** + * @param int $type + * @param string $file + */ + public function setUiTemplate($type, $file) { + $this->uiTemplates[$type] = $file; + } + /** * @param $form */ diff --git a/src/Model/UploadController.php b/src/Model/UploadController.php index f0a889d..55a4584 100644 --- a/src/Model/UploadController.php +++ b/src/Model/UploadController.php @@ -65,14 +65,11 @@ public function getFilter() { * @return string */ private function getControlFile() { - switch($this->uploadControl->getUIMode()) { - case \Zet\FileUpload\FileUploadControl::UI_FULL: - return "full.latte"; - case \Zet\FileUpload\FileUploadControl::UI_MINIMAL: - return "minimal.latte"; - default: - throw new \Nette\InvalidArgumentException(); + $template = $this->uploadControl->getUiTemplate($this->uploadControl->getUIMode()); + if(is_null($template)) { + throw new \Nette\InvalidArgumentException(); } + return $template; } /** @@ -103,7 +100,7 @@ public function getJavaScriptTemplate() { */ public function getControlTemplate() { $template = $this->template; - $template->setFile(__DIR__ . "/../Template/" . $this->getControlFile()); + $template->setFile($this->getControlFile()); $template->htmlId = $this->uploadControl->getHtmlId(); $template->htmlName = $this->uploadControl->getHtmlName();