From d3e3fc5fa10ee3fb50e4bbff27c8347098b3613b Mon Sep 17 00:00:00 2001 From: Zechy Date: Thu, 28 Sep 2017 13:33:45 +0200 Subject: [PATCH] =?UTF-8?q?*=20Bootstrap3Renderer,=20=C3=BApravy=20v=20Boo?= =?UTF-8?q?tstrap4Renderer.=20*=20Dolad=C4=9Bn=C3=AD=20Html5Renderer.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Template/Renderer/Bootstrap3Renderer.php | 87 +++++++++++++++++++- src/Template/Renderer/Bootstrap4Renderer.php | 10 ++- src/Template/Renderer/Html5Renderer.php | 12 ++- 3 files changed, 96 insertions(+), 13 deletions(-) diff --git a/src/Template/Renderer/Bootstrap3Renderer.php b/src/Template/Renderer/Bootstrap3Renderer.php index a7b7e73..69d3f4e 100644 --- a/src/Template/Renderer/Bootstrap3Renderer.php +++ b/src/Template/Renderer/Bootstrap3Renderer.php @@ -3,6 +3,7 @@ namespace Zet\FileUpload\Template\Renderer; use Nette\Object; +use Nette\Utils\Html; /** * Class Bootstrap3Renderer @@ -12,13 +13,62 @@ */ class Bootstrap3Renderer extends BaseRenderer { + public function init() { + parent::init(); + + $this->elements["globalProgressValue"] = null; + $this->elements["fileProgressValue"] = null; + } + /** * Sestavení výchozí šablony uploaderu. * * @return \Nette\Utils\Html */ public function buildDefaultTemplate() { - // TODO: Implement buildDefaultTemplate() method. + $customContainer = Html::el("div"); + + $this->elements["input"]->setAttribute("style", "display: none"); + $id = $this->elements["input"]->getAttribute("id"); + $button = Html::el("button type='button' class='btn btn-primary'"); + $button->setAttribute("onclick", "document.getElementById('$id').click(); return false;") + ->setAttribute("style", "margin-bottom: 10px"); + $button->setText("Nahrát soubor"); + + $customContainer->addHtml($this->elements["input"]); + $customContainer->addHtml($button); + + $globalProgress = $this->elements["globalProgress"] + ->setAttribute("class", "progress-bar"); + $progressContainer = Html::el("div class='progress'"); + $progressContainer->addHtml($globalProgress); + $customContainer->addHtml($progressContainer); + + $container = Html::el("table"); + $container->setAttribute("class", "table table-striped"); + + $thead = Html::el("thead"); + $tr = Html::el("tr"); + $preview = Html::el("th style='width: 15%;'"); + $tr->addHtml($preview); + $filename = Html::el("th")->setText("Soubor"); + $tr->addHtml($filename); + $status = Html::el("th style='width: 20%'")->setText("Stav"); + $tr->addHtml($status); + $actions = Html::el("th style='width: 50px'"); + $tr->addHtml($actions); + $thead->addHtml($tr); + + $container->addHtml($thead); + + $fileUploadContainer = $this->elements["container"]; + $fileUploadContainer->setName("tbody"); + $container->addHtml($fileUploadContainer); + $customContainer->addHtml($container); + + return $customContainer; + + return $customContainer; } /** @@ -27,7 +77,33 @@ public function buildDefaultTemplate() { * @return \Nette\Utils\Html */ public function buildFileContainerTemplate() { - // TODO: Implement buildFileContainerTemplate() method. + $tr = Html::el("tr"); + + $preview = Html::el("td style='vertical-align: middle'"); + $preview->addHtml($this->elements["imagePreview"]->setAttribute("width", "100%")->setAttribute("class", "img-rounded")); + $preview->addHtml($this->elements["filePreview"]->setName("span")->setAttribute("class", "label label-info")); + $tr->addHtml($preview); + + $name = Html::el("td style='vertical-align: middle'"); + $name->addHtml($this->elements["filename"]); + $tr->addHtml($name); + + $progressTd = Html::el("td style='vertical-align: middle'"); + $progressContainer = Html::el("div class='progress' style='margin-bottom: 0px'"); + $progress = $this->elements["fileProgress"]->setAttribute("class", "progress-bar"); + $progressContainer->addHtml($progress); + $progressTd->addHtml($progressContainer); + $tr->addHtml($progressTd); + + $delete = Html::el("td style='vertical-align: middle' class='text-center'"); + $delete->addHtml( + $this->elements["delete"] + ->setAttribute("class", "btn btn-danger") + ->setHtml("×") + ); + $tr->addHtml($delete); + + return $tr; } /** @@ -36,6 +112,11 @@ public function buildFileContainerTemplate() { * @return \Nette\Utils\Html */ public function buildFileError() { - // TODO: Implement buildFileError() method. + $tr = Html::el("tr class='danger'"); + $tr->addHtml($this->elements["errorMessage"]->setName("td")->addAttributes([ + "colspan" => 4 + ])); + + return $tr; } } \ No newline at end of file diff --git a/src/Template/Renderer/Bootstrap4Renderer.php b/src/Template/Renderer/Bootstrap4Renderer.php index b782bd4..0e6f90c 100644 --- a/src/Template/Renderer/Bootstrap4Renderer.php +++ b/src/Template/Renderer/Bootstrap4Renderer.php @@ -49,7 +49,7 @@ public function buildDefaultTemplate() { $thead = Html::el("thead class='thead-inverse'"); $tr = Html::el("tr"); - $preview = Html::el("th style='width: 25%;'"); + $preview = Html::el("th style='width: 15%;'"); $tr->addHtml($preview); $filename = Html::el("th")->setText("Soubor"); $tr->addHtml($filename); @@ -74,7 +74,7 @@ public function buildFileContainerTemplate() { $tr = Html::el("tr"); $preview = Html::el("td class='align-middle'"); - $preview->addHtml($this->elements["imagePreview"]->setAttribute("width", "100%")); + $preview->addHtml($this->elements["imagePreview"]->setAttribute("width", "100%")->setAttribute("class", "rounded")); $preview->addHtml($this->elements["filePreview"]->setName("span")->setAttribute("class", "badge badge-pill badge-info")); $tr->addHtml($preview); @@ -91,7 +91,11 @@ public function buildFileContainerTemplate() { $tr->addHtml($progressTd); $delete = Html::el("td class='align-middle text-center'"); - $delete->addHtml($this->elements["delete"]->setAttribute("class", "btn btn-outline-danger")->setText("X")); + $delete->addHtml( + $this->elements["delete"] + ->setAttribute("class", "btn btn-outline-danger") + ->setHtml("×") + ); $tr->addHtml($delete); return $tr; diff --git a/src/Template/Renderer/Html5Renderer.php b/src/Template/Renderer/Html5Renderer.php index df2d21d..80fcafb 100644 --- a/src/Template/Renderer/Html5Renderer.php +++ b/src/Template/Renderer/Html5Renderer.php @@ -22,7 +22,7 @@ public function init() { $this->elements["container"]->setName("table")->addAttributes([ "style" => "width: 100%", - "border" => "1" + "border" => "0" ]); $this->elements["globalProgress"]->setName("progress") @@ -92,26 +92,24 @@ public function buildFileContainerTemplate() { $tr = Html::el("tr"); $preview = Html::el("td")->addAttributes([ - "style" => "width: 20%" + "style" => "width: 15%" ]); $preview->addHtml($this->elements["imagePreview"]->setAttribute("width", "100%")); $preview->addHtml($this->elements["filePreview"]); $tr->addHtml($preview); $name = Html::el("td"); - $name->addHtml($this->elements["filename"])->addAttributes([ - "style" => "width: 55%" - ]); + $name->addHtml($this->elements["filename"]); $tr->addHtml($name); $progress = Html::el("td"); $progress->addHtml($this->elements["fileProgress"])->addAttributes([ - "style" => "width: 15%" + "style" => "width: 20%" ]); $tr->addHtml($progress); $delete = Html::el("td")->addAttributes([ - "style" => "width: 5%; text-align: center", + "style" => "width: 50px; text-align: center", ]); $delete->addHtml($this->elements["delete"]); $tr->addHtml($delete);