From 373c2f89e5f9acf7a46a63a624408acc9d626b7f Mon Sep 17 00:00:00 2001 From: cuneytsenturk Date: Sat, 2 Feb 2019 11:15:24 +0300 Subject: [PATCH] Media show stylesheet... --- app/Http/Controllers/Common/Uploads.php | 36 ++++++++++++++++ public/css/app.css | 11 +++++ .../views/incomes/invoices/edit.blade.php | 26 +++++------- .../views/incomes/invoices/show.blade.php | 19 +-------- resources/views/partials/media/file.blade.php | 40 ++++++++++++++++++ .../views/partials/media/files.blade.php | 42 +++++++++++++++++++ routes/web.php | 1 + 7 files changed, 143 insertions(+), 32 deletions(-) create mode 100644 resources/views/partials/media/file.blade.php create mode 100644 resources/views/partials/media/files.blade.php diff --git a/app/Http/Controllers/Common/Uploads.php b/app/Http/Controllers/Common/Uploads.php index 06c1213f0..92a766b20 100644 --- a/app/Http/Controllers/Common/Uploads.php +++ b/app/Http/Controllers/Common/Uploads.php @@ -28,6 +28,42 @@ class Uploads extends Controller return response()->file($path); } + /** + * Get the specified resource. + * + * @param $id + * @return mixed + */ + public function show($id) + { + $file = false; + + $media = Media::find($id); + + // Get file path + if (!$path = $this->getPath($media)) { + return response()->json([ + 'success' => false, + 'error' => true, + 'data' => [], + 'message' => 'null', + 'html' => '', + ]); + } + + $file = $media; + + $html = view('partials.media.file', compact('file'))->render(); + + return response()->json([ + 'success' => true, + 'error' => false, + 'data' => [], + 'message' => 'null', + 'html' => $html, + ]); + } + /** * Download the specified resource. * diff --git a/public/css/app.css b/public/css/app.css index df8840fd0..ea1fb1398 100644 --- a/public/css/app.css +++ b/public/css/app.css @@ -933,3 +933,14 @@ input[type="number"] { .table-report { overflow-x: auto !important; } + +.mailbox-attachment-file-name { + white-space: nowrap; + width: 100%; + overflow: hidden; + text-overflow: ellipsis; +} + +.mailbox-attachment-download { + margin-right: 5px; +} diff --git a/resources/views/incomes/invoices/edit.blade.php b/resources/views/incomes/invoices/edit.blade.php index c62194d9d..dccd5a9de 100644 --- a/resources/views/incomes/invoices/edit.blade.php +++ b/resources/views/incomes/invoices/edit.blade.php @@ -257,27 +257,23 @@ text : '{{ trans('general.form.select.file') }}', style : 'btn-default', @if($invoice->attachment) - placeholder : 'attachment->basename; ?>' + placeholder : '{{ $invoice->attachment->basename }}' @else placeholder : '{{ trans('general.form.no_file_selected') }}' @endif }); @if($invoice->attachment) - attachment_html = ''; - attachment_html += ' '; - attachment_html += ' '; - attachment_html += ' {{ $invoice->attachment->basename }}'; - attachment_html += ' '; - attachment_html += ' '; - attachment_html += ' {!! Form::open(['id' => 'attachment-' . $invoice->attachment->id, 'method' => 'DELETE', 'url' => [url('uploads/' . $invoice->attachment->id)], 'style' => 'display:inline']) !!}'; - attachment_html += ' '; - attachment_html += ' '; - attachment_html += ' '; - attachment_html += ' {!! Form::close() !!}'; - attachment_html += ''; - - $('.fancy-file .fake-file').append(attachment_html); + $.ajax({ + url: '{{ url('uploads/' . $invoice->attachment->id . '/show') }}', + type: 'GET', + dataType: 'JSON', + success: function(json) { + if (json['success']) { + $('.fancy-file').after(json['html']); + } + } + }); @endif @if(old('item')) diff --git a/resources/views/incomes/invoices/show.blade.php b/resources/views/incomes/invoices/show.blade.php index ca230a31f..c4b8c5fa8 100644 --- a/resources/views/incomes/invoices/show.blade.php +++ b/resources/views/incomes/invoices/show.blade.php @@ -339,23 +339,8 @@ @if($invoice->attachment) - - - - {{ $invoice->attachment->basename }} - - - {!! Form::open([ - 'id' => 'attachment-' . $invoice->attachment->id, - 'method' => 'DELETE', - 'url' => [url('uploads/' . $invoice->attachment->id)], - 'style' => 'display:inline' - ]) !!} - - - - {!! Form::close() !!} - + @php $file = $invoice->attachment; @endphp + @include('partials.media.file') @endif diff --git a/resources/views/partials/media/file.blade.php b/resources/views/partials/media/file.blade.php new file mode 100644 index 000000000..2cb0c306e --- /dev/null +++ b/resources/views/partials/media/file.blade.php @@ -0,0 +1,40 @@ + diff --git a/resources/views/partials/media/files.blade.php b/resources/views/partials/media/files.blade.php new file mode 100644 index 000000000..e4ae762a2 --- /dev/null +++ b/resources/views/partials/media/files.blade.php @@ -0,0 +1,42 @@ + diff --git a/routes/web.php b/routes/web.php index 7874cb64f..eaa8031c4 100644 --- a/routes/web.php +++ b/routes/web.php @@ -4,6 +4,7 @@ Route::group(['middleware' => 'language'], function () { Route::group(['middleware' => 'auth'], function () { Route::group(['prefix' => 'uploads'], function () { Route::get('{id}', 'Common\Uploads@get'); + Route::get('{id}/show', 'Common\Uploads@show'); Route::get('{id}/download', 'Common\Uploads@download'); });