Skip to content

Commit

Permalink
* Bootstrap3Renderer, úpravy v Bootstrap4Renderer.
Browse files Browse the repository at this point in the history
* Doladění Html5Renderer.
  • Loading branch information
JZechy committed Sep 28, 2017
1 parent ed4cdc8 commit d3e3fc5
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 13 deletions.
87 changes: 84 additions & 3 deletions src/Template/Renderer/Bootstrap3Renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Zet\FileUpload\Template\Renderer;

use Nette\Object;
use Nette\Utils\Html;

/**
* Class Bootstrap3Renderer
Expand All @@ -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;
}

/**
Expand All @@ -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;
}

/**
Expand All @@ -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;
}
}
10 changes: 7 additions & 3 deletions src/Template/Renderer/Bootstrap4Renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);

Expand All @@ -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;
Expand Down
12 changes: 5 additions & 7 deletions src/Template/Renderer/Html5Renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit d3e3fc5

Please sign in to comment.