Files
firefly-iii/public/js/ff/accounts/show.js

95 lines
3.0 KiB
JavaScript
Raw Normal View History

2016-12-09 18:52:27 +01:00
/*
* show.js
* Copyright (C) 2016 thegrumpydictator@gmail.com
*
* This software may be modified and distributed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International License.
*
* See the LICENSE file for details.
*/
2015-05-24 18:22:41 +02:00
var fixHelper = function (e, tr) {
2016-01-22 07:27:49 +01:00
"use strict";
var $originals = tr.children();
var $helper = tr.clone();
$helper.children().each(function (index) {
// Set helper cell sizes to match the original sizes
$(this).width($originals.eq(index).width());
2015-05-24 18:22:41 +02:00
});
return $helper;
2015-05-24 18:22:41 +02:00
};
2015-02-21 12:16:41 +01:00
2015-05-24 18:22:41 +02:00
$(function () {
"use strict";
2016-12-09 18:52:27 +01:00
lineChart(chartUri, 'overview-chart');
2016-12-06 06:52:17 +01:00
pieChart(incomeCategoryUri, 'account-cat-in');
pieChart(expenseCategoryUri, 'account-cat-out');
pieChart(expenseBudgetUri, 'account-budget-out');
2016-11-20 18:31:29 +01:00
2015-02-21 12:16:41 +01:00
2015-03-27 13:20:48 +01:00
// sortable!
2015-05-24 18:22:41 +02:00
if (typeof $(".sortable-table tbody").sortable !== "undefined") {
2015-03-27 13:20:48 +01:00
$(".sortable-table tbody").sortable(
{
helper: fixHelper,
items: 'tr:not(.ignore)',
stop: sortStop,
handle: '.handle',
start: function (event, ui) {
// Build a placeholder cell that spans all the cells in the row
var cellCount = 0;
$('td, th', ui.helper).each(function () {
// For each TD or TH try and get it's colspan attribute, and add that or 1 to the total
var colspan = 1;
var colspanAttr = $(this).attr('colspan');
if (colspanAttr > 1) {
colspan = colspanAttr;
}
cellCount += colspan;
});
// Add the placeholder UI - note that this is the item's content, so TD rather than TR
ui.placeholder.html('<td colspan="' + cellCount + '">&nbsp;</td>');
}
2015-03-27 13:20:48 +01:00
}
).disableSelection();
2015-09-25 20:25:22 +02:00
} else {
console.log('its null');
2015-03-27 13:20:48 +01:00
}
});
function sortStop(event, ui) {
2015-05-24 18:22:41 +02:00
"use strict";
2015-03-27 13:20:48 +01:00
var current = $(ui.item);
2015-09-25 20:25:22 +02:00
console.log('sort stop');
2015-03-27 13:20:48 +01:00
var thisDate = current.data('date');
var originalBG = current.css('backgroundColor');
2015-05-24 18:22:41 +02:00
if (current.prev().data('date') !== thisDate && current.next().data('date') !== thisDate) {
2015-03-27 13:20:48 +01:00
// animate something with color:
current.animate({backgroundColor: "#d9534f"}, 200, function () {
$(this).animate({backgroundColor: originalBG}, 200);
2015-03-27 13:20:48 +01:00
});
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?
2016-12-21 20:34:47 +01:00
$.post('transactions/reorder', {items: submit, date: thisDate, _token: token});
2015-03-27 13:20:48 +01:00
current.animate({backgroundColor: "#5cb85c"}, 200, function () {
$(this).animate({backgroundColor: originalBG}, 200);
2015-03-27 13:20:48 +01:00
});
2016-01-22 07:27:49 +01:00
}