Skip to content

Commit

Permalink
Merge pull request #28 from d3yii2/0.9.39
Browse files Browse the repository at this point in the history
0.9.40
  • Loading branch information
uldisn authored Nov 28, 2019
2 parents 8357ef9 + 1f6a535 commit 13ddd70
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 7 deletions.
6 changes: 5 additions & 1 deletion components/DeleteAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,14 @@ class DeleteAction extends Action

public $modelName;

public function run(int $id, string $model_name): string
public function run(int $id, string $model_name = ''): string
{
Yii::$app->response->format = Response::FORMAT_JSON;

if(!$model_name){
$model_name = $this->modelName;
}

if(!Yii::$app->getModule('d3files')->disableController){
if (is_array($this->modelName) && !in_array($model_name, $this->modelName, true)) {
throw new HttpException(422, 'Can not upload file for requested model');
Expand Down
5 changes: 4 additions & 1 deletion components/DownloadAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,12 @@ class DownloadAction extends Action

public const THE_REQUESTED_FILE_DOES_NOT_EXIST = 'The requested file does not exist.';

public function run(int $id, string $model_name): void
public function run(int $id, string $model_name = ''): void
{

if(!$model_name){
$model_name = $this->modelName;
}
if(!Yii::$app->getModule('d3files')->disableController){
if (is_array($this->modelName) && !in_array($model_name, $this->modelName, true)) {
throw new HttpException(422, 'Can not upload file for requested model');
Expand Down
1 change: 1 addition & 0 deletions components/UploadAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ public function run(int $id): string
'id' => $model->id,
'file_name' => $model->file_name,
'file_model_id' => $modelM->id,
'model_name' => $postModelName
];

$hasPreview = Yii::$app->request->get('preview');
Expand Down
11 changes: 9 additions & 2 deletions views/d3files/files-list.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php

use d3yii2\d3files\widgets\D3FilesWidget;
use d3yii2\d3files\D3FilesAsset;
use yii\helpers\Url;

Expand All @@ -15,13 +16,15 @@
* @var bool $readOnly
* @var bool $hideTitle
* @var array $_params_
* @var string $uploadButtonPlacement
*/

D3FilesAsset::register($this);

$uploadUrl = Url::to([$urlPrefix . 'd3filesupload', 'id' => $model_id]);

$data = isset($hasPreview) ? 'data-type="preview"' : '';

?>

<div id="d3files-widget-<?= $model_id ?>" class="panel d3files-widget"<?= $data ?>>
Expand All @@ -38,8 +41,12 @@
</h3>
</div>
<?php
if (!$readOnly): ?>
<div class="pull-right" data-toggle="tooltip" data-title="<?php echo Yii::t('d3files', 'Upload file'); ?>">
if (!$readOnly):
$uploadBtnClass = D3FilesWidget::BUTTON_PLACEMENT_LEFT === $uploadButtonPlacement
? 'pull-left'
: 'pull-right';
?>
<div class="<?= $uploadBtnClass ?>" data-toggle="tooltip" data-title="<?php echo Yii::t('d3files', 'Upload file'); ?>">
<label class="d3files-upload-btn btn btn-success btn-xs" data-title="<?php echo Yii::t('d3files', 'Upload file'); ?>">
<input type="file" class="d3file-input" style="display: none;" data-url="<?php echo $uploadUrl; ?>"
name="<?php echo $model_name; ?>"/>
Expand Down
13 changes: 10 additions & 3 deletions views/d3files/upload.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,15 @@

use yii\helpers\Html;

/* @var $this yii\web\View */
/* @var $model d3yii2\d3files\models\D3files */
/**
* @var $this yii\web\View
* @var string $file_name
* @var int $file_model_id
* @var string $icon
* @var string $model_name
* @var string $previewButton
* @var array $previewAttrs
*/

?>
<tr data-key="<?= $id; ?>" class="d3files-row">
Expand All @@ -24,7 +31,7 @@
<td class="text-center col-xs-1">
<?= Html::a(
'<span class="glyphicon glyphicon-trash"></span>',
['d3filesdelete', 'id' => $file_model_id],
['d3filesdelete', 'id' => $file_model_id, 'model_name' => $model_name],
['class' => 'd3files-delete', 'title' => Yii::t('d3files', 'Delete')]
) ?>
</td>
Expand Down
6 changes: 6 additions & 0 deletions widgets/D3FilesWidget.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,13 @@ class D3FilesWidget extends Widget
public $actionColumn;
public $urlPrefix = '/d3files/d3files/';

public $uploadButtonPlacement = self::BUTTON_PLACEMENT_LEFT;

public const VIEW_FILES_LIST = 'files-list';

public const BUTTON_PLACEMENT_LEFT = 'left';
public const BUTTON_PLACEMENT_RIGHT = 'right';

/**
* @throws \yii\db\Exception
* @throws Exception
Expand Down Expand Up @@ -140,6 +145,7 @@ public function getViewParams(): array
'viewByExtensions' => $this->viewByExtensions,
'actionColumn' => $this->actionColumn,
'readOnly' => $this->readOnly,
'uploadButtonPlacement' => $this->uploadButtonPlacement,
];
}

Expand Down

0 comments on commit 13ddd70

Please sign in to comment.