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

Add ‘More Actions’ to payments form

This commit is contained in:
Hillel Coren 2017-01-02 22:23:29 +02:00
parent 318dfd83e1
commit 977e96dbc3
2 changed files with 35 additions and 3 deletions

View File

@ -122,9 +122,16 @@ class PaymentController extends BaseController
public function edit(PaymentRequest $request) public function edit(PaymentRequest $request)
{ {
$payment = $request->entity(); $payment = $request->entity();
$payment->payment_date = Utils::fromSqlDate($payment->payment_date); $payment->payment_date = Utils::fromSqlDate($payment->payment_date);
$actions = [];
if ( ! $payment->trashed()) {
$actions[] = ['url' => 'javascript:submitAction("archive")', 'label' => trans('texts.archive_payment')];
$actions[] = ['url' => 'javascript:onDeleteClick()', 'label' => trans('texts.delete_payment')];
} else {
$actions[] = ['url' => 'javascript:submitAction("restore")', 'label' => trans('texts.restore_expense')];
}
$data = [ $data = [
'client' => null, 'client' => null,
'invoice' => null, 'invoice' => null,
@ -138,6 +145,7 @@ class PaymentController extends BaseController
'method' => 'PUT', 'method' => 'PUT',
'url' => 'payments/'.$payment->public_id, 'url' => 'payments/'.$payment->public_id,
'title' => trans('texts.edit_payment'), 'title' => trans('texts.edit_payment'),
'actions' => $actions,
'paymentTypes' => Cache::get('paymentTypes'), 'paymentTypes' => Cache::get('paymentTypes'),
'clients' => Client::scope()->with('contacts')->orderBy('name')->get(), 'clients' => Client::scope()->with('contacts')->orderBy('name')->get(),
]; ];
@ -173,6 +181,10 @@ class PaymentController extends BaseController
*/ */
public function update(UpdatePaymentRequest $request) public function update(UpdatePaymentRequest $request)
{ {
if (in_array($request->action, ['archive', 'delete', 'restore'])) {
return self::bulk();
}
$payment = $this->paymentRepo->save($request->input(), $request->entity()); $payment = $this->paymentRepo->save($request->input(), $request->entity());
Session::flash('message', trans('texts.updated_payment')); Session::flash('message', trans('texts.updated_payment'));
@ -191,7 +203,7 @@ class PaymentController extends BaseController
$count = $this->paymentService->bulk($ids, $action, ['amount'=>$amount]); $count = $this->paymentService->bulk($ids, $action, ['amount'=>$amount]);
if ($count > 0) { if ($count > 0) {
$message = Utils::pluralize($action=='refund'?'refunded_payment':$action.'d_payment', $count); $message = Utils::pluralize($action=='refund' ? 'refunded_payment':$action.'d_payment', $count);
Session::flash('message', $message); Session::flash('message', $message);
} }

View File

@ -15,7 +15,7 @@
@section('content') @section('content')
{!! Former::open($url) {!! Former::open($url)
->addClass('col-md-10 col-md-offset-1 warn-on-exit') ->addClass('col-md-10 col-md-offset-1 warn-on-exit main-form')
->onsubmit('onFormSubmit(event)') ->onsubmit('onFormSubmit(event)')
->method($method) ->method($method)
->rules(array( ->rules(array(
@ -30,6 +30,7 @@
<span style="display:none"> <span style="display:none">
{!! Former::text('public_id') !!} {!! Former::text('public_id') !!}
{!! Former::text('action') !!}
</span> </span>
<div class="row"> <div class="row">
@ -81,6 +82,14 @@
@if (!$payment || !$payment->is_deleted) @if (!$payment || !$payment->is_deleted)
{!! Button::success(trans('texts.save'))->withAttributes(['id' => 'saveButton'])->appendIcon(Icon::create('floppy-disk'))->submit()->large() !!} {!! Button::success(trans('texts.save'))->withAttributes(['id' => 'saveButton'])->appendIcon(Icon::create('floppy-disk'))->submit()->large() !!}
@endif @endif
@if ($payment)
{!! DropdownButton::normal(trans('texts.more_actions'))
->withContents($actions)
->large()
->dropup() !!}
@endif
</center> </center>
{!! Former::close() !!} {!! Former::close() !!}
@ -121,6 +130,17 @@
$('#saveButton').attr('disabled', true); $('#saveButton').attr('disabled', true);
} }
function submitAction(action) {
$('#action').val(action);
$('.main-form').submit();
}
function onDeleteClick() {
sweetConfirm(function() {
submitAction('delete');
});
}
</script> </script>
@stop @stop