This gitlab repository is moving to a new Home. The new server will be running the latest version with a lot of nice features and increased performance. Thererfor you are no longer able to sign up to this gitlab server. Check https://code.dirk-benkert.de for the new server. All active repositories will be moved over.

Commit 09eae9d2 by Dirk Benkert

removed file-input plugin with dropzone.js

added multifileupload
parent 304bcbfb
......@@ -138,6 +138,30 @@ class Crud extends AbstractPlugin {
}
/**
* getter
*
* @return array
*/
public function getOptions() {
return $this->options;
}
/**
* getter
*
* @param string $key
*
* @return mixed
*/
public function getOption($key) {
if (isset($this->options[$key])) {
return $this->options[$key];
}
return null;
}
/**
* Does a CRUD delete operation
* $doNotAsk toggels the "do you really want to delete?" question, wich requires a delete.phtml
*
......@@ -214,9 +238,11 @@ class Crud extends AbstractPlugin {
* Does a CRUD save operation
* Returns ViewModel for the edit.phtml in case of invalid data or redirect
*
* @param bool $debug enable error-log output for invalid forms
*
* @return \Zend\View\Model\ViewModel
*/
public function saveEntity() {
public function saveEntity($debug = false) {
$controller = $this->getController();
$form = $this->options[self::FORM];
$persistor = $this->getPersistor();
......@@ -241,9 +267,17 @@ class Crud extends AbstractPlugin {
$form->setData($post);
if (!$form->isValid()) {
error_log(print_r($form->getData(), true));
error_log(print_r($form->getMessages(), true));
if (true === $debug) {
error_log(print_r($form->getData(), true));
error_log(print_r($form->getMessages(), true));
}
$result = false;
foreach ($form->getMessages() as $field => $messages) {
foreach ($messages as $validator => $message) {
$controller->flashMessenger()->addErrorMessage($message);
}
}
} else {
$finalData = $form->getData();
if (false === $editMode && isset($this->options[self::DEFAULT_VALUES])) {
......
......@@ -103,7 +103,7 @@ class PaginationFilterSort extends AbstractPlugin {
$this->options = $options;
$this->session = new Container($options[self::SESSION_NAMESPACE]);
if (empty($session->page)) {
if (!isset($session->page)) {
$session->page = 1;
}
......
......@@ -65,7 +65,7 @@ abstract class AbstractPersistor implements PersistorInterface {
/**
* getter
*
* @return Administration\Controller\Plugin\Crud
* @return \Administration\Controller\Plugin\Crud
*/
public function getService() {
return $this->service;
......@@ -74,7 +74,7 @@ abstract class AbstractPersistor implements PersistorInterface {
/**
* setter
*
* @param Administration\Controller\Plugin\Crud $service
* @param \Administration\Controller\Plugin\Crud $service
*/
public function setService($service) {
$this->service = $service;
......
......@@ -18,6 +18,11 @@ return array(
'Files' => 'Application\Controller\FilesController',
),
),
'controller_plugins' => array(
'invokables' => array(
'FlashmessagePersistor' => 'Application\Controller\Plugin\FlashmessagePersistor',
)
),
'service_manager' => array(
'aliases' => array(
'translator' => 'MvcTranslator',
......
msgid ""
msgstr ""
"Project-Id-Version: share-application\n"
"POT-Creation-Date: 2015-09-14 09:30+0200\n"
"PO-Revision-Date: 2015-09-14 09:32+0200\n"
"POT-Creation-Date: 2015-09-15 08:05+0200\n"
"PO-Revision-Date: 2015-09-15 08:05+0200\n"
"Last-Translator: \n"
"Language-Team: \n"
"Language: de\n"
......@@ -23,30 +23,30 @@ msgstr "Profil gespeichert"
msgid "Profil could not be saved."
msgstr "Das Profil konnte nicht gespeichert werden."
#: src/Application/Controller/JsonController.php:135
#: src/Application/Controller/JsonController.php:142
msgid "Language"
msgstr "Sprache"
#: src/Application/Controller/JsonController.php:157
#: src/Application/Controller/JsonController.php:164
msgid "Administration"
msgstr "Administration"
#: src/Application/Controller/JsonController.php:161
#: src/Application/Controller/JsonController.php:168
msgid "User"
msgstr "Benutzer"
#: src/Application/Controller/JsonController.php:175
#: src/Application/Controller/JsonController.php:182
msgid "<i class=\"fa fa-user\"></i> Profil"
msgstr "<i class=\"fa fa-user\"></i> Profil"
#: src/Application/Controller/JsonController.php:179
#: src/Application/Controller/JsonController.php:186
msgid "logout"
msgstr "<i class=\"fa fa-lock\"></i> abmelden"
#: src/Application/Form/FileForm.php:116
#: src/Application/Form/FolderForm.php:125
#: view/application/dialog/newuser.phtml:66
#: view/application/files/edit.phtml:60 view/application/folder/edit.phtml:64
#: view/application/files/edit.phtml:64 view/application/folder/edit.phtml:64
#: view/application/index/profile.phtml:86
msgid "save"
msgstr "speichern"
......@@ -135,7 +135,7 @@ msgid "Add user"
msgstr "Benutzer hinzufügen"
#: view/application/dialog/newuser.phtml:65
#: view/application/files/edit.phtml:59 view/application/folder/edit.phtml:63
#: view/application/files/edit.phtml:63 view/application/folder/edit.phtml:63
msgid "cancel"
msgstr "abbrechen"
......@@ -144,10 +144,10 @@ msgid "Do you really want do delete this file?"
msgstr "Möchten Sie die Datei wirklich löschen?"
#: view/application/files/edit.phtml:26
msgid "Upload file"
msgstr "Datei hochladen"
msgid "Upload files"
msgstr "Dateien hochladen"
#: view/application/files/edit.phtml:32
#: view/application/files/edit.phtml:34
msgid ""
"The upload of larger files may take some time, depending on your internet "
"connection. Do not close this window!"
......
......@@ -57,9 +57,9 @@ class FilesController extends ControllerAbstract {
//'%s (%s) added.', // success message on $editMode = false
//'%s (%s) saved.', // success message on $editMode = true
//'%s (%s) deleted.', // success message on deletion
'File added.', // success message on $editMode = false
'File saved.', // success message on $editMode = true
'File deleted.', // success message on deletion
'File (%s) added.', // success message on $editMode = false
'File (%s) saved.', // success message on $editMode = true
'File (%s) deleted.', // success message on deletion
);
/**
......@@ -86,6 +86,8 @@ class FilesController extends ControllerAbstract {
* @return \Zend\View\Model\ViewModel
*/
public function editAction() {
$messages = $this->flashMessenger()->getMessages();
$plugin = $this->Crud();
$plugin->setOptions($this->getCrudOptions());
......@@ -110,6 +112,11 @@ class FilesController extends ControllerAbstract {
* @return \Zend\View\Model\ViewModel
*/
public function saveAction() {
// save action on files controller is called multiple times for multifile upload so
// fetch and re-add messages on flashmessenger
$persistor = $this->FlashmessagePersistor();
$persistor->keepMessages();
$plugin = $this->Crud();
$plugin->setOptions($this->getCrudOptions());
......@@ -168,7 +175,7 @@ class FilesController extends ControllerAbstract {
),
Crud::ID_COLUMN => 'id',
Crud::FORM => new FileForm($this->getServiceLocator(), $editMode, $folderId),
Crud::UPLOAD_ELEMENT_NAME => 'upload',
Crud::UPLOAD_ELEMENT_NAME => 'file',
Crud::ROUTE => array(
'files/index',
array('folder_id' => $folderId),
......@@ -176,7 +183,7 @@ class FilesController extends ControllerAbstract {
),
Crud::EDIT_TEMPLATE => 'application/files/edit.phtml',
Crud::MESSAGES => $this->message,
//Plugin\Crud::REPLACEMENTS => array('email'),
Crud::REPLACEMENTS => array('name'),
);
}
}
<?php
/**
* Dirk Benkert (https://www.dirk-benkert.de/)
*
* @link https://gitlab.dirk-benkert.de/zf2/share for the canonical source repository
* @copyright Copyright (c) 2015 Dirk Benkert (https://www.dirk-benkert.de)
* @license Apache License Version 2.0
*
* Copyright 2015 Dirk Benkert
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
namespace Application\Controller\Plugin;
use Zend\Mvc\Controller\Plugin\AbstractPlugin;
use Zend\Mvc\Controller\Plugin\FlashMessenger;
use Application\Util\Text;
/**
* Controller plugin for CRUD operations
*
* @package Administration_Controller_Plugin
* @author Dirk Benkert <mail@dirk-benkert.de>
* @copyright Copyright (c) 2015 Dirk Benkert
*/
class FlashmessagePersistor extends AbstractPlugin {
protected $namespaces = array(
FlashMessenger::NAMESPACE_ERROR,
FlashMessenger::NAMESPACE_SUCCESS,
FlashMessenger::NAMESPACE_WARNING,
FlashMessenger::NAMESPACE_INFO,
);
public function keepMessages() {
$flash = $this->getController()->flashMessenger();
foreach ($this->namespaces as $namespace) {
if ($flash->hasMessages($namespace)) {
$messages = $flash->getMessages($namespace);
$flash->clearMessages($namespace);
foreach ($messages as $message) {
$flash->addMessage($message, $namespace);
}
}
}
}
}
......@@ -23,6 +23,7 @@
namespace Application\CrudPersistor;
use Application\Service\Path;
use Administration\Controller\Plugin\Crud;
/**
* Persists a file (entity and uploaded file in ./data/files/)
......@@ -62,10 +63,11 @@ class File extends \Administration\CrudPersistor\Entity {
$identity = $this->getService()->getController()->getIdentity();
$userEntity = $this->getService()->getController()->getEntityManager()->find('Application\Entity\User', $identity->id);
$fileinputs = $this->getService()->getOption(Crud::UPLOAD_ELEMENT_NAME);
$mappedData = array(
'name' => $data['upload']['name'],
'size' => $data['upload']['size'],
'type' => $data['upload']['type'],
'name' => $data[$fileinputs[0]]['name'],
'size' => $data[$fileinputs[0]]['size'],
'type' => $data[$fileinputs[0]]['type'],
'created' => time(),
'path' => $this->saveFile($data),
'user' => $userEntity,
......@@ -90,16 +92,17 @@ class File extends \Administration\CrudPersistor\Entity {
//$basePath = $config['share-application']['physical-path'];
//$path = rtrim($basePath, '/') . DIRECTORY_SEPARATOR . $data['folder']->label . DIRECTORY_SEPARATOR . $data['upload']['name'];
$fileinputs = $this->getService()->getOption(Crud::UPLOAD_ELEMENT_NAME);
$pathService = new Path($this->getService()->getController()->getServiceLocator());
$path = $pathService->getFilePath($data['folder']->label, $data['upload']['name']);
$path = $pathService->getFilePath($data['folder']->label, $data[$fileinputs[0]]['name']);
if (!is_dir(dirname($path))) {
mkdir(dirname($path));
chmod(dirname($path), 0777);
}
move_uploaded_file($data['upload']['tmp_name'], $path);
move_uploaded_file($data[$fileinputs[0]]['tmp_name'], $path);
chmod($path, 0777);
return $path;
......
......@@ -99,7 +99,7 @@ class FileForm extends AbstractForm {
));
$this->add(array(
'name' => 'upload',
'name' => 'file',
'attributes' => array(
'type' => 'file',
),
......@@ -160,7 +160,7 @@ class FileForm extends AbstractForm {
$path
);
$inputFilter->add($factory->createInput(array(
'name' => 'upload',
'name' => 'file',
'filters' => array(
array('name' => 'StripTags'),
array('name' => 'StringTrim'),
......
......@@ -79,6 +79,7 @@ class AlertBox extends AbstractHelper {
*/
public function render() {
$html = '';
$flash = $this->getView()->flashMessenger();
$flash->setMessageOpenFormat('<div%s>
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">
......@@ -88,9 +89,16 @@ class AlertBox extends AbstractHelper {
->setMessageSeparatorString('</li><li>')
->setMessageCloseString('</li></ul></div>');
$html .= $flash->render('error', array('alert', 'alert-dismissible', 'alert-danger', 'autodismiss'));
$html .= $flash->render('info', array('alert', 'alert-dismissible', 'alert-info', 'autodismiss'));
//$html .= $flash->renderCurrent('error', array('alert', 'alert-dismissible', 'alert-danger'));
$html .= $flash->render('error', array('alert', 'alert-dismissible', 'alert-danger'));
//$html .= $flash->renderCurrent('info', array('alert', 'alert-dismissible', 'alert-info'));
$html .= $flash->render('info', array('alert', 'alert-dismissible', 'alert-info'));
//$html .= $flash->renderCurrent('default', array('alert', 'alert-dismissible', 'alert-warning', 'autodismiss'));
$html .= $flash->render('default', array('alert', 'alert-dismissible', 'alert-warning', 'autodismiss'));
//$html .= $flash->renderCurrent('success', array('alert', 'alert-dismissible', 'alert-success', 'autodismiss'));
$html .= $flash->render('success', array('alert', 'alert-dismissible', 'alert-success', 'autodismiss'));
return sprintf('
......
......@@ -23,40 +23,46 @@
?>
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<h4 class="modal-title" id="myModalLabel"><?php echo $this->translate('Upload file'); ?></h4>
<h4 class="modal-title" id="myModalLabel"><?php echo $this->translate('Upload files'); ?></h4>
</div>
<form method="post" action="<?php echo $this->url('application/default', array('controller' => 'files', 'action' => 'save')); ?>">
<div class="modal-body">
<div class="form-group">
<div class="col-sm-8 col-sm-offset-4">
<p><?php echo $this->translate('The upload of larger files may take some time, depending on your internet connection. Do not close this window!'); ?></p>
</div>
</div>
<?php
$form->prepare();
echo $this->formElement($form->get('id'));
echo $this->formElement($form->get('csrf'));
echo $this->formElement($form->get('folder'));
?>
<?php
$element = $form->get('upload');
$messages = $element->getMessages();
$errorClass = '';
$errorMessages = '';
<div class="mod modFile">
<div class="inner">
<form method="post" id="uploadForm" action="<?php echo $this->url('application/default', array('controller' => 'files', 'action' => 'save')); ?>">
<div class="modal-body">
<!-- <div class="form-group">
<div class="col-sm-8 col-sm-offset-4">
<p><?php echo $this->translate('The upload of larger files may take some time, depending on your internet connection. Do not close this window!'); ?></p>
</div>
</div> -->
<?php
$form->prepare();
echo $this->formElement($form->get('id'));
echo $this->formElement($form->get('csrf'));
echo $this->formElement($form->get('folder'));
?>
<?php
$element = $form->get('file');
$messages = $element->getMessages();
$errorClass = '';
$errorMessages = '';
if (!empty($messages)) {
$errorClass = 'error';
$errorMessages = sprintf('%s', $this->formElementErrors($element)
);
}
?>
<div class="form-group <?php echo $errorClass; ?>">
<?php echo $errorMessages; ?>
<input id="input-id" name="upload" type="file" class="file" data-preview-file-type="text">
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal"><?php echo $this->translate('cancel'); ?></button>
<button type="submit" class="btn btn-primary" data-submitmode="ajax"><?php echo $this->translate('save'); ?></button>
if (!empty($messages)) {
$errorClass = 'error';
$errorMessages = sprintf('%s', $this->formElementErrors($element)
);
}
?>
<div class="form-group <?php echo $errorClass; ?>">
<?php echo $errorMessages; ?>
<div class="dropzone" id="my-awesome-dropzone"></div>
<div class="dropzone-previews"></div>
<!-- <input id="input-id" name="upload" type="file" class="file" data-preview-file-type="text"> -->
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal"><?php echo $this->translate('cancel'); ?></button>
<button type="submit" id="submitFile" class="btn btn-primary"><?php echo $this->translate('save'); ?></button>
</div>
</form>
</div>
</form>
\ No newline at end of file
</div>
\ No newline at end of file
......@@ -29,15 +29,14 @@
<meta name="viewport" content="width=device-width">
<meta name="format-detection" content="telephone=no">
<link rel="stylesheet" href="<?php echo $this->basePath('resources/css/app.min.css'); ?>">
<link rel="stylesheet" href="<?php echo $this->basePath('resources/css/app.css'); ?>">
<link rel="stylesheet" href="<?php echo $this->basePath('resources/fonts/bonvenocf-light/stylesheet.css'); ?>">
<link rel="stylesheet" href="<?php echo $this->basePath('resources/fonts/opensans_light_macroman/stylesheet.css'); ?>">
<link rel="stylesheet" href="<?php echo $this->basePath('resources/fonts/opensans_regular_macroman/stylesheet.css'); ?>">
<link rel="stylesheet" href="<?php echo $this->basePath('resources/css/library/fileinput.min.css'); ?>">
<script type="text/javascript" src="<?php echo $this->basePath('resources/js/library/modernizr.js'); ?>"></script>
<script type="text/javascript" src="<?php echo $this->basePath('resources/js/library/require.js'); ?>" data-main="<?php echo $this->basePath('resources/js/jasapp.min.js'); ?>"></script>
<script type="text/javascript" src="<?php echo $this->basePath('resources/js/library/require.js'); ?>" data-main="<?php echo $this->basePath('resources/js/jasapp.js'); ?>"></script>
</head>
<?php
$locale = $this->plugin('translate')->getTranslator()->getLocale();
......
......@@ -10208,3 +10208,63 @@ embed {
.modUserNew .dropdown-content .item:hover {
background-color: #cccccc;
}
/**
* Dirk Benkert (https://www.dirk-benkert.de/)
*
* @link https://gitlab.dirk-benkert.de/zf2/share for the canonical source repository
* @copyright Copyright (c) 2015 Dirk Benkert (https://www.dirk-benkert.de)
* @license Apache License Version 2.0
*
* Copyright 2015 Dirk Benkert
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
.modFile .inner {
min-height: 150px;
}
.modFile .dz-message {
border: 1px solid #cccccc;
border-radius: 4px;
padding: 10px;
text-align: center;
font-size: 1.25em;
}
.modFile .dz-message:hover {
background-color: #dddddd;
cursor: pointer;
}
.modFile .dz-preview {
width: 180px;
background-color: #fefefe;
border-radius: 4px;
padding: 5px;
display: inline-block;
position: relative;
}
.modFile .dz-preview .progress {
margin: 0 25px 0 0;
padding: 0;
}
.modFile .dz-remove {
color: #a94442;
background-color: #fff;
font-size: 2em !important;
position: absolute;
bottom: 0px;
right: 4px;
}
.modFile .dropzone-previews {
max-height: 250px;
overflow-y: scroll;
margin-top: 10px;
}
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
/**
*
* manually modified file, do not Update with new version of dropzone.js
*
* check line 444
*
*/
;(function(){
/**
* Require the module at `name`.
*
* @param {String} name
* @return {Object} exports
* @api public
*/
function require(name) {
var module = require.modules[name];
if (!module) throw new Error('failed to require "' + name + '"');
if (!('exports' in module) && typeof module.definition === 'function') {
module.client = module.component = true;
module.definition.call(this, module.exports = {}, module);
delete module.definition;
}
return module.exports;
}
/**
* Registered modules.
*/
require.modules = {};
/**
* Register module at `name` with callback `definition`.
*
* @param {String} name
* @param {Function} definition
* @api private
*/
require.register = function (name, definition) {
require.modules[name] = {
definition: definition
};
};
/**
* Define a module's exports immediately with `exports`.
*
* @param {String} name
* @param {Generic} exports
* @api private
*/
require.define = function (name, exports) {
require.modules[name] = {
exports: exports
};
};
require.register("component~emitter@1.1.2", function (exports, module) {
/**
* Expose `Emitter`.
*/
module.exports = Emitter;
/**
* Initialize a new `Emitter`.
*
* @api public
*/
function Emitter(obj) {
if (obj) return mixin(obj);
};
/**
* Mixin the emitter properties.
*
* @param {Object} obj
* @return {Object}
* @api private
*/
function mixin(obj) {
for (var key in Emitter.prototype) {
obj[key] = Emitter.prototype[key];
}
return obj;
}
/**
* Listen on the given `event` with `fn`.
*
* @param {String} event
* @param {Function} fn
* @return {Emitter}
* @api public
*/
Emitter.prototype.on =
Emitter.prototype.addEventListener = function(event, fn){
this._callbacks = this._callbacks || {};
(this._callbacks[event] = this._callbacks[event] || [])
.push(fn);
return this;
};
/**
* Adds an `event` listener that will be invoked a single
* time then automatically removed.
*
* @param {String} event
* @param {Function} fn
* @return {Emitter}
* @api public
*/
Emitter.prototype.once = function(event, fn){
var self = this;
this._callbacks = this._callbacks || {};
function on() {
self.off(event, on);
fn.apply(this, arguments);
}
on.fn = fn;
this.on(event, on);
return this;
};
/**
* Remove the given callback for `event` or all
* registered callbacks.
*
* @param {String} event
* @param {Function} fn
* @return {Emitter}
* @api public
*/
Emitter.prototype.off =
Emitter.prototype.removeListener =
Emitter.prototype.removeAllListeners =
Emitter.prototype.removeEventListener = function(event, fn){
this._callbacks = this._callbacks || {};
// all
if (0 == arguments.length) {
this._callbacks = {};
return this;
}
// specific event
var callbacks = this._callbacks[event];
if (!callbacks) return this;
// remove all handlers
if (1 == arguments.length) {
delete this._callbacks[event];
return this;
}
// remove specific handler
var cb;
for (var i = 0; i < callbacks.length; i++) {
cb = callbacks[i];
if (cb === fn || cb.fn === fn) {
callbacks.splice(i, 1);
break;
}
}
return this;
};
/**
* Emit `event` with the given args.
*
* @param {String} event