MultiUpload – rozšíření JS?
- Joacim
- Člen | 229
Zdravím,
už jsem zde pokládal podobnou otázku na kterou zatím neznám odpověď.
Přes composer jsem si stáhnul jkuchar/multiplefileupload
a vše zprovoznil.
Bohužel jsem obdržel Toto ,ale potřeboval bych "Tuto ":https://www.youtube.com/watch?… funkčnost
- Buďto bych chtěl nastavit jkuchar/multiplefileupload, aby fungoval jako klasický multiupload → tedy jedno tlačítko pro vybrání souborů a v okně filesystemu si vybrat 1 až 20 fotek a nevim zda to jde bez použití JS
- Implementovat Uploadify nebo "Plupload ":http://www.plupload.com/examples nebo Fine Uploader
- bylo by dobré kdyby se to dalo implementovat na již přidaný jkuchar/multiplefileupload
- ptám se jelikož zde na foru jsou příspěvky starší 2 let
- jaká je nejlepší možnost ? a co použít
bootstrap.php
// Setup MultipleFileUpload
MultipleFileUpload\MultipleFileUpload::register();
GalleryPresenter.php
class GalleryPresenter extends ProtectedPresenter {
/** @var Nette\Database\Context */
private $database;
/** @var ImageStorage */
private $imageStorage;
public function __construct(Nette\Database\Context $database) {
$this->database = $database;
}
public function renderDefault() {
}
public function handleRenderGalleryAdd(array $gallery_data) {
if ($this->isAjax()) {
// Insert new gallery to DB
// Vrať Last ID a vytvoř novou složku podle právě přidané galerie
// Create gallery folder
}
}
public function handleRenderGalleryDelete(array $gallery_data) {
if ($this->isAjax()) {
}
$this->redrawControl('galleryList');
}
}
public function injectImages(\App\Model\ImageStorage $storage) {
$this->imageStorage = $storage;
}
public function renderShow($gid) {
}
/**
* Returns array of suggestions
*/
public function checkConfiguration() {
$www = $this->context->expand("%wwwDir%");
$publicMFUDir = $www . "/MultipleFileUpload/";
$jsDir = $www . "/js/";
$messages = array();
if (!file_exists($publicMFUDir)) {
$messages[] = "Directory \"www/MultipleFileUpload\" not found! Copy or link content of \"libs/jkuchar/MultipleFileUpload/public\" folder to \"www/MultipleFileUpload\".";
};
if (!file_exists($publicMFUDir . "MFUFallbackController.js")) {
$messages[] = "File MFUFallbackController.js is missing! Is should be in www/MultipleFileUpload. MFU can't work without this file.";
};
if (!file_exists($jsDir)) {
$messages[] = "WARNING: Directory \"www/js\" not found! (trying to check, if jQuery is properly installed)";
}
if (!file_exists($jsDir . "jquery.js")) {
$messages[] = "WARNING: File jquery.js not found! MultipleFileUpload does not work corectly without jQuery.";
}
if (!file_exists($jsDir . "nette.ajax.js")) {
$messages[] = "WARNING: File nette.ajax.js not found! This is needed if you want to use AJAX. (https://componette.org/search/?q=vojtech-dobes%2Fnette-ajax-js)";
}
if (!file_exists($jsDir . "netteForms.js")) {
$messages[] = "WARNING: File netteForms.js not found! This is needed if you want validation of forms.";
}
return $messages;
}
public function createComponentForm($name) {
$form = new Form($this, $name);
$form->getElementPrototype()->class[] = "ajax"; // activate AJAX in https://componette.org/search/?q=vojtech-dobes%2Fnette-ajax-js
// $form->addText("textField", "Text field")
// ->addRule(Form::FILLED, "This is required text field.");
$form->addMultipleFileUpload("upload", "Attachments")
->addRule('MultipleFileUpload\MultipleFileUpload::validateFilled',"You have to upload at least one file!");
// ->addRule('MultipleFileUpload\MultipleFileUpload::validateFileSize',"Files are together too large.",100*1024);
// $form->addMultipleFileUpload("upload2","Second file uploader");
$form->addSubmit("send", "Submit your form!");
$form->onSuccess[] = $this->handleFormSuccess;
// Invalidace snippetů
$form->onError[] = array($this, "handleRedrawForm");
$form->onSuccess[] = array($this, "handleRedrawForm");
}
public function handleFormSuccess(Form $form) {
$data = $form->getValues();
// Let's pass our data to template
$this->template->values = $data;
$queueId = uniqid();
// Moving uploaded files
foreach ($data["upload"] AS $file) {
// $file je instance HttpUploadedFile
var_dump($file); exit();
$newFilePath = \Nette\Environment::expand("%appDir%") . "/../img_gallery/q{" . $queueId . "}__f{" . rand(10, 99) . "}__" . $file->getName();
// V produkčním módu nepřesunujeme soubory...
if (!\Nette\Environment::isProduction()) {
if ($file->move($newFilePath))
$this->flashMessage("File " . $file->getName() . " was successfully moved!");
else
$this->flashMessage("Error while moving file " . $file->getName() . ".");
}
}
}
public function handleRedrawForm() {
// This invalidates snippet
// on AJAX requests this causes redrawing of the form
$this->invalidateControl("form");
}
public function renderAdd($gid) {
}
}
templates/gallery/add.latte
{block content}
<div class="row">
<div class="col-sm-12">
<div class="container-fluid">
<!-- Page Heading -->
<div class="row">
<div class="col-lg-12">
<h1 class="page-header">
Galerie
<small>Seznam galerií</small>
</h1>
<ol class="breadcrumb">
<li>
<i class="fa fa-photo"></i> Galerie
</li>
<li class="active">
<i class="fa fa-plus"></i> Přidání
</li>
</ol>
</div>
</div>
<!-- /.row -->
{form form}
<ul class=error n:if="$form->errors">
<li n:foreach="$form->errors as $error">{$error}</li>
</ul>
<table>
<tr n:foreach="$form->controls as $input" n:class="$input->required ? required">
<th>{if $input->controlPrototype->type !== checkbox}{label $input /}{/if}</th>
<td>{input $input} {if $input->controlPrototype->type === checkbox}{label $input /}{/if}
<span class=error n:if="$input->errors">{$input->errors|implode:' '}</span>
</td>
</tr>
</table>
{/form}
</div>
</div>
</div>
{/block}
{block scripts}
{include parent}
<script src="{$basePath}/js/jquery-ui.min.js"></script>
<script src="{$basePath}/js/jquery.quicksearch.js"></script>
{/block}
{block head}
<link rel="stylesheet" href="{$basePath}/css/jquery-ui.min.css">
<link rel="stylesheet" href="{$basePath}/css/jquery-ui.structure.min.css">
<link rel="stylesheet" href="{$basePath}/css/jquery-ui.theme.min.css">
{/block}
Navíc nevím zda je v composeru uploadify verze a struktury, které bych mohl využít
Editoval Joacim (8. 8. 2015 11:01)
- F.Vesely
- Člen | 369
Normalne postupuj podle navodu https://github.com/…leFileUpload#… a pojede ti PlUpload. U tebe napriklad nevidim krok cislo 3, tedy pridani js a css souboru:
{=MultipleFileUpload\MultipleFileUpload::getHead()|noescape}
- Joacim
- Člen | 229
@layout.latte (na konci latte)
<!-- Bootstrap core JavaScript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
{block scripts}
<!-- jQuery -->
<script src="{$basePath}/js/jquery.js"></script>
<script src="{$basePath}/js/nette.ajax.js"></script>
<!-- Bootstrap Core JavaScript -->
<script src="{$basePath}/js/bootstrap.min.js"></script>
<!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
<script src="{$basePath}/js/ie10-viewport-bug-workaround.js"></script>
<script type="text/JavaScript" src="{$basePath}/MultipleFileUpload/MFUFallbackController.js"></script>
{=MultipleFileUpload\MultipleFileUpload::getHead()|noescape}
{/block}
</body>
</html>
- Joacim
- Člen | 229
Uncaught ReferenceError: MFUFallbackController is not defined(anonymous function) @ add?gid=15:348
URL: http://localhost/…/gallery/add?…
CHci přidat obrázky do již vytvořené galerie a GID je gallery ID s tím že stále vidím TOTO
Editoval Joacim (8. 8. 2015 14:26)
- F.Vesely
- Člen | 369
Uz si vzpominam, taky jsem to resil. Problem je v tom, ze ty registrujes JS az na konci a pri vykreslovani toho formularoveho prvku uz se pocita s tim, ze mas JS nacteny.
Resenich je vice:
- Dat nacitani JS {=MultipleFileUpload\MultipleFileUpload::getHead()|noescape} a jquery do hlavicky
- Upravit soubor vendor/jkuchar/multiplefileupload/MultipleFileUpload/RegisterJS.latte tak, aby se kod provadel az po nacteni JS
- Joacim
- Člen | 229
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="author" content="">
<link rel="stylesheet" media="screen,projection,tv" href="{$basePath}/css/screen.css">
<link rel="stylesheet" media="print" href="{$basePath}/css/print.css">
<link rel="shortcut icon" href="{$basePath}/scode-logo-blue_32.ico">
<title></title>
<!-- Bootstrap Core CSS -->
<link href="{$basePath}/css/bootstrap.min.css" rel="stylesheet">
<!-- Custom CSS -->
<link href="{$basePath}/css/sb-admin.css" rel="stylesheet">
<link href="{$basePath}/css/theme.css" rel="stylesheet">
<!-- Morris Charts CSS -->
<link href="{$basePath}/css/plugins/morris.css" rel="stylesheet">
<!-- Custom Fonts -->
<link href="{$basePath}/font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css">
<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
<script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
<!-- Bootstrap core JavaScript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
{block scripts}
<!-- jQuery -->
<script src="{$basePath}/js/jquery.js"></script>
<script src="{$basePath}/js/nette.ajax.js"></script>
<!-- Bootstrap Core JavaScript -->
<script src="{$basePath}/js/bootstrap.min.js"></script>
<!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
<script src="{$basePath}/js/ie10-viewport-bug-workaround.js"></script>
<script type="text/JavaScript" src="{$basePath}/MultipleFileUpload/MFUFallbackController.js"></script>
{=MultipleFileUpload\MultipleFileUpload::getHead()|noescape}
{/block}
{block head}{/block}
</head>
Díky moc, už to funguje, ale musel jsem dát všechny JS nahoru do HEADER, jaký mají přesně význam bloky (makra scripts ) ?
Editoval Joacim (8. 8. 2015 22:42)
- Joacim
- Člen | 229
Ještě bych potřeboval zprovoznit hromadnou editaci fotek 2 způsoby:
- Mám template show kde si označím libovolný počet fotek a poté kliknu na editovat fotky (form button nebo ajax <a> ?) → do edit renderu potřebuji předat seznam (array s ID vybraných fotek)
- Mám multiupload a po nahrání fotek do DB a do systému potřebuji přejít z templatu add do templatu edit s tím že bych potřeboval do renderEdit přenést array všech označených fotek (ID fotky) nejlépe použití bez session
public function handleFormSuccess(Form $form) {
$gid = $this->getParameter('gid');
$data = $form->getValues();
// Let's pass our data to template
$this->template->values = $data;
$queueId = uniqid();
$gallery = new \Gallery();
// Moving uploaded files
foreach ($data["upload"] AS $file) {
// Vytvoření háhledu (thumbnail)
// Uložení záznamů do DB
$this->database->query('INSERT INTO `gallery_images` (`name`, `url`, `thumb_url`, `size`, `created`, `createdBy`, `edited`, `editedBy`, `contentType`, `sanitizedName`, `gallery_id`) VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)'
, $file->getName(), $file->getTemporaryFile(), NULL, $file->getSize(), date('Y-m-d H:i:s'), $this->user->identity->user_id, NULL, NULL, $file->getContentType(), $file->getSanitizedName(), $gid);
// $file je instance HttpUploadedFile
$newFilePath = \Nette\Environment::expand("%appDir%") . "/../www/img_gallery/" . $gid . "/" . $file->getName();
// V produkčním módu nepřesunujeme soubory...
if (!\Nette\Environment::isProduction()) {
if ($file->move($newFilePath)) {
$gallery->resize($newFilePath, $gid, $file->getName());
$this->flashMessage("File " . $file->getName() . " was successfully moved!");
} else {
$this->flashMessage("Error while moving file " . $file->getName() . ".");
}
}
}
$this->redirect("Gallery:edit", $gid);
}
Jaké jsou možnosti, případně neřešil jste tento problém už někdo ?
Editoval Joacim (2. 9. 2015 12:23)