Skip to content

Commit

Permalink
Added enableNotes option
Browse files Browse the repository at this point in the history
  • Loading branch information
anothersoftware-lv committed Mar 16, 2021
1 parent 585c03e commit 31e5a98
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 58 deletions.
2 changes: 1 addition & 1 deletion D3Files.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class D3Files extends Module
public $sharedLeftLoadings;
public $imageExtensions = ['jpg', 'gif', 'png', 'bmp'];
public $models = [];
public $enableNotes;

public function init()
{
Expand All @@ -46,5 +47,4 @@ public function getView($view)
$this->viewPath or $this->viewPath = __DIR__ . '/views';
return $this->viewPath . '/' . $view . '.php';
}

}
9 changes: 6 additions & 3 deletions assets/js/d3files.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,10 +202,12 @@ $(function () {
});

d.on("click", ".d3files-save-notes", function () {
let widget = $(this).closest(".d3files-widget");
let saveBtn = $(this);
let widget = saveBtn.closest(".d3files-widget");
let alert = widget.find(".d3files-alert");
let textarea = $(this).prev(".d3files-notes-field");
let textarea = saveBtn.prev(".d3files-notes-field");
let notes = textarea ? textarea.val() : false;
let row = saveBtn.closest("tr.d3files-row-notes");
let url;

alert.remove();
Expand All @@ -217,7 +219,8 @@ $(function () {
data: {notes: notes},
success: function (data) {
showSuccess(data, widget);
textarea.closest("tr.d3files-row-notes").hide();
row.prev('tr').find(".d3files-notes-text").text(notes);
row.hide();
},
error: function (xhr) {
showError(xhr.responseJSON, widget);
Expand Down
8 changes: 8 additions & 0 deletions components/D3Files.php
Original file line number Diff line number Diff line change
Expand Up @@ -228,4 +228,12 @@ public static function copyFilesBetweenModels(ActiveRecord $modelFrom, ActiveRec

return true;
}

/**
* @return mixed|object|null
*/
public function isNotesEnabled()
{
return Yii::$app->getModule('d3files')->enableNotes;
}
}
3 changes: 3 additions & 0 deletions messages/lv-LV/d3files.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
*/
return [
'Attachment error' => 'Pielikuma kļūda',
'Edit notes' => 'Rediģēt piezīmi',
'Cannot upload the file' => 'Failu neizdevās augšuplādēt',
'File Notes updated' => 'Faila piezīme saglabāta',
'File uploaded successfully.' => 'Fails veiksmīgi augšuplādēts',
'File not uploaded.' => 'Fails netika augšuplādēts',
'File too large' => 'Faila izmērs pārsniedz atļauto',
Expand Down Expand Up @@ -53,6 +55,7 @@
'Preview atachment' => 'Priekšskatīt pielikumu',
'Previous Attachment' => 'Iepriekšējais pielikums',
'Next Attachment' => 'Nākamais pielikums',
'Save Note' => 'Saglabāt piezīmi',
'Select attachment' => 'Izvēlies pielikumu',
'Selected attachments' => 'Izvēlēti pielikumi',
'Type ID' => 'Tips',
Expand Down
113 changes: 59 additions & 54 deletions views/d3files/_list_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,62 +21,67 @@
foreach ($fileList as $file) {
if (!D3Files::hasFileWithExtension([$file], $viewByExtensions)) {
continue;
}

?><tr><td class="col-xs-10"><?=
Html::a(
'<i class="fa fa-cloud-download text-primary"></i> ' . $file['file_name'],
Url::to([
$urlPrefix . 'd3filesdownload',
'id' => $file['file_model_id'],
'model_name' => $model_name,
]),
[
'data-title' => Yii::t('d3files', 'Download'),
'data-placement' => 'top',
'data-toggle' => 'tooltip',
'class' => 'text-primary',
]
) ?></td><td class="col-xs-1"><?php

if (isset($previewExtensions, $previewFileList) && D3Files::fileHasExtension($file, $previewExtensions)) {
echo $this->render($previewButton, compact('icon', 'file', 'previewFileList'));
}
if ($actionColumn && is_callable($actionColumn)) {
echo $actionColumn($file);
} ?></td><td class="text-center col-xs-1"><?php
if (!$readOnly) {
echo Html::a(
'<span class="glyphicon glyphicon-trash"></span>',
[
$urlPrefix . 'd3filesdelete',
'id' => $file['file_model_id'],
'model_name' => $model_name,
],
[
'data-title' => Yii::t('d3files', 'Delete'),
'data-placement' => 'top',
'data-toggle' => 'tooltip',
'class' => 'd3files-delete text-primary',
]
);
}
?></td>
<?php if (!$readOnly): ?>
<td>
<?= Html::a(
'<span class="glyphicon glyphicon-book"></span>',
'#',
[
'onclick' => 'event.preventDefault()',
'data-title' => Yii::t('d3files', 'Edit notes'),
'data-placement' => 'top',
'data-toggle' => 'tooltip',
'class' => 'd3files-edit-notes text-primary',
]
) ?>
} ?>
<tr>
<td class="col-xs-10"><?=
Html::a(
'<i class="fa fa-cloud-download text-primary"></i> ' . $file['file_name'],
Url::to([
$urlPrefix . 'd3filesdownload',
'id' => $file['file_model_id'],
'model_name' => $model_name,
]),
[
'data-title' => Yii::t('d3files', 'Download'),
'data-placement' => 'top',
'data-toggle' => 'tooltip',
'class' => 'text-primary',
]
) ?>
</td>
<?php if (!$readOnly && $enableNotes): ?>
<td class="d3files-notes-text"><?= $file['notes'] ?></td>
<td>
<?= Html::a(
'<span class="glyphicon glyphicon-book"></span>',
'#',
[
'onclick' => 'event.preventDefault()',
'data-title' => Yii::t('d3files', 'Edit notes'),
'data-placement' => 'top',
'data-toggle' => 'tooltip',
'class' => 'd3files-edit-notes text-primary',
]
) ?>
</td>
<?php endif; ?>
<td class="col-xs-1"><?php
if (isset($previewExtensions, $previewFileList) && D3Files::fileHasExtension($file, $previewExtensions)) {
echo $this->render($previewButton, compact('icon', 'file', 'previewFileList'));
}
if ($actionColumn && is_callable($actionColumn)) {
echo $actionColumn($file);
} ?>
</td>
<td class="text-center col-xs-1"><?php
if (!$readOnly) {
echo Html::a(
'<span class="glyphicon glyphicon-trash"></span>',
[
$urlPrefix . 'd3filesdelete',
'id' => $file['file_model_id'],
'model_name' => $model_name,
],
[
'data-title' => Yii::t('d3files', 'Delete'),
'data-placement' => 'top',
'data-toggle' => 'tooltip',
'class' => 'd3files-delete text-primary',
]
);
}
?>
</td>
</tr>
<?php
if (!$readOnly): ?>
Expand Down
7 changes: 7 additions & 0 deletions widgets/D3FilesWidget.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class D3FilesWidget extends D3Widget
public $readOnly = false;
// File handling controller route. If empty, then use actual controller
public $controllerRoute = '';
public $enableNotes;

/**
* @deprecated $viewByFancyBox
Expand Down Expand Up @@ -111,6 +112,11 @@ public function init(): void
$this->urlPrefix = $this->controllerRoute;
}

// Check default settting from module if not specified
if (null === $this->enableNotes) {
$this->enableNotes = D3Files::isNotesEnabled();
}

$this->initFilesList();

if (!$this->readOnly) {
Expand Down Expand Up @@ -177,6 +183,7 @@ public function getViewParams(): ?array
'readOnly' => $this->readOnly,
'uploadButtonPlacement' => $this->uploadButtonPlacement,
'allowUpload' => $this->allowUpload,
'enableNotes' => $this->enableNotes,
];
}

Expand Down

0 comments on commit 31e5a98

Please sign in to comment.