Coder Social home page Coder Social logo

devgroup-ru / yii2-dropzone Goto Github PK

View Code? Open in Web Editor NEW
11.0 20.0 13.0 22 KB

This extension provides the Dropzone integration for the Yii2 framework.

License: GNU General Public License v3.0

PHP 100.00%
yii2 dropzone file-upload drag-and-drop yii2-widgets yii2-framework dropzonejs php upload fileupload

yii2-dropzone's Introduction

Dropzone Extension for Yii 2

This extension provides the Dropzone integration for the Yii2 framework.

Installation

This extension requires Dropzone

The preferred way to install this extension is through composer.

Either run

php composer.phar require --prefer-dist devgroup/yii2-dropzone "*"

or add

"devgroup/yii2-dropzone": "*"

to the require section of your composer.json.

General Usage

use devgroup\dropzone\DropZone;

DropZone::widget(
    [
        'name' => 'file', // input name or 'model' and 'attribute'
        'url' => '', // upload url
        'storedFiles' => [], // stores files
        'eventHandlers' => [], // dropzone event handlers
        'sortable' => true, // sortable flag
        'sortableOptions' => [], // sortable options
        'htmlOptions' => [], // container html options
        'options' => [], // dropzone js options
    ]
)

you can also register devgroup\dropzone\UploadAction and devgroup\dropzone\RemoveAction actions in your controller

yii2-dropzone's People

Contributors

bethrezen avatar evgen-d avatar fps01 avatar glutaminefree avatar jarrydgoodman avatar krivochenko avatar pjacquemin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

yii2-dropzone's Issues

Usage with ActiveField

Its nice widget. But does not have support to use with ActiveField. Please add the support, because it helps in validation, labeling etc.

Incorrect processing storedFiles property.

Method addFiles() generates following JS code:

var mockFile = { name: "5", size: 0 };
dropzone_w1.emit("addedfile", mockFile);
dropzone_w1.emit("thumbnail", mockFile, "http://rudov.com/uploads/portfolio/photo/thumb/1446309929_941.jpg");
var mockFile = { name: "14", size: 0 };
dropzone_w1.emit("thumbnail", mockFile, "http://rudov.com/uploads/portfolio/photo/thumb/1446315949_866.jpg");

So just first file will be added. You shold change code of addFiles method:

        $i = 1;
        foreach ($files as $file) {
            // Create the mock file:
            $this->getView()->registerJs(
                'var mockFile' . $i . ' = { name: "' . $file['name'] . '", size: ' . $file['size'] . ' };'
            );
            // Call the default addedfile event handler
            $this->getView()->registerJs(
                $this->dropzoneName . '.emit("addedfile", mockFile' . $i . ');'
            );
            // And optionally show the thumbnail of the file:
            $this->getView()->registerJs(
                $this->dropzoneName . '.emit("thumbnail", mockFile' . $i . ', "' . $file['thumbnail'] . '");'
            );
            $i++;
        }

Ошибка в $storedFiles

Не получается отобразить несколько файлов, сохраненных ранее на сервере, используя storedFiles. Отображается только один файл.

Причина:
https://github.com/DevGroup-ru/yii2-dropzone/blob/master/DropZone.php#L52 вот этот js-код регистрируется только один раз (т.к строка не зависит от переменной $file и поэтому генерируется одинаковый $key в методе registerJs). А нужно, чтобы строка эта генерировалась для каждого файла.

how to change dictDefaultMessage

I try to change this way

<?= \zainiafzan\widget\Dropzone::widget([
                        'options' => [
                            'addRemoveLinks'    => true,
                            'url'               => 'profile',
                            'dictDefaultMessage'=> Yii::t('frontend','TEXTDROPFILE'),
                        ],

but nothing happens

htmlOptions is overwritten

Hi,

I think that there is a bug in your code.
The $htmlOptions is initialized with the dropzone class at top of DropZone.php :
$htmlOptions = [
'class' => 'dropzone',
];

When using public htmlOptions with the widget, $htmlOptions is overwritten in DropZone.php and the dropzone class option doesnt exists anymore.

You should declare the dropzone class like this in init() or in run() :
$this->htmlOptions['class'] = $this->htmlOptions['class'] . ' dropzone';

Have a nice day and thank you for your sharing.

Как кастомизировать данное решение

Прошу прощения, возможно, за глупый вопрос.
А как кастомизировать? Как мне убрать эту картинку с перетаскиванием и свои стили применить? Перекрывать css? может есть возможность о которой я не догадываюсь?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.