diff --git a/app/Http/Controllers/BaseController.php b/app/Http/Controllers/BaseController.php index c583f919b86f..213843aa8eee 100644 --- a/app/Http/Controllers/BaseController.php +++ b/app/Http/Controllers/BaseController.php @@ -1,6 +1,7 @@ datatable, FILTER_VALIDATE_BOOLEAN); + $referer = Request::server('HTTP_REFERER'); $entityTypes = Utils::pluralizeEntityType($entityType); - if ($action == 'restore' && count($ids) == 1) { + if (strpos($referer, '/clients/')) { + // when restoring redirect to entity + return redirect($referer); + } elseif ($action == 'restore' && count($ids) == 1) { return redirect("{$entityTypes}/" . $ids[0]); + // when viewing from a datatable list } elseif ($isDatatable || ($action == 'archive' || $action == 'delete')) { return redirect("{$entityTypes}"); + // when viewing individual entity } elseif (count($ids)) { return redirect("{$entityTypes}/" . $ids[0]); } else { diff --git a/app/Ninja/Datatables/ExpenseDatatable.php b/app/Ninja/Datatables/ExpenseDatatable.php index 536e9dcbf419..6bf432e6d02b 100644 --- a/app/Ninja/Datatables/ExpenseDatatable.php +++ b/app/Ninja/Datatables/ExpenseDatatable.php @@ -114,7 +114,7 @@ class ExpenseDatatable extends EntityDatatable [ trans('texts.invoice_expense'), function ($model) { - return "javascript:invoiceEntity({$model->public_id})"; + return "javascript:submitForm_expense('invoice', {$model->public_id})"; }, function ($model) { return ! $model->invoice_id && (!$model->deleted_at || $model->deleted_at == '0000-00-00') && Auth::user()->can('create', ENTITY_INVOICE); diff --git a/app/Ninja/Datatables/InvoiceDatatable.php b/app/Ninja/Datatables/InvoiceDatatable.php index 4203d47d3444..5d90107d03c3 100644 --- a/app/Ninja/Datatables/InvoiceDatatable.php +++ b/app/Ninja/Datatables/InvoiceDatatable.php @@ -110,8 +110,8 @@ class InvoiceDatatable extends EntityDatatable ], [ trans('texts.mark_sent'), - function ($model) { - return "javascript:markEntity({$model->public_id})"; + function ($model) use ($entityType) { + return "javascript:submitForm_{$entityType}('markSent', {$model->public_id})"; }, function ($model) { return $model->invoice_status_id < INVOICE_STATUS_SENT && Auth::user()->can('editByOwner', [ENTITY_INVOICE, $model->user_id]); @@ -147,7 +147,7 @@ class InvoiceDatatable extends EntityDatatable [ trans('texts.convert_to_invoice'), function ($model) { - return "javascript:convertEntity({$model->public_id})"; + return "javascript:submitForm_quote('convert', {$model->public_id})"; }, function ($model) use ($entityType) { return $entityType == ENTITY_QUOTE && ! $model->quote_invoice_id && Auth::user()->can('editByOwner', [ENTITY_INVOICE, $model->user_id]); diff --git a/app/Ninja/Datatables/TaskDatatable.php b/app/Ninja/Datatables/TaskDatatable.php index 78647f49c5cb..a65e28b8de83 100644 --- a/app/Ninja/Datatables/TaskDatatable.php +++ b/app/Ninja/Datatables/TaskDatatable.php @@ -78,7 +78,7 @@ class TaskDatatable extends EntityDatatable [ trans('texts.stop_task'), function ($model) { - return "javascript:stopTask({$model->public_id})"; + return "javascript:submitForm_task('stop', {$model->public_id})"; }, function ($model) { return $model->is_running && Auth::user()->can('editByOwner', [ENTITY_TASK, $model->user_id]); @@ -87,7 +87,7 @@ class TaskDatatable extends EntityDatatable [ trans('texts.invoice_task'), function ($model) { - return "javascript:invoiceEntity({$model->public_id})"; + return "javascript:submitForm_task('invoice', {$model->public_id})"; }, function ($model) { return ! $model->invoice_number && (!$model->deleted_at || $model->deleted_at == '0000-00-00') && Auth::user()->can('create', ENTITY_INVOICE); diff --git a/app/Services/DatatableService.php b/app/Services/DatatableService.php index 82223ffc324f..7eb8029bc9d4 100644 --- a/app/Services/DatatableService.php +++ b/app/Services/DatatableService.php @@ -116,16 +116,16 @@ class DatatableService } if (($datatable->entityType != ENTITY_USER || $model->public_id) && $can_edit) { - $dropdown_contents .= "
  • public_id})\">" + $dropdown_contents .= "
  • entityType}('archive', {$model->public_id})\">" . trans("texts.archive_{$datatable->entityType}") . '
  • '; } } else if($can_edit) { - $dropdown_contents .= "
  • public_id})\">" + $dropdown_contents .= "
  • entityType}('restore', {$model->public_id})\">" . trans("texts.restore_{$datatable->entityType}") . '
  • '; } if (property_exists($model, 'is_deleted') && !$model->is_deleted && $can_edit) { - $dropdown_contents .= "
  • public_id})\">" + $dropdown_contents .= "
  • entityType}('delete', {$model->public_id})\">" . trans("texts.delete_{$datatable->entityType}") . '
  • '; } diff --git a/resources/views/clients/show.blade.php b/resources/views/clients/show.blade.php index 618b041d3ef9..4424c9d1c1cd 100644 --- a/resources/views/clients/show.blade.php +++ b/resources/views/clients/show.blade.php @@ -218,6 +218,7 @@ trans('texts.adjustment')) ->setUrl(url('api/activities/'. $client->public_id)) ->setCustomValues('entityType', 'activity') + ->setCustomValues('clientId', $client->public_id) ->setOptions('sPaginationType', 'bootstrap') ->setOptions('bFilter', false) ->setOptions('aaSorting', [['0', 'desc']]) diff --git a/resources/views/datatable.blade.php b/resources/views/datatable.blade.php index 91a135b30f2b..3277ece37941 100644 --- a/resources/views/datatable.blade.php +++ b/resources/views/datatable.blade.php @@ -79,7 +79,9 @@ {!! json_encode($k) !!}: {!! $o !!}, @endforeach "fnDrawCallback": function(oSettings) { - if (window.onDatatableReady) { + if (window.onDatatableReady_{{ $values['entityType'] }}) { + window.onDatatableReady_{{ $values['entityType'] }}(); + } else if (window.onDatatableReady) { window.onDatatableReady(); } }, diff --git a/resources/views/list.blade.php b/resources/views/list.blade.php index 348077424005..7fa718b526e0 100644 --- a/resources/views/list.blade.php +++ b/resources/views/list.blade.php @@ -1,27 +1,28 @@ -{!! Former::open(Utils::pluralizeEntityType($entityType) . '/bulk')->addClass('listForm') !!} +{!! Former::open(Utils::pluralizeEntityType($entityType) . '/bulk') + ->addClass('listForm_' . $entityType) !!}
    - {!! Former::text('action') !!} - {!! Former::text('public_id') !!} + {!! Former::text('action')->id('action_' . $entityType) !!} + {!! Former::text('public_id')->id('public_id_' . $entityType) !!} {!! Former::text('datatable')->value('true') !!}
    @can('create', 'invoice') @if ($entityType == ENTITY_TASK) - {!! Button::primary(trans('texts.invoice'))->withAttributes(['class'=>'invoice', 'onclick' =>'submitForm("invoice")'])->appendIcon(Icon::create('check')) !!} + {!! Button::primary(trans('texts.invoice'))->withAttributes(['class'=>'invoice', 'onclick' =>'submitForm_'.$entityType.'("invoice")'])->appendIcon(Icon::create('check')) !!} @endif @if ($entityType == ENTITY_EXPENSE) - {!! Button::primary(trans('texts.invoice'))->withAttributes(['class'=>'invoice', 'onclick' =>'submitForm("invoice")'])->appendIcon(Icon::create('check')) !!} + {!! Button::primary(trans('texts.invoice'))->withAttributes(['class'=>'invoice', 'onclick' =>'submitForm_'.$entityType.'("invoice")'])->appendIcon(Icon::create('check')) !!} @endif @endcan @if (in_array($entityType, [ENTITY_EXPENSE_CATEGORY, ENTITY_PRODUCT])) - {!! Button::normal(trans('texts.archive'))->asLinkTo('javascript:submitForm("archive")')->appendIcon(Icon::create('trash')) !!} + {!! Button::normal(trans('texts.archive'))->asLinkTo('javascript:submitForm_'.$entityType.'("archive")')->appendIcon(Icon::create('trash')) !!} @else {!! DropdownButton::normal(trans('texts.archive'))->withContents([ - ['label' => trans('texts.archive_'.$entityType), 'url' => 'javascript:submitForm("archive")'], - ['label' => trans('texts.delete_'.$entityType), 'url' => 'javascript:submitForm("delete")'], + ['label' => trans('texts.archive_'.$entityType), 'url' => 'javascript:submitForm_'.$entityType.'("archive")'], + ['label' => trans('texts.delete_'.$entityType), 'url' => 'javascript:submitForm_'.$entityType.'("delete")'], ])->withAttributes(['class'=>'archive'])->split() !!} @endif @@ -49,7 +50,7 @@
    - @if (empty($clientId)) @@ -64,6 +65,7 @@
    + {!! Datatable::table() ->addColumn(Utils::trans($datatable->columnFields())) ->setUrl(url('api/' . Utils::pluralizeEntityType($entityType) . '/' . (isset($clientId) ? $clientId : ''))) @@ -112,166 +114,128 @@