From 980d9ce88569761e94971629ea973bf97783b8ae Mon Sep 17 00:00:00 2001 From: Sander Dorigo Date: Sun, 5 Oct 2014 08:49:36 +0200 Subject: [PATCH] Also validate edits. --- app/controllers/TransactionController.php | 14 ++- app/lib/Firefly/Form/Form.php | 2 +- app/start/global.php | 4 +- app/views/transactions/create.blade.php | 2 +- app/views/transactions/edit.blade.php | 126 +++------------------- 5 files changed, 30 insertions(+), 118 deletions(-) diff --git a/app/controllers/TransactionController.php b/app/controllers/TransactionController.php index e0e3abf8e5..53d7546c85 100644 --- a/app/controllers/TransactionController.php +++ b/app/controllers/TransactionController.php @@ -342,8 +342,8 @@ class TransactionController extends BaseController Session::flash('success', 'Transaction updated!'); Event::fire('journals.update', [$journal]); - if (Input::get('post_submit_action') == 'create_another') { - return Redirect::route('transactions.create', $what)->withInput(); + if (Input::get('post_submit_action') == 'return_to_edit') { + return Redirect::route('transactions.edit', $journal->id); } else { return Redirect::route('transactions.index.' . $what); } @@ -355,6 +355,16 @@ class TransactionController extends BaseController ); } + break; + case 'validate_only': + $data = Input::all(); + $data['what'] = strtolower($journal->transactionType->type); + $messageBags = $this->_helper->validate($data); + + Session::flash('warnings', $messageBags['warnings']); + Session::flash('successes', $messageBags['successes']); + Session::flash('errors', $messageBags['errors']); + return Redirect::route('transactions.edit', $journal->id)->withInput(); break; default: throw new FireflyException('Method ' . Input::get('post_submit_action') . ' not implemented yet.'); diff --git a/app/lib/Firefly/Form/Form.php b/app/lib/Firefly/Form/Form.php index 5aec4c3f7b..bbe8f3f4b4 100644 --- a/app/lib/Firefly/Form/Form.php +++ b/app/lib/Firefly/Form/Form.php @@ -16,7 +16,7 @@ class Form * @return string * @throws FireflyException */ - public static function ffAmount($name, $value = null, array $options = []) + public static function ffNumber($name, $value = null, array $options = []) { $options['step'] = 'any'; $options['min'] = '0.01'; diff --git a/app/start/global.php b/app/start/global.php index 2a9c06beca..981afc49ec 100644 --- a/app/start/global.php +++ b/app/start/global.php @@ -78,8 +78,8 @@ App::down( \Form::macro('ffSelect', function ($name, array $list = [], $selected = null, array $options = []) { return \Firefly\Form\Form::ffSelect($name, $list, $selected, $options); }); -\Form::macro('ffAmount', function ($name, $value = null, array $options = []) { - return \Firefly\Form\Form::ffAmount($name, $value, $options); +\Form::macro('ffNumber', function ($name, $value = null, array $options = []) { + return \Firefly\Form\Form::ffNumber($name, $value, $options); }); \Form::macro('ffDate', function ($name, $value = null, array $options = []) { return \Firefly\Form\Form::ffDate($name, $value, $options); diff --git a/app/views/transactions/create.blade.php b/app/views/transactions/create.blade.php index 7acc907bcc..91fa93176f 100644 --- a/app/views/transactions/create.blade.php +++ b/app/views/transactions/create.blade.php @@ -37,7 +37,7 @@ - {{Form::ffAmount('amount')}} + {{Form::ffNumber('amount')}} {{Form::ffDate('date', date('Y-m-d'))}} diff --git a/app/views/transactions/edit.blade.php b/app/views/transactions/edit.blade.php index 9a15e1d6f1..1856d334b7 100644 --- a/app/views/transactions/edit.blade.php +++ b/app/views/transactions/edit.blade.php @@ -12,103 +12,33 @@
-
- -
- -
-
+ {{Form::ffText('description',$journal->description)}} @if($what == 'deposit' || $what == 'withdrawal') -
- -
- {{Form::select('account_id',$accounts,Input::old('account_id') ?: $data['account_id'],['class' => 'form-control'])}} -
-
+ {{Form::ffSelect('account_id',$accounts,$data['account_id'])}} @endif @if($what == 'withdrawal') -
- -
- -
-
+ {{Form::ffText('expense_account',$data['expense_account'])}} @endif @if($what == 'deposit') -
- -
- -
-
+ {{Form::ffText('revenue_account',$data['revenue_account'])}} @endif @if($what == 'transfer') -
- -
- {{Form::select('account_to_id',$accounts,Input::old('account_from_id') ?: $data['account_from_id'],['class' => 'form-control'])}} -
-
- -
- -
- {{Form::select('account_from_id',$accounts,Input::old('account_to_id') ?: $data['account_to_id'],['class' => 'form-control'])}} -
-
+ {{Form::ffSelect('account_from_id',$accounts,$data['account_from_id'])}} + {{Form::ffSelect('account_to_id',$accounts,$data['account_to_id'])}} @endif -
- -
- -
-
+ {{Form::ffNumber('amount',$data['amount'])}} -
- -
- -
-
+ {{Form::ffDate('date',$data['date'])}}
@@ -128,44 +58,16 @@
@if($what == 'withdrawal') -
- -
- {{Form::select('budget_id',$budgets,Input::old('budget_id') ?: $data['budget_id'],['class' => 'form-control'])}} - Select one of your budgets to make this transaction a part of it. -
-
+ {{Form::ffSelect('budget_id',$budgets,$data['budget_id'])}} @endif -
- -
- - Add more fine-grained information to this transaction by entering a category. - Like the beneficiary-field, this field will auto-complete existing categories but can also be used - to create new ones. - -
-
+ {{Form::ffText('category',$data['category'])}} + + + @if($what == 'transfer' && count($piggies) > 0) -
- -
- {{Form::select('piggybank_id',$piggies,Input::old('piggybank_id') ?: $data['piggybank_id'],['class' => 'form-control'])}} - @if($errors->has('piggybank_id')) -

{{$errors->first('piggybank_id')}}

- @else - - You can directly add the amount you're transferring - to one of your piggy banks, provided they are related to the account your - transferring to. - - @endif -
-
+ {{Form::ffSelect('piggybank_id',$piggies,$data['piggybank_id'])}} @endif