Skip to content

Commit

Permalink
Možnost přidávat vlastní šablonu.
Browse files Browse the repository at this point in the history
  • Loading branch information
JZechy committed Oct 29, 2016
1 parent 3661140 commit f28a47c
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 9 deletions.
26 changes: 25 additions & 1 deletion src/FileUploadControl.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
*/
Expand Down
13 changes: 5 additions & 8 deletions src/Model/UploadController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down Expand Up @@ -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();

Expand Down

0 comments on commit f28a47c

Please sign in to comment.