Skip to content

Commit

Permalink
* Html5Renderer úpravy.
Browse files Browse the repository at this point in the history
* Bootstrap4Renderer
  • Loading branch information
JZechy committed Sep 24, 2017
1 parent e6a899e commit ed4cdc8
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 10 deletions.
6 changes: 4 additions & 2 deletions src/FileUploadControl.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Zet\FileUpload;

use Tracy\Debugger;

/**
* Class FileUploadControl
* @author Zechy <[email protected]>
Expand Down Expand Up @@ -156,11 +158,11 @@ public function __construct($name, $maxFiles, $maxFileSize = NULL) {
parent::__construct($name);
$this->maxFiles = $maxFiles;
if(is_null($maxFileSize)) {
$this->maxFileSize = $this->parseIniSize(ini_get("upload_max_filesize"));
$this->fileSizeString = ini_get("upload_max_filesize") . "B";
$this->maxFileSize = $this->parseIniSize(ini_get("upload_max_filesize"));
} else {
$this->maxFileSize = $this->parseIniSize($maxFileSize);
$this->fileSizeString = $maxFileSize . "B";
$this->maxFileSize = $this->parseIniSize($maxFileSize);
}
$this->controller = new Model\UploadController($this);
$this->token = uniqid();
Expand Down
80 changes: 77 additions & 3 deletions src/Template/Renderer/Bootstrap4Renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Zet\FileUpload\Template\Renderer;

use Nette\Utils\Html;

/**
* Class Bootstrap4Renderer
*
Expand All @@ -10,13 +12,57 @@
*/
class Bootstrap4Renderer 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 mb-2'");
$button->setAttribute("onclick", "document.getElementById('$id').click(); return false;");
$button->setText("Nahrát soubor");

$customContainer->addHtml($this->elements["input"]);
$customContainer->addHtml($button);

$globalProgress = $this->elements["globalProgress"]
->setAttribute("class", "progress-bar")
->setAttribute("style", "height: 20px");
$progressContainer = Html::el("div class='progress mb-2'");
$progressContainer->addHtml($globalProgress);
$customContainer->addHtml($progressContainer);

$container = $this->elements["container"];
$container->setName("table");
$container->setAttribute("class", "table");

$thead = Html::el("thead class='thead-inverse'");
$tr = Html::el("tr");
$preview = Html::el("th style='width: 25%;'");
$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);
$customContainer->addHtml($container);

return $customContainer;
}

/**
Expand All @@ -25,7 +71,30 @@ public function buildDefaultTemplate() {
* @return \Nette\Utils\Html
*/
public function buildFileContainerTemplate() {
// TODO: Implement buildFileContainerTemplate() method.
$tr = Html::el("tr");

$preview = Html::el("td class='align-middle'");
$preview->addHtml($this->elements["imagePreview"]->setAttribute("width", "100%"));
$preview->addHtml($this->elements["filePreview"]->setName("span")->setAttribute("class", "badge badge-pill badge-info"));
$tr->addHtml($preview);

$name = Html::el("td class='align-middle'");
$name->addHtml($this->elements["filename"]);
$tr->addHtml($name);

$progressTd = Html::el("td class='align-middle'");
$progressContainer = Html::el("div class='progress'");
$progress = $this->elements["fileProgress"]->setAttribute("class", "progress-bar")
->setAttribute("style", "height: 10px");
$progressContainer->addHtml($progress);
$progressTd->addHtml($progressContainer);
$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"));
$tr->addHtml($delete);

return $tr;
}

/**
Expand All @@ -34,6 +103,11 @@ public function buildFileContainerTemplate() {
* @return \Nette\Utils\Html
*/
public function buildFileError() {
// TODO: Implement buildFileError() method.
$tr = Html::el("tr class='bg-danger text-light'");
$tr->addHtml($this->elements["errorMessage"]->setName("td")->addAttributes([
"colspan" => 4
]));

return $tr;
}
}
15 changes: 11 additions & 4 deletions src/Template/Renderer/Html5Renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,21 @@ public function init() {
*/
public function buildDefaultTemplate() {
$table = $this->elements["container"];
$table->setAttribute("cellpadding", "5px");

// Header
$tr = Html::el("tr");
$th = Html::el("th colspan='2'");
$th = Html::el("th colspan='2' style='border-right: none'");
$th->setText("Nahrávání souborů");
$tr->addHtml($th);
$th2 = Html::el("th colspan='2'");
$th2->addHtml($this->elements["input"]);
$th2 = Html::el("th colspan='2' style='text-align: right; border-left: none'");
$th2->addHtml($this->elements["input"]->setAttribute("style", "display: none"));
$button = Html::el("button type='button'");
$button->setText("Nahrát soubor");
$id = $this->elements["input"]->getAttribute("id");
$button->setAttribute("onclick", "document.getElementById('$id').click(); return false;");
$th2->addHtml($button);

$tr->addHtml($th2);
$table->addHtml($tr);

Expand All @@ -87,7 +94,7 @@ public function buildFileContainerTemplate() {
$preview = Html::el("td")->addAttributes([
"style" => "width: 20%"
]);
$preview->addHtml($this->elements["imagePreview"]);
$preview->addHtml($this->elements["imagePreview"]->setAttribute("width", "100%"));
$preview->addHtml($this->elements["filePreview"]);
$tr->addHtml($preview);

Expand Down
2 changes: 1 addition & 1 deletion src/www/fileupload/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ FileUploadController.prototype = {
this.renderer.addError(file, this.fileId, message);
this.fileId++;
} else if (file["size"] > this.config.maxFileSize) {
message = this.messages.maxSize.replace("%maxSize%", this.config.maxFileSize.toString());
message = this.messages.maxSize.replace("%maxSize%", this.config.fileSizeString);
this.renderer.addError(file, this.fileId, message);
this.fileId++;
} else {
Expand Down

0 comments on commit ed4cdc8

Please sign in to comment.