From 12fd825de5756c083f5bc18fa2857b78d39ec195 Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Fri, 25 Nov 2016 16:02:39 +0200 Subject: [PATCH] Working on datatables on vendor page --- app/Http/Controllers/BaseController.php | 6 +++--- app/Http/routes.php | 2 +- app/Services/ExpenseService.php | 2 +- resources/views/datatable.blade.php | 2 +- resources/views/list.blade.php | 4 ++-- resources/views/vendors/show.blade.php | 24 ++++++++++-------------- 6 files changed, 18 insertions(+), 22 deletions(-) diff --git a/app/Http/Controllers/BaseController.php b/app/Http/Controllers/BaseController.php index 213843aa8e..11e78f6b66 100644 --- a/app/Http/Controllers/BaseController.php +++ b/app/Http/Controllers/BaseController.php @@ -33,12 +33,12 @@ class BaseController extends Controller $referer = Request::server('HTTP_REFERER'); $entityTypes = Utils::pluralizeEntityType($entityType); - if (strpos($referer, '/clients/')) { // when restoring redirect to entity - return redirect($referer); - } elseif ($action == 'restore' && count($ids) == 1) { + if ($action == 'restore' && count($ids) == 1) { return redirect("{$entityTypes}/" . $ids[0]); // when viewing from a datatable list + } elseif (strpos($referer, '/clients/')) { + return redirect($referer); } elseif ($isDatatable || ($action == 'archive' || $action == 'delete')) { return redirect("{$entityTypes}"); // when viewing individual entity diff --git a/app/Http/routes.php b/app/Http/routes.php index 7a3b5100c7..db3a539f5d 100644 --- a/app/Http/routes.php +++ b/app/Http/routes.php @@ -206,7 +206,7 @@ Route::group(['middleware' => 'auth:user'], function() { Route::resource('expenses', 'ExpenseController'); Route::get('expenses/create/{vendor_id?}/{client_id?}', 'ExpenseController@create'); Route::get('api/expenses', 'ExpenseController@getDatatable'); - Route::get('api/vendor_expenses/{id}', 'ExpenseController@getDatatableVendor'); + Route::get('api/expenses/{id}', 'ExpenseController@getDatatableVendor'); Route::post('expenses/bulk', 'ExpenseController@bulk'); Route::get('expense_categories', 'ExpenseCategoryController@index'); Route::get('api/expense_categories', 'ExpenseCategoryController@getDatatable'); diff --git a/app/Services/ExpenseService.php b/app/Services/ExpenseService.php index 040f7a4057..c07e3f29e0 100644 --- a/app/Services/ExpenseService.php +++ b/app/Services/ExpenseService.php @@ -82,7 +82,7 @@ class ExpenseService extends BaseService */ public function getDatatableVendor($vendorPublicId) { - $datatable = new ExpenseDatatable(false, true); + $datatable = new ExpenseDatatable(true, true); $query = $this->expenseRepo->findVendor($vendorPublicId); diff --git a/resources/views/datatable.blade.php b/resources/views/datatable.blade.php index ab43929af1..4355282fa9 100644 --- a/resources/views/datatable.blade.php +++ b/resources/views/datatable.blade.php @@ -82,7 +82,7 @@ @if (isset($values['entityType'])) if (window.onDatatableReady_{{ $values['entityType'] }}) { window.onDatatableReady_{{ $values['entityType'] }}(); - } else { + } else if (window.onDatatableReady) { window.onDatatableReady(); } @else diff --git a/resources/views/list.blade.php b/resources/views/list.blade.php index 7fa718b526..b438a606f2 100644 --- a/resources/views/list.blade.php +++ b/resources/views/list.blade.php @@ -58,7 +58,7 @@ {!! Button::normal(trans('texts.categories'))->asLinkTo(URL::to('/expense_categories'))->appendIcon(Icon::create('list')) !!} @endif - @if (Auth::user()->can('create', $entityType)) + @if (empty($vendorId) && Auth::user()->can('create', $entityType)) {!! Button::primary(trans("texts.new_{$entityType}"))->asLinkTo(url(Utils::pluralizeEntityType($entityType) . '/create'))->appendIcon(Icon::create('plus-sign')) !!} @endif @endif @@ -68,7 +68,7 @@ {!! Datatable::table() ->addColumn(Utils::trans($datatable->columnFields())) - ->setUrl(url('api/' . Utils::pluralizeEntityType($entityType) . '/' . (isset($clientId) ? $clientId : ''))) + ->setUrl(url('api/' . Utils::pluralizeEntityType($entityType) . '/' . (isset($clientId) ? $clientId : (isset($vendorId) ? $vendorId : '')))) ->setCustomValues('rightAlign', isset($rightAlign) ? $rightAlign : []) ->setCustomValues('entityType', Utils::pluralizeEntityType($entityType)) ->setCustomValues('clientId', isset($clientId) && $clientId) diff --git a/resources/views/vendors/show.blade.php b/resources/views/vendors/show.blade.php index 3063bb4d71..649691d539 100644 --- a/resources/views/vendors/show.blade.php +++ b/resources/views/vendors/show.blade.php @@ -3,6 +3,9 @@ @section('head') @parent + + + @if ($vendor->hasAddress())