From 373c2f89e5f9acf7a46a63a624408acc9d626b7f Mon Sep 17 00:00:00 2001 From: cuneytsenturk Date: Sat, 2 Feb 2019 11:15:24 +0300 Subject: [PATCH 1/5] 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'); }); From 18e381f095849f0c4e837687971a5f5f7cedd979 Mon Sep 17 00:00:00 2001 From: cuneytsenturk Date: Sat, 2 Feb 2019 11:21:05 +0300 Subject: [PATCH 2/5] updates common uploads show --- app/Listeners/Updates/V13/Version1311.php | 62 +++++++++++++++++++++++ app/Providers/EventServiceProvider.php | 1 + 2 files changed, 63 insertions(+) create mode 100644 app/Listeners/Updates/V13/Version1311.php diff --git a/app/Listeners/Updates/V13/Version1311.php b/app/Listeners/Updates/V13/Version1311.php new file mode 100644 index 000000000..114165eb8 --- /dev/null +++ b/app/Listeners/Updates/V13/Version1311.php @@ -0,0 +1,62 @@ +check($event)) { + return; + } + + $this->updatePermissions(); + + // Update database + Artisan::call('migrate', ['--force' => true]); + } + + protected function updatePermissions() + { + $permissions = []; + + // Common Uploads + $permissions[] = Permission::firstOrCreate([ + 'name' => 'read-common-uploads', + 'display_name' => 'Read Common Uploads', + 'description' => 'Read Common Uploads', + ]); + + // Attach permission to roles + $roles = Role::all(); + + foreach ($roles as $role) { + $allowed = ['admin', 'manager']; + + if (!in_array($role->name, $allowed)) { + continue; + } + + foreach ($permissions as $permission) { + $role->attachPermission($permission); + } + } + } +} diff --git a/app/Providers/EventServiceProvider.php b/app/Providers/EventServiceProvider.php index 86267942b..b5732a2fa 100644 --- a/app/Providers/EventServiceProvider.php +++ b/app/Providers/EventServiceProvider.php @@ -33,6 +33,7 @@ class EventServiceProvider extends ServiceProvider 'App\Listeners\Updates\V13\Version135', 'App\Listeners\Updates\V13\Version138', 'App\Listeners\Updates\V13\Version139', + 'App\Listeners\Updates\V13\Version1311', ], 'Illuminate\Auth\Events\Login' => [ 'App\Listeners\Auth\Login', From d4b5861120d98a3f3b563b365ebdcdee969725be Mon Sep 17 00:00:00 2001 From: cuneytsenturk Date: Sat, 2 Feb 2019 14:02:26 +0300 Subject: [PATCH 3/5] all media edit and show page --- app/Http/Controllers/Common/Uploads.php | 9 ++- database/seeds/Roles.php | 3 +- resources/views/auth/users/edit.blade.php | 37 +++++----- .../views/common/companies/edit.blade.php | 35 +++++----- resources/views/common/items/edit.blade.php | 37 +++++----- .../views/customers/profile/edit.blade.php | 35 +++++----- resources/views/expenses/bills/edit.blade.php | 29 ++++---- resources/views/expenses/bills/show.blade.php | 19 +----- .../views/expenses/payments/edit.blade.php | 35 +++++----- .../views/expenses/vendors/edit.blade.php | 29 ++++---- .../views/incomes/invoices/edit.blade.php | 3 + .../views/incomes/revenues/edit.blade.php | 35 +++++----- resources/views/partials/media/file.blade.php | 6 +- .../views/partials/media/files.blade.php | 4 +- .../views/settings/settings/edit.blade.php | 68 ++++++++----------- .../views/wizard/companies/edit.blade.php | 30 ++++---- 16 files changed, 196 insertions(+), 218 deletions(-) diff --git a/app/Http/Controllers/Common/Uploads.php b/app/Http/Controllers/Common/Uploads.php index 92a766b20..ae522b7a3 100644 --- a/app/Http/Controllers/Common/Uploads.php +++ b/app/Http/Controllers/Common/Uploads.php @@ -34,9 +34,14 @@ class Uploads extends Controller * @param $id * @return mixed */ - public function show($id) + public function show($id, Request $request) { $file = false; + $column_name = 'attachment'; + + if ($request->has('column_name')) { + $column_name = $request->get('column_name'); + } $media = Media::find($id); @@ -53,7 +58,7 @@ class Uploads extends Controller $file = $media; - $html = view('partials.media.file', compact('file'))->render(); + $html = view('partials.media.file', compact('file', 'column_name'))->render(); return response()->json([ 'success' => true, diff --git a/database/seeds/Roles.php b/database/seeds/Roles.php index 088d369ac..3c7a0b8be 100644 --- a/database/seeds/Roles.php +++ b/database/seeds/Roles.php @@ -36,7 +36,7 @@ class Roles extends Seeder 'common-companies' => 'c,r,u,d', 'common-import' => 'c', 'common-items' => 'c,r,u,d', - 'common-uploads' => 'd', + 'common-uploads' => 'r,d', 'common-notifications' => 'c,r,u,d', 'incomes-invoices' => 'c,r,u,d', 'incomes-revenues' => 'c,r,u,d', @@ -76,6 +76,7 @@ class Roles extends Seeder 'common-companies' => 'c,r,u,d', 'common-import' => 'c', 'common-items' => 'c,r,u,d', + 'common-uploads' => 'r', 'common-notifications' => 'c,r,u,d', 'incomes-invoices' => 'c,r,u,d', 'incomes-revenues' => 'c,r,u,d', diff --git a/resources/views/auth/users/edit.blade.php b/resources/views/auth/users/edit.blade.php index 0b8bd9b5f..d2e081b6f 100644 --- a/resources/views/auth/users/edit.blade.php +++ b/resources/views/auth/users/edit.blade.php @@ -86,31 +86,30 @@ text : '{{ trans('general.form.select.file') }}', style : 'btn-default', @if($user->picture) - placeholder : 'picture->basename; ?>' + placeholder : '{{ $user->picture->basename }}' @else placeholder : '{{ trans('general.form.no_file_selected') }}' @endif }); @if($user->picture) - picture_html = ''; - picture_html += ' '; - picture_html += ' '; - picture_html += ' {{ $user->picture->basename }}'; - picture_html += ' '; - picture_html += ' '; - picture_html += ' {!! Form::open(['id' => 'picture-' . $user->picture->id, 'method' => 'DELETE', 'url' => [url('uploads/' . $user->picture->id)], 'style' => 'display:inline']) !!}'; - picture_html += ' '; - picture_html += ' '; - picture_html += ' '; - picture_html += ' {!! Form::close() !!}'; - picture_html += ''; - - $('.fancy-file .fake-file').append(picture_html); - - $(document).on('click', '#remove-picture', function (e) { - confirmDelete("#picture-{!! $user->picture->id !!}", "{!! trans('general.attachment') !!}", "{!! trans('general.delete_confirm', ['name' => '' . $user->picture->basename . '', 'type' => strtolower(trans('general.attachment'))]) !!}", "{!! trans('general.cancel') !!}", "{!! trans('general.delete') !!}"); - }); + $.ajax({ + url: '{{ url('uploads/' . $user->picture->id . '/show') }}', + type: 'GET', + data: {column_name: 'picture'}, + dataType: 'JSON', + success: function(json) { + if (json['success']) { + $('.fancy-file').after(json['html']); + } + } + }); + + @permission('delete-common-uploads') + $(document).on('click', '#remove-picture', function (e) { + confirmDelete("#picture-{!! $user->picture->id !!}", "{!! trans('general.attachment') !!}", "{!! trans('general.delete_confirm', ['name' => '' . $user->picture->basename . '', 'type' => strtolower(trans('general.attachment'))]) !!}", "{!! trans('general.cancel') !!}", "{!! trans('general.delete') !!}"); + }); + @endpermission @endif @endif diff --git a/resources/views/common/companies/edit.blade.php b/resources/views/common/companies/edit.blade.php index 29defd177..54d424874 100644 --- a/resources/views/common/companies/edit.blade.php +++ b/resources/views/common/companies/edit.blade.php @@ -63,31 +63,30 @@ text : '{{ trans('general.form.select.file') }}', style : 'btn-default', @if($company->company_logo) - placeholder : 'company_logo->basename; ?>' + placeholder : '{{ $company->company_logo->basename }}' @else placeholder : '{{ trans('general.form.no_file_selected') }}' @endif }); @if($company->company_logo) - attachment_html = ''; - attachment_html += ' '; - attachment_html += ' '; - attachment_html += ' {{ $company->company_logo->basename }}'; - attachment_html += ' '; - attachment_html += ' '; - attachment_html += ' {!! Form::open(['id' => 'attachment-' . $company->company_logo->id, 'method' => 'DELETE', 'url' => [url('uploads/' . $company->company_logo->id)], 'style' => 'display:inline']) !!}'; - attachment_html += ' '; - attachment_html += ' '; - attachment_html += ' '; - attachment_html += ' {!! Form::close() !!}'; - attachment_html += ''; + $.ajax({ + url: '{{ url('uploads/' . $company->company_logo->id . '/show') }}', + type: 'GET', + data: {column_name: 'attachment'}, + dataType: 'JSON', + success: function(json) { + if (json['success']) { + $('.fancy-file').after(json['html']); + } + } + }); - $('.fancy-file .fake-file').append(attachment_html); - - $(document).on('click', '#remove-attachment', function (e) { - confirmDelete("#attachment-{!! $company->company_logo->id !!}", "{!! trans('general.attachment') !!}", "{!! trans('general.delete_confirm', ['name' => '' . $company->company_logo->basename . '', 'type' => strtolower(trans('general.attachment'))]) !!}", "{!! trans('general.cancel') !!}", "{!! trans('general.delete') !!}"); - }); + @permission('delete-common-uploads') + $(document).on('click', '#remove-attachment', function (e) { + confirmDelete("#attachment-{!! $company->company_logo->id !!}", "{!! trans('general.attachment') !!}", "{!! trans('general.delete_confirm', ['name' => '' . $company->company_logo->basename . '', 'type' => strtolower(trans('general.attachment'))]) !!}", "{!! trans('general.cancel') !!}", "{!! trans('general.delete') !!}"); + }); + @endpermission @endif }); diff --git a/resources/views/common/items/edit.blade.php b/resources/views/common/items/edit.blade.php index 3ecf81db1..2403c6b27 100644 --- a/resources/views/common/items/edit.blade.php +++ b/resources/views/common/items/edit.blade.php @@ -110,31 +110,30 @@ text : '{{ trans('general.form.select.file') }}', style : 'btn-default', @if($item->picture) - placeholder : 'picture->basename; ?>' + placeholder : '{{ $item->picture->basename }}' @else placeholder : '{{ trans('general.form.no_file_selected') }}' @endif }); @if($item->picture) - picture_html = ''; - picture_html += ' '; - picture_html += ' '; - picture_html += ' {{ $item->picture->basename }}'; - picture_html += ' '; - picture_html += ' '; - picture_html += ' {!! Form::open(['id' => 'picture-' . $item->picture->id, 'method' => 'DELETE', 'url' => [url('uploads/' . $item->picture->id)], 'style' => 'display:inline']) !!}'; - picture_html += ' '; - picture_html += ' '; - picture_html += ' '; - picture_html += ' {!! Form::close() !!}'; - picture_html += ''; - - $('.fancy-file .fake-file').append(picture_html); - - $(document).on('click', '#remove-picture', function (e) { - confirmDelete("#picture-{!! $item->picture->id !!}", "{!! trans('general.attachment') !!}", "{!! trans('general.delete_confirm', ['name' => '' . $item->picture->basename . '', 'type' => strtolower(trans('general.attachment'))]) !!}", "{!! trans('general.cancel') !!}", "{!! trans('general.delete') !!}"); - }); + $.ajax({ + url: '{{ url('uploads/' . $item->picture->id . '/show') }}', + type: 'GET', + data: {column_name: 'picture'}, + dataType: 'JSON', + success: function(json) { + if (json['success']) { + $('.fancy-file').after(json['html']); + } + } + }); + + @permission('delete-common-uploads') + $(document).on('click', '#remove-picture', function (e) { + confirmDelete("#picture-{!! $item->picture->id !!}", "{!! trans('general.attachment') !!}", "{!! trans('general.delete_confirm', ['name' => '' . $item->picture->basename . '', 'type' => strtolower(trans('general.attachment'))]) !!}", "{!! trans('general.cancel') !!}", "{!! trans('general.delete') !!}"); + }); + @endpermission @endif }); diff --git a/resources/views/customers/profile/edit.blade.php b/resources/views/customers/profile/edit.blade.php index ba5464bcf..1df388a87 100644 --- a/resources/views/customers/profile/edit.blade.php +++ b/resources/views/customers/profile/edit.blade.php @@ -64,31 +64,30 @@ text : '{{ trans('general.form.select.file') }}', style : 'btn-default', @if($user->picture) - placeholder : 'picture->basename; ?>' + placeholder : '{{ $user->picture->basename }}' @else placeholder : '{{ trans('general.form.no_file_selected') }}' @endif }); @if($user->picture) - picture_html = ''; - picture_html += ' '; - picture_html += ' '; - picture_html += ' {{ $user->picture->basename }}'; - picture_html += ' '; - picture_html += ' '; - picture_html += ' {!! Form::open(['id' => 'picture-' . $user->picture->id, 'method' => 'DELETE', 'url' => [url('uploads/' . $user->picture->id)], 'style' => 'display:inline']) !!}'; - picture_html += ' '; - picture_html += ' '; - picture_html += ' '; - picture_html += ' {!! Form::close() !!}'; - picture_html += ''; + $.ajax({ + url: '{{ url('uploads/' . $user->picture->id . '/show') }}', + type: 'GET', + data: {column_name: 'picture'}, + dataType: 'JSON', + success: function(json) { + if (json['success']) { + $('.fancy-file').after(json['html']); + } + } + }); - $('.fancy-file .fake-file').append(picture_html); - - $(document).on('click', '#remove-picture', function (e) { - confirmDelete("#picture-{!! $user->picture->id !!}", "{!! trans('general.attachment') !!}", "{!! trans('general.delete_confirm', ['name' => '' . $user->picture->basename . '', 'type' => strtolower(trans('general.attachment'))]) !!}", "{!! trans('general.cancel') !!}", "{!! trans('general.delete') !!}"); - }); + @permission('delete-common-uploads') + $(document).on('click', '#remove-picture', function (e) { + confirmDelete("#picture-{!! $user->picture->id !!}", "{!! trans('general.attachment') !!}", "{!! trans('general.delete_confirm', ['name' => '' . $user->picture->basename . '', 'type' => strtolower(trans('general.attachment'))]) !!}", "{!! trans('general.cancel') !!}", "{!! trans('general.delete') !!}"); + }); + @endpermission @endif }); diff --git a/resources/views/expenses/bills/edit.blade.php b/resources/views/expenses/bills/edit.blade.php index 736cdf228..c90eaa2a8 100644 --- a/resources/views/expenses/bills/edit.blade.php +++ b/resources/views/expenses/bills/edit.blade.php @@ -257,27 +257,24 @@ text : '{{ trans('general.form.select.file') }}', style : 'btn-default', @if($bill->attachment) - placeholder : 'attachment->basename; ?>' + placeholder : '{{ $bill->attachment->basename }}' @else placeholder : '{{ trans('general.form.no_file_selected') }}' @endif }); @if($bill->attachment) - attachment_html = ''; - attachment_html += ' '; - attachment_html += ' '; - attachment_html += ' {{ $bill->attachment->basename }}'; - attachment_html += ' '; - attachment_html += ' '; - attachment_html += ' {!! Form::open(['id' => 'attachment-' . $bill->attachment->id, 'method' => 'DELETE', 'url' => [url('uploads/' . $bill->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/' . $bill->attachment->id . '/show') }}', + type: 'GET', + data: {column_name: 'attachment'}, + dataType: 'JSON', + success: function(json) { + if (json['success']) { + $('.fancy-file').after(json['html']); + } + } + }); @endif @if(old('item')) @@ -285,11 +282,13 @@ @endif }); + @permission('delete-common-uploads') @if($bill->attachment) $(document).on('click', '#remove-attachment', function (e) { confirmDelete("#attachment-{!! $bill->attachment->id !!}", "{!! trans('general.attachment') !!}", "{!! trans('general.delete_confirm', ['name' => '' . $bill->attachment->basename . '', 'type' => strtolower(trans('general.attachment'))]) !!}", "{!! trans('general.cancel') !!}", "{!! trans('general.delete') !!}"); }); @endif + @endpermission $(document).on('click', '#button-add-item', function (e) { $.ajax({ diff --git a/resources/views/expenses/bills/show.blade.php b/resources/views/expenses/bills/show.blade.php index 489feb93f..772f795aa 100644 --- a/resources/views/expenses/bills/show.blade.php +++ b/resources/views/expenses/bills/show.blade.php @@ -311,23 +311,8 @@ @if($bill->attachment) - - - - {{ $bill->attachment->basename }} - - - {!! Form::open([ - 'id' => 'attachment-' . $bill->attachment->id, - 'method' => 'DELETE', - 'url' => [url('uploads/' . $bill->attachment->id)], - 'style' => 'display:inline' - ]) !!} - - - - {!! Form::close() !!} - + @php $file = $bill->attachment; @endphp + @include('partials.media.file') @endif diff --git a/resources/views/expenses/payments/edit.blade.php b/resources/views/expenses/payments/edit.blade.php index 2f7885ee3..700cb023d 100644 --- a/resources/views/expenses/payments/edit.blade.php +++ b/resources/views/expenses/payments/edit.blade.php @@ -137,31 +137,30 @@ text : '{{ trans('general.form.select.file') }}', style : 'btn-default', @if($payment->attachment) - placeholder : 'attachment->basename; ?>' + placeholder : '{{ $payment->attachment->basename }}' @else placeholder : '{{ trans('general.form.no_file_selected') }}' @endif }); @if($payment->attachment) - attachment_html = ''; - attachment_html += ' '; - attachment_html += ' '; - attachment_html += ' {{ $payment->attachment->basename }}'; - attachment_html += ' '; - attachment_html += ' '; - attachment_html += ' {!! Form::open(['id' => 'attachment-' . $payment->attachment->id, 'method' => 'DELETE', 'url' => [url('uploads/' . $payment->attachment->id)], 'style' => 'display:inline']) !!}'; - attachment_html += ' '; - attachment_html += ' '; - attachment_html += ' '; - attachment_html += ' {!! Form::close() !!}'; - attachment_html += ''; + $.ajax({ + url: '{{ url('uploads/' . $payment->attachment->id . '/show') }}', + type: 'GET', + data: {column_name: 'attachment'}, + dataType: 'JSON', + success: function(json) { + if (json['success']) { + $('.fancy-file').after(json['html']); + } + } + }); - $('.fancy-file .fake-file').append(attachment_html); - - $(document).on('click', '#remove-attachment', function (e) { - confirmDelete("#attachment-{!! $payment->attachment->id !!}", "{!! trans('general.attachment') !!}", "{!! trans('general.delete_confirm', ['name' => '' . $payment->attachment->basename . '', 'type' => strtolower(trans('general.attachment'))]) !!}", "{!! trans('general.cancel') !!}", "{!! trans('general.delete') !!}"); - }); + @permission('delete-common-uploads') + $(document).on('click', '#remove-attachment', function (e) { + confirmDelete("#attachment-{!! $payment->attachment->id !!}", "{!! trans('general.attachment') !!}", "{!! trans('general.delete_confirm', ['name' => '' . $payment->attachment->basename . '', 'type' => strtolower(trans('general.attachment'))]) !!}", "{!! trans('general.cancel') !!}", "{!! trans('general.delete') !!}"); + }); + @endpermission @endif }); diff --git a/resources/views/expenses/vendors/edit.blade.php b/resources/views/expenses/vendors/edit.blade.php index ca9560eea..4993bdd41 100644 --- a/resources/views/expenses/vendors/edit.blade.php +++ b/resources/views/expenses/vendors/edit.blade.php @@ -69,31 +69,30 @@ text : '{{ trans('general.form.select.file') }}', style : 'btn-default', @if($vendor->logo) - placeholder : 'logo->basename; ?>' + placeholder : '{{ $vendor->logo->basename }}' @else placeholder : '{{ trans('general.form.no_file_selected') }}' @endif }); @if($vendor->logo) - logo_html = ''; - - $('.fancy-file .fake-file').append(logo_html); + $.ajax({ + url: '{{ url('uploads/' . $vendor->logo->id . '/show') }}', + type: 'GET', + data: {column_name: 'logo'}, + dataType: 'JSON', + success: function(json) { + if (json['success']) { + $('.fancy-file').after(json['html']); + } + } + }); + @permission('delete-common-uploads') $(document).on('click', '#remove-logo', function (e) { confirmDelete("#logo-{!! $vendor->logo->id !!}", "{!! trans('general.attachment') !!}", "{!! trans('general.delete_confirm', ['name' => '' . $vendor->logo->basename . '', 'type' => strtolower(trans('general.attachment'))]) !!}", "{!! trans('general.cancel') !!}", "{!! trans('general.delete') !!}"); }); + @endpermission @endif }); diff --git a/resources/views/incomes/invoices/edit.blade.php b/resources/views/incomes/invoices/edit.blade.php index dccd5a9de..2805c057a 100644 --- a/resources/views/incomes/invoices/edit.blade.php +++ b/resources/views/incomes/invoices/edit.blade.php @@ -267,6 +267,7 @@ $.ajax({ url: '{{ url('uploads/' . $invoice->attachment->id . '/show') }}', type: 'GET', + data: {column_name: 'attachment'}, dataType: 'JSON', success: function(json) { if (json['success']) { @@ -281,11 +282,13 @@ @endif }); + @permission('delete-common-uploads') @if($invoice->attachment) $(document).on('click', '#remove-attachment', function (e) { confirmDelete("#attachment-{!! $invoice->attachment->id !!}", "{!! trans('general.attachment') !!}", "{!! trans('general.delete_confirm', ['name' => '' . $invoice->attachment->basename . '', 'type' => strtolower(trans('general.attachment'))]) !!}", "{!! trans('general.cancel') !!}", "{!! trans('general.delete') !!}"); }); @endif + @endpermission $(document).on('click', '#button-add-item', function (e) { $.ajax({ diff --git a/resources/views/incomes/revenues/edit.blade.php b/resources/views/incomes/revenues/edit.blade.php index 197407cc4..f5464d828 100644 --- a/resources/views/incomes/revenues/edit.blade.php +++ b/resources/views/incomes/revenues/edit.blade.php @@ -137,32 +137,31 @@ text : '{{ trans('general.form.select.file') }}', style : 'btn-default', @if($revenue->attachment) - placeholder : 'attachment->basename; ?>' + placeholder : '{{ $revenue->attachment->basename }}' @else placeholder : '{{ trans('general.form.no_file_selected') }}' @endif }); @if($revenue->attachment) - attachment_html = ''; - attachment_html += ' '; - attachment_html += ' '; - attachment_html += ' {{ $revenue->attachment->basename }}'; - attachment_html += ' '; - attachment_html += ' '; - attachment_html += ' {!! Form::open(['id' => 'attachment-' . $revenue->attachment->id, 'method' => 'DELETE', 'url' => [url('uploads/' . $revenue->attachment->id)], 'style' => 'display:inline']) !!}'; - attachment_html += ' '; - attachment_html += ' '; - attachment_html += ' '; - attachment_html += ' {!! Form::close() !!}'; - attachment_html += ''; + $.ajax({ + url: '{{ url('uploads/' . $revenue->attachment->id . '/show') }}', + type: 'GET', + data: {column_name: 'attachment'}, + dataType: 'JSON', + success: function(json) { + if (json['success']) { + $('.fancy-file').after(json['html']); + } + } + }); - $('.fancy-file .fake-file').append(attachment_html); - - $(document).on('click', '#remove-attachment', function (e) { - confirmDelete("#attachment-{!! $revenue->attachment->id !!}", "{!! trans('general.attachment') !!}", "{!! trans('general.delete_confirm', ['name' => '' . $revenue->attachment->basename . '', 'type' => strtolower(trans('general.attachment'))]) !!}", "{!! trans('general.cancel') !!}", "{!! trans('general.delete') !!}"); - }); + @permission('delete-common-uploads') + $(document).on('click', '#remove-attachment', function (e) { + confirmDelete("#attachment-{!! $revenue->attachment->id !!}", "{!! trans('general.attachment') !!}", "{!! trans('general.delete_confirm', ['name' => '' . $revenue->attachment->basename . '', 'type' => strtolower(trans('general.attachment'))]) !!}", "{!! trans('general.cancel') !!}", "{!! trans('general.delete') !!}"); + }); @endif + @endpermission }); $(document).on('change', '#account_id', function (e) { diff --git a/resources/views/partials/media/file.blade.php b/resources/views/partials/media/file.blade.php index 2cb0c306e..960675409 100644 --- a/resources/views/partials/media/file.blade.php +++ b/resources/views/partials/media/file.blade.php @@ -21,14 +21,16 @@ {{ $file->readableSize() }} {!! Form::open([ - 'id' => 'attachment-' . $file->id, + 'id' => $column_name. '-' . $file->id, 'method' => 'DELETE', 'url' => [url('uploads/' . $file->id)], 'style' => 'display:inline' ]) !!} - + @permission('delete-common-uploads') + + @endpermission {!! Form::close() !!} diff --git a/resources/views/partials/media/files.blade.php b/resources/views/partials/media/files.blade.php index e4ae762a2..f1deb107b 100644 --- a/resources/views/partials/media/files.blade.php +++ b/resources/views/partials/media/files.blade.php @@ -27,9 +27,11 @@ 'url' => [url('uploads/' . $file->id)], 'style' => 'display:inline' ]) !!} - + @permission('delete-common-uploads') + + @endpermission {!! Form::close() !!} diff --git a/resources/views/settings/settings/edit.blade.php b/resources/views/settings/settings/edit.blade.php index 1b9757f3a..06c808faa 100644 --- a/resources/views/settings/settings/edit.blade.php +++ b/resources/views/settings/settings/edit.blade.php @@ -246,27 +246,23 @@ }); @if($setting['company_logo']) - company_logo_html = ''; - company_logo_html += ' '; - company_logo_html += ' '; - company_logo_html += ' {!! Form::open(['id' => 'company_logo-' . $setting['company_logo']->id, 'method' => 'DELETE', 'url' => [url('uploads/' . $setting['company_logo']->id)], 'style' => 'display:inline']) !!}'; - company_logo_html += ' '; - company_logo_html += ' '; - company_logo_html += ' '; - company_logo_html += ' '; - company_logo_html += ' {!! Form::close() !!}'; - company_logo_html += ''; - - $('#company .fancy-file .fake-file').append(company_logo_html); - - $(document).on('click', '#remove-company_logo', function (e) { - confirmDelete("#company_logo-{!! $setting['company_logo']->id !!}", "{!! trans('general.attachment') !!}", "{!! trans('general.delete_confirm', ['name' => '' . $setting['company_logo']->basename . '', 'type' => strtolower(trans('general.attachment'))]) !!}", "{!! trans('general.cancel') !!}", "{!! trans('general.delete') !!}"); - }); + $.ajax({ + url: '{{ url('uploads/' . $setting['company_logo']->id . '/show') }}', + type: 'GET', + data: {column_name: 'company_logo'}, + dataType: 'JSON', + success: function(json) { + if (json['success']) { + $('#company .fancy-file').after(json['html']); + } + } + }); + + @permission('delete-common-uploads') + $(document).on('click', '#remove-company_logo', function (e) { + confirmDelete("#company_logo-{!! $setting['company_logo']->id !!}", "{!! trans('general.attachment') !!}", "{!! trans('general.delete_confirm', ['name' => '' . $setting['company_logo']->basename . '', 'type' => strtolower(trans('general.attachment'))]) !!}", "{!! trans('general.cancel') !!}", "{!! trans('general.delete') !!}"); + }); + @endpermission @endif var invoice_file = false; @@ -286,27 +282,23 @@ }); @if($setting['invoice_logo']) - invoice_logo_html = ''; - - $(target + ' .fancy-file .fake-file').append(invoice_logo_html); + $.ajax({ + url: '{{ url('uploads/' . $setting['invoice_logo']->id . '/show') }}', + type: 'GET', + data: {column_name: 'invoice_logo'}, + dataType: 'JSON', + success: function(json) { + if (json['success']) { + $(target + ' .fancy-file').after(json['html']); + } + } + }); + @permission('delete-common-uploads') $(document).on('click', '#remove-invoice_logo', function (e) { confirmDelete("#invoice_logo-{!! $setting['invoice_logo']->id !!}", "{!! trans('general.attachment') !!}", "{!! trans('general.delete_confirm', ['name' => '' . $setting['invoice_logo']->basename . '', 'type' => strtolower(trans('general.attachment'))]) !!}", "{!! trans('general.cancel') !!}", "{!! trans('general.delete') !!}"); }); + @endpermission @endif invoice_file = true; diff --git a/resources/views/wizard/companies/edit.blade.php b/resources/views/wizard/companies/edit.blade.php index 8322cfcac..b8efd9eed 100644 --- a/resources/views/wizard/companies/edit.blade.php +++ b/resources/views/wizard/companies/edit.blade.php @@ -116,27 +116,23 @@ }); @if($company->company_logo) - company_logo_html = ''; - - $('.form-group.col-md-6 .fancy-file .fake-file').append(company_logo_html); + $.ajax({ + url: '{{ url('uploads/' . $company->company_logo->id . '/show') }}', + type: 'GET', + data: {column_name: 'company_logo'}, + dataType: 'JSON', + success: function(json) { + if (json['success']) { + $('.form-group.col-md-6 .fancy-file').after(json['html']); + } + } + }); + @permission('delete-common-uploads') $(document).on('click', '#remove-company_logo', function (e) { confirmDelete("#company_logo-{!! $company->company_logo->id !!}", "{!! trans('general.attachment') !!}", "{!! trans('general.delete_confirm', ['name' => '' . $company->company_logo->basename . '', 'type' => strtolower(trans('general.attachment'))]) !!}", "{!! trans('general.cancel') !!}", "{!! trans('general.delete') !!}"); }); + @endpermission @endif }); From 8708512b961986c38ba4c589892d181192d2c29f Mon Sep 17 00:00:00 2001 From: cuneytsenturk Date: Sat, 2 Feb 2019 14:26:03 +0300 Subject: [PATCH 4/5] edit page and show pages media delete issue solved. --- app/Http/Controllers/Common/Uploads.php | 10 +++++++++- resources/views/expenses/bills/show.blade.php | 2 ++ resources/views/incomes/invoices/show.blade.php | 2 ++ resources/views/partials/media/file.blade.php | 15 +++++++++++++-- resources/views/partials/media/files.blade.php | 15 +++++++++++++-- resources/views/settings/settings/edit.blade.php | 4 ++-- 6 files changed, 41 insertions(+), 7 deletions(-) diff --git a/app/Http/Controllers/Common/Uploads.php b/app/Http/Controllers/Common/Uploads.php index ae522b7a3..98274b149 100644 --- a/app/Http/Controllers/Common/Uploads.php +++ b/app/Http/Controllers/Common/Uploads.php @@ -37,12 +37,20 @@ class Uploads extends Controller public function show($id, Request $request) { $file = false; + $options = false; $column_name = 'attachment'; if ($request->has('column_name')) { $column_name = $request->get('column_name'); } + if ($request->has('page')) { + $options = [ + 'page' => $request->get('page'), + 'key' => $request->get('key'), + ]; + } + $media = Media::find($id); // Get file path @@ -58,7 +66,7 @@ class Uploads extends Controller $file = $media; - $html = view('partials.media.file', compact('file', 'column_name'))->render(); + $html = view('partials.media.file', compact('file', 'column_name', 'options'))->render(); return response()->json([ 'success' => true, diff --git a/resources/views/expenses/bills/show.blade.php b/resources/views/expenses/bills/show.blade.php index 772f795aa..7d9cb3cdc 100644 --- a/resources/views/expenses/bills/show.blade.php +++ b/resources/views/expenses/bills/show.blade.php @@ -431,11 +431,13 @@ @push('scripts')