diff --git a/app/Http/Controllers/TransactionController.php b/app/Http/Controllers/TransactionController.php index 4149d9f44f..be952d0a99 100644 --- a/app/Http/Controllers/TransactionController.php +++ b/app/Http/Controllers/TransactionController.php @@ -210,6 +210,15 @@ class TransactionController extends Controller } + /** + * Reorder transactions (which all must have the same date) + */ + public function reorder() + { + $ids = Input::get('items'); + + } + /** * @param TransactionJournal $journal * diff --git a/app/Http/routes.php b/app/Http/routes.php index 3bf64a8ceb..299799ea5b 100644 --- a/app/Http/routes.php +++ b/app/Http/routes.php @@ -366,6 +366,7 @@ Route::group( ); Route::post('/transaction/update/{tj}', ['uses' => 'TransactionController@update', 'as' => 'transactions.update']); Route::post('/transaction/destroy/{tj}', ['uses' => 'TransactionController@destroy', 'as' => 'transactions.destroy']); + Route::post('/transaction/reorder', ['uses' => 'TransactionController@reorder', 'as' => 'transactions.reorder']); /** * Auth\Auth Controller diff --git a/app/Validation/FireflyValidator.php b/app/Validation/FireflyValidator.php index b4b95b1701..c4ecc34cd3 100644 --- a/app/Validation/FireflyValidator.php +++ b/app/Validation/FireflyValidator.php @@ -80,18 +80,36 @@ class FireflyValidator extends Validator public function validateUniqueAccountForUser($attribute, $value, $parameters) { // get account type from data, we must have this: - $type = isset($this->data['what']) ? $this->data['what'] : Input::get('what'); - $longType = Config::get('firefly.accountTypeByIdentifier.' . $type); - $dbType = AccountType::whereType($longType)->first(); - if (!$dbType) { + $type = isset($this->data['what']) ? $this->data['what'] : null; + // some fallback: + if(is_null($type)) { + $type = Input::get('what'); + } + // still null? + if(is_null($type)) { + // find by other field: + $type = isset($this->data['account_type_id']) ? $this->data['account_type_id'] : 0; + $dbType = AccountType::find($type); + } else { + $longType = Config::get('firefly.accountTypeByIdentifier.' . $type); + $dbType = AccountType::whereType($longType)->first(); + } + + if (is_null($dbType)) { return false; } - $query = DB::table('accounts')->where('name', $value)->where('account_type_id', $dbType->id)->where('user_id', Auth::user()->id); + + // user id? + $userId = Auth::check() ? Auth::user()->id : $this->data['user_id']; + + $query = DB::table('accounts')->where('name', $value)->where('account_type_id', $dbType->id)->where('user_id', $userId); + if (isset($parameters[0])) { $query->where('id', '!=', $parameters[0]); } $count = $query->count(); if ($count == 0) { + return true; } diff --git a/database/migrations/2015_03_27_061038_changes_for_v333.php b/database/migrations/2015_03_27_061038_changes_for_v333.php new file mode 100644 index 0000000000..3b8b2e81e0 --- /dev/null +++ b/database/migrations/2015_03_27_061038_changes_for_v333.php @@ -0,0 +1,33 @@ +smallInteger('order',false,true)->default(0); + + } + ); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + // + } + +} diff --git a/public/js/transactions.js b/public/js/transactions.js index 15d6a123b6..a6d5ee37e1 100644 --- a/public/js/transactions.js +++ b/public/js/transactions.js @@ -31,45 +31,23 @@ $(document).ready(function () { $(".sortable-table tbody").sortable( { helper: fixHelper, - connectWith: '.sortable-table tbody', - //stop: stopSorting, items: 'tr:not(.ignore)', stop: sortStop, - handle: '.handle' - //revert: 'invalid' + handle: '.handle', + revert: 'invalid' } ).disableSelection(); }); -function sortChange() { - //console.log("change"); -} - -function sortSort(event, ui) { - //var current = $(ui.item); - //var thisDate = current.data('date'); - - //if(current.prev().data('date') != thisDate && current.next().data('date') != thisDate) { - // console.log('FALSE ['+current.prev().data('date')+'] ['+thisDate+'] ['+current.next().data('date')+'] ('+current.index()+')'); - // return true; - - // return false; - //} - //console.log('TRUE ['+current.prev().data('date')+'] ['+thisDate+'] ['+current.next().data('date')+'] ('+current.index()+')'); - -} - function sortStop(event, ui) { - console.log("stop"); var current = $(ui.item); var thisDate = current.data('date'); var originalBG = current.css('backgroundColor'); if (current.prev().data('date') != thisDate && current.next().data('date') != thisDate) { - console.log('False!'); - console.log('[' + current.prev().data('date') + '] [' + thisDate + '] [' + current.next().data('date') + ']'); - + //console.log('False!'); + //console.log('[' + current.prev().data('date') + '] [' + thisDate + '] [' + current.next().data('date') + ']'); // animate something with color: current.animate({ backgroundColor: "#d9534f" @@ -79,13 +57,23 @@ function sortStop(event, ui) { }, 200); }); - - // fade back to original - return false; } - console.log('TRUE!'); - console.log('[' + current.prev().data('date') + '] [' + thisDate + '] [' + current.next().data('date') + ']'); + + // do update + var list = $('tr[data-date="' + thisDate + '"]'); + var submit = []; + $.each(list, function (i, v) { + var row = $(v); + var id = row.data('id'); + submit.push(id); + }); + + $.post('/transaction/reorder',{items: submit,_token:token}); + console.log(submit); + + //console.log('TRUE!'); + //console.log('[' + current.prev().data('date') + '] [' + thisDate + '] [' + current.next().data('date') + ']'); current.animate({ backgroundColor: "#5cb85c" @@ -95,6 +83,9 @@ function sortStop(event, ui) { }, 200); }); + + + //else update some order thing bla bla. //check if the item above OR under this one have the same date //if not. return false diff --git a/resources/views/accounts/show.blade.php b/resources/views/accounts/show.blade.php index 462cbe5a9e..0fcd1ff2e7 100644 --- a/resources/views/accounts/show.blade.php +++ b/resources/views/accounts/show.blade.php @@ -37,7 +37,7 @@ Transactions