From fcf50093381435fd1b57914b26994eeb4ed1c3f5 Mon Sep 17 00:00:00 2001 From: James Cole Date: Fri, 27 Mar 2015 13:20:48 +0100 Subject: [PATCH] Moved some code around. --- public/js/accounts.js | 75 ++++++++++++++++++++- public/js/transactions.js | 71 +------------------ resources/views/accounts/show.blade.php | 2 +- resources/views/transactions/show.blade.php | 3 - 4 files changed, 76 insertions(+), 75 deletions(-) diff --git a/public/js/accounts.js b/public/js/accounts.js index 9301f828e6..5435c2d6b9 100644 --- a/public/js/accounts.js +++ b/public/js/accounts.js @@ -4,4 +4,77 @@ $(function () { googleLineChart('chart/account/' + accountID, 'overview-chart'); } -}); \ No newline at end of file + // sortable! + if (typeof $(".sortable-table tbody").sortable != "undefined") { + $(".sortable-table tbody").sortable( + { + helper: fixHelper, + items: 'tr:not(.ignore)', + stop: sortStop, + handle: '.handle' + } + ).disableSelection(); + } + +}); + + +// Return a helper with preserved width of cells +var fixHelper = function (e, ui) { + ui.children().each(function () { + $(this).width($(this).width()); + }); + return ui; +}; + +function sortStop(event, ui) { + 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') + ']'); + // animate something with color: + current.animate({ + backgroundColor: "#d9534f" + }, 200, function () { + $(this).animate({ + backgroundColor: originalBG + }, 200); + }); + + return false; + } + + // 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); + }); + + // do extra animation when done? + $.post('/transaction/reorder', {items: submit, date: thisDate, _token: token}); + console.log(submit); + + //console.log('TRUE!'); + //console.log('[' + current.prev().data('date') + '] [' + thisDate + '] [' + current.next().data('date') + ']'); + + current.animate({ + backgroundColor: "#5cb85c" + }, 200, function () { + $(this).animate({ + backgroundColor: originalBG + }, 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 + +} \ No newline at end of file diff --git a/public/js/transactions.js b/public/js/transactions.js index 9a5eee1356..142e19a44d 100644 --- a/public/js/transactions.js +++ b/public/js/transactions.js @@ -24,80 +24,11 @@ if ($('input[name="category"]').length > 0) { }); } -// Return a helper with preserved width of cells -var fixHelper = function (e, ui) { - ui.children().each(function () { - $(this).width($(this).width()); - }); - return ui; -}; $(document).ready(function () { if (typeof googleTablePaged != 'undefined') { googleTablePaged('table/transactions/' + what, 'transaction-table'); } - // sortable! - $(".sortable-table tbody").sortable( - { - helper: fixHelper, - items: 'tr:not(.ignore)', - stop: sortStop, - handle: '.handle' - } - ).disableSelection(); -}); -function sortStop(event, ui) { - 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') + ']'); - // animate something with color: - current.animate({ - backgroundColor: "#d9534f" - }, 200, function () { - $(this).animate({ - backgroundColor: originalBG - }, 200); - }); - - return false; - } - - // 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); - }); - - // do extra animation when done? - $.post('/transaction/reorder',{items: submit,date: thisDate,_token:token}); - console.log(submit); - - //console.log('TRUE!'); - //console.log('[' + current.prev().data('date') + '] [' + thisDate + '] [' + current.next().data('date') + ']'); - - current.animate({ - backgroundColor: "#5cb85c" - }, 200, function () { - $(this).animate({ - backgroundColor: originalBG - }, 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 - -} \ No newline at end of file +}); \ No newline at end of file diff --git a/resources/views/accounts/show.blade.php b/resources/views/accounts/show.blade.php index 7fd0e893e8..8cf88a34b4 100644 --- a/resources/views/accounts/show.blade.php +++ b/resources/views/accounts/show.blade.php @@ -58,5 +58,5 @@ - + @stop diff --git a/resources/views/transactions/show.blade.php b/resources/views/transactions/show.blade.php index 36bbc26312..6c3e671dd3 100644 --- a/resources/views/transactions/show.blade.php +++ b/resources/views/transactions/show.blade.php @@ -152,9 +152,6 @@ @stop @section('scripts') - @stop