1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 05:02:36 +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)
{
$payment = $request->entity();
$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 = [
'client' => null,
'invoice' => null,
@ -138,6 +145,7 @@ class PaymentController extends BaseController
'method' => 'PUT',
'url' => 'payments/'.$payment->public_id,
'title' => trans('texts.edit_payment'),
'actions' => $actions,
'paymentTypes' => Cache::get('paymentTypes'),
'clients' => Client::scope()->with('contacts')->orderBy('name')->get(),
];
@ -173,6 +181,10 @@ class PaymentController extends BaseController
*/
public function update(UpdatePaymentRequest $request)
{
if (in_array($request->action, ['archive', 'delete', 'restore'])) {
return self::bulk();
}
$payment = $this->paymentRepo->save($request->input(), $request->entity());
Session::flash('message', trans('texts.updated_payment'));
@ -191,7 +203,7 @@ class PaymentController extends BaseController
$count = $this->paymentService->bulk($ids, $action, ['amount'=>$amount]);
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);
}

View File

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