示例#1
0
 public function init()
 {
     parent::init();
     Html::addCssClass($this->htmlOptions, 'custom-dz');
     /** @var Image[] $files */
     $files = Image::find()->where(['and', 'object_id = :objectId', 'object_model_id = :modelId'], [':objectId' => $this->objectId, ':modelId' => $this->modelId])->orderBy(['sort_order' => SORT_ASC])->all();
     /** Image $file */
     foreach ($files as $file) {
         $thumbnail_src = $file->getThumbnail('80x80');
         $this->storedFiles[] = ['id' => $file->id, 'name' => $file->filename, 'file' => $file->file, 'thumbnail' => $thumbnail_src, 'description' => $file->image_description];
     }
     $params = ArrayHelper::merge(isset($this->options['params']) ? $this->options['params'] : [], ['objectId' => $this->objectId, 'modelId' => $this->modelId]);
     $this->sortable = true;
     $this->options = ArrayHelper::merge($this->options, ['acceptedFiles' => 'image/*', 'params' => $params, 'previewTemplate' => '<div class="file-row">
                     ' . Html::input('hidden', 'id[]') . Html::input('hidden', 'file[]') . '
                     <!-- This is used as the file preview template -->
                     <div>
                         <span class="preview"><img style="width: 80px; height: 80px;" data-dz-thumbnail /></span>
                     </div>
                     <div>
                         <p class="name" data-dz-name></p>
                         <div class="dz-error-message"><span data-dz-errormessage></span></div>
                     </div>
                     <div class="description">
                         ' . Html::textarea('description', '', ['style' => 'width: 100%; min-width: 80px; height: 80px;']) . '
                     </div>
                     <div>
                         <p class="size" data-dz-size></p>
                         <div class="dz-progress progress progress-striped active" role="progressbar" aria-valuemin="0" aria-valuemax="100" aria-valuenow="0">
                           <div class="progress-bar progress-bar-success" style="width:0%;" data-dz-uploadprogress></div>
                         </div>
                         <div class="dz-success-mark"><span>✔</span> OK</div>
                         <div class="dz-error-mark"><span>✘</span> ERROR</div>
                     </div>
                     <div>
                       <button data-dz-remove class="btn btn-danger delete">
                         <i class="fa fa-trash-o"></i>
                         <span>' . Yii::t('app', 'Delete') . '</span>
                       </button>
                     </div>
                   </div>', 'thumbnailWidth' => '80', 'thumbnailHeight' => '80', 'previewsContainer' => "#{$this->id}"]);
     $this->eventHandlers = ['removedfile' => 'function(file) {
             jQuery.get(
                 "' . Url::toRoute($this->removeUrl) . '",
                 {
                     "id" : jQuery(file.previewElement).find("[name=\\"id[]\\"]").val(),
                     "filename" : jQuery(file.previewElement).data("filename")
                 }
             ).done(function (data) { return data });
         }', 'success' => 'function(file, response) {
             response = jQuery.parseJSON(response);
             jQuery(file.previewElement).find("[data-dz-name]").text(response.filename);
             jQuery(file.previewElement).data("filename", response.filename);
             jQuery(file.previewElement).find("[name=\\"id[]\\"]").val(response.afterUpload.id);
             jQuery(file.previewElement).find("[name=\\"file[]\\"]").val(response.afterUpload.file);
             jQuery(file.previewElement).find(".description textarea").attr("name", "description["+response.afterUpload.id+"]");
         }', 'complete' => 'function(file) {
             jQuery(file.previewElement).removeClass("dz-processing");
         }'];
 }
示例#2
0
?>
        <?php 
echo Html::a('Удалить', ['/admin/users/delete', 'id' => $model->id, 'index' => true], ['class' => 'btn btn-danger', 'data' => ['confirm' => 'Are you sure you want to delete this item?', 'method' => 'post']]);
?>
    </h1>

    <?php 
echo DetailView::widget(['model' => $model, 'attributes' => ['id', ['attribute' => 'project_id', 'format' => 'raw', 'label' => 'Проект', 'value' => Html::a($model->project->title, ['view', 'id' => $model->project->id])], 'name', ['attribute' => 'link', 'format' => 'raw', 'value' => '<input type="text" class="user-link" onclick="select()" readonly value="' . Url::to(['/link/view', 'link' => $model->link], true) . '">'], ['attribute' => 'selected_photos', 'label' => 'Выбранные фото (' . $selected_photo_count . ')', 'format' => 'raw', 'value' => $selected_photo_names]]]);
?>

    <h3 class="page-header">
        Фото
    </h3>

    <?php 
echo DropZone::widget(['name' => 'file', 'url' => ['upload'], 'storedFiles' => [], 'eventHandlers' => ['sending' => 'function(file, xhr, data) {data.append("user_id", "' . $model->id . '");}'], 'sortable' => true, 'sortableOptions' => [], 'htmlOptions' => [], 'options' => ['dictDefaultMessage' => 'Перенесите файлы сюда...', 'acceptedFiles' => 'image/*']]);
?>

    <div class="row">
        <?php 
foreach ($photos as $photo) {
    ?>
            <div class="col-sm-4 col-md-3 photo photo-<?php 
    echo $photo->id;
    ?>
">
                <div class="panel <?php 
    echo $photo->selected ? 'panel-primary' : 'panel-default';
    ?>
 text-center panel-photo">
                    <div class="panel-heading">