1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-08 12:12:48 +01:00

Rework redirect after bulk edit logic

This commit is contained in:
Hillel Coren 2016-09-19 16:30:46 +03:00
parent 73781e88d5
commit 753e482144
8 changed files with 27 additions and 29 deletions

View File

@ -1,5 +1,6 @@
<?php namespace App\Http\Controllers;
use Utils;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
@ -20,4 +21,20 @@ class BaseController extends Controller
$this->layout = View::make($this->layout);
}
}
protected function returnBulk($entityType, $action, $ids)
{
$isDatatable = filter_var(request()->datatable, FILTER_VALIDATE_BOOLEAN);
$entityTypes = Utils::pluralizeEntityType($entityType);
if ($action == 'restore' && count($ids) == 1) {
return redirect("{$entityTypes}/" . $ids[0]);
} elseif ($isDatatable || ($action == 'archive' || $action == 'delete')) {
return redirect("{$entityTypes}");
} elseif (count($ids)) {
return redirect("{$entityTypes}/" . $ids[0]);
} else {
return redirect("{$entityTypes}");
}
}
}

View File

@ -221,10 +221,6 @@ class ClientController extends BaseController
$message = Utils::pluralize($action.'d_client', $count);
Session::flash('message', $message);
if ($action == 'restore' && $count == 1) {
return Redirect::to('clients/'.Utils::getFirst($ids));
} else {
return Redirect::to('clients');
}
return $this->returnBulk(ENTITY_CLIENT, $action, $ids);
}
}

View File

@ -245,7 +245,7 @@ class ExpenseController extends BaseController
Session::flash('message', $message);
}
return Redirect::to('expenses');
return $this->returnBulk($this->entityType, $action, $ids);
}
private static function getViewModel()

View File

@ -531,11 +531,7 @@ class InvoiceController extends BaseController
Session::flash('message', $message);
}
if ($action == 'restore' && $count == 1) {
return Redirect::to("{$entityType}s/".Utils::getFirst($ids));
} else {
return Redirect::to("{$entityType}s");
}
return $this->returnBulk($entityType, $action, $ids);
}
public function convertQuote(InvoiceRequest $request)
@ -615,7 +611,7 @@ class InvoiceController extends BaseController
public function checkInvoiceNumber()
{
$invoiceNumber = request()->invoice_number;
$count = Invoice::scope()
->whereInvoiceNumber($invoiceNumber)
->withTrashed()

View File

@ -154,11 +154,7 @@ class QuoteController extends BaseController
Session::flash('message', $message);
}
if ($action == 'restore' && $count == 1) {
return Redirect::to('quotes/'.Utils::getFirst($ids));
} else {
return Redirect::to('quotes');
}
return $this->returnBulk(ENTITY_QUOTE, $action, $ids);
}
public function approve($invitationKey)

View File

@ -300,11 +300,7 @@ class TaskController extends BaseController
$message = Utils::pluralize($action.'d_task', $count);
Session::flash('message', $message);
if ($action == 'restore' && $count == 1) {
return Redirect::to('tasks/'.$ids[0].'/edit');
} else {
return Redirect::to('tasks');
}
return $this->returnBulk($this->entityType, $action, $ids);
}
}

View File

@ -81,7 +81,7 @@ class VendorController extends BaseController
public function show(VendorRequest $request)
{
$vendor = $request->entity();
$actionLinks = [
['label' => trans('texts.new_vendor'), 'url' => URL::to('/vendors/create/' . $vendor->public_id)]
];
@ -185,10 +185,6 @@ class VendorController extends BaseController
$message = Utils::pluralize($action.'d_vendor', $count);
Session::flash('message', $message);
if ($action == 'restore' && $count == 1) {
return Redirect::to('vendors/' . Utils::getFirst($ids));
} else {
return Redirect::to('vendors');
}
return $this->returnBulk($this->entityType, $action, $ids);
}
}

View File

@ -7,6 +7,7 @@
<div style="display:none">
{!! Former::text('action') !!}
{!! Former::text('public_id') !!}
{!! Former::text('datatable')->value('true') !!}
</div>
@can('create', 'invoice')
@ -88,7 +89,7 @@
@endif
{!! Former::close() !!}
<script type="text/javascript">
function submitForm(action) {