Skip to content
This repository has been archived by the owner on Jul 27, 2023. It is now read-only.

How to preload picture images into the plugin? #135

Open
khmerlove opened this issue Jan 10, 2018 · 5 comments
Open

How to preload picture images into the plugin? #135

khmerlove opened this issue Jan 10, 2018 · 5 comments

Comments

@khmerlove
Copy link

I do not know how to preload images from an existing directory into the plugin ? Please help me!!!

@alpo008
Copy link

alpo008 commented Mar 21, 2018

Hi, khmerlove, are you still need a solution?
Yesterday I had to invented one and I can share it.
Sincerely, Alex.

@cresusjpt
Copy link

please share with us

@alpo008
Copy link

alpo008 commented Aug 31, 2018

Hello @cresusjpt!
Six months ago I did it this way:
First I rendered existing photos in the hidden container .existing-photos.hidden

foreach ($model->getGalleryPhotos()->orderBy(['id' => SORT_DESC])->all() as $photo) :
...
//see the attached file
...
php endforeach;

Second on document load I moved these photos into widget container and deleted hidden:

$(document).ready(function(){
var $existingPhotos = $(".existing-photos .files");
$("#room-uploadedphotos-fileupload .files").html($existingPhotos.html());
$(".existing-photos").remove();
});

And here you can see widget settings for my case:

echo FileUploadUI::widget([
'model' => $model,
'attribute' => 'uploadedPhotos',
'url' => Url::toRoute(['photos-upload', 'id' => $model->id]),
'gallery' => false,
'fieldOptions' => [
'accept' => 'image/*'
],
'clientOptions' => [
'maxFileSize' => 2000000,
'prependFiles' => true,
'dataType' => 'json'
],
'clientEvents' => [
'fileuploaddone' => 'function(e, data) {
$(document).find(".existing-photos").remove();
var that = $(this).data("blueimp-fileupload") ||
$(this).data("fileupload"),
getFilesFromResponse = data.getFilesFromResponse ||
that.options.getFilesFromResponse,
files = getFilesFromResponse(data),
template,
deferred;
template = that._renderDownload(files);
$(".files").html(template);
$(".files").find("tr.fade").addClass("in");
}',
'fileuploadfail' => 'function(e, data) {
}',
],
]);
:
You can see the code here
Please do not hesitate to contact me if you find any unclearness.
Have a nice day.
Alex.

@cresusjpt
Copy link

cresusjpt commented Aug 31, 2018 via email

@speker2010
Copy link

From Jquery File Upload plugin's html files I got this:

    var passscans = $('#documents-files-fileupload').addClass('fileupload-processing');
        $.ajax({
            url: '{$passScansUrl}',
            dataType: 'json',
            context: passscans[0]
        }).always(function () {
            $(this).removeClass('fileupload-processing');
        }).done(function (result) {
            $(this).fileupload('option', 'done')
                .call(this, $.Event('done'), {result: result});
        });

where in $passScansUrl:
$passScansUrl = Url::toRoute(['site/get-files', 'app_id' => $model->Application->id]);

where get-files action:

public function actionGetPassScans() {
    $files = FileHelper::findFiles($directory);
    $output = [];
    foreach ($files as $file) {
        $fileName = basename($file);
        $path = '/img/temp/' . Yii::$app->session->id . DIRECTORY_SEPARATOR . $fileName;
        $output['files'][] = [
            'name' => $fileName,
            'size' => filesize($file),
            'url' => $path,
            'thumbnailUrl' => $path,
            'deleteUrl' => 'image-delete?name=' . $fileName,
            'deleteType' => 'POST',
        ];
    }
    return Json::encode($output);
}

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants