2016-01-29 17:31:07 +01:00
|
|
|
/*
|
|
|
|
* index.js
|
2020-02-16 13:59:41 +01:00
|
|
|
* Copyright (c) 2019 james@firefly-iii.org
|
2016-01-29 17:31:07 +01:00
|
|
|
*
|
2019-10-02 06:43:38 +02:00
|
|
|
* This file is part of Firefly III (https://github.com/firefly-iii).
|
2016-12-23 07:02:45 +01:00
|
|
|
*
|
2019-10-02 06:43:38 +02:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as
|
|
|
|
* published by the Free Software Foundation, either version 3 of the
|
|
|
|
* License, or (at your option) any later version.
|
2017-10-21 08:40:00 +02:00
|
|
|
*
|
2019-10-02 06:43:38 +02:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
2017-10-21 08:40:00 +02:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2019-10-02 06:43:38 +02:00
|
|
|
* GNU Affero General Public License for more details.
|
2017-10-21 08:40:00 +02:00
|
|
|
*
|
2019-10-02 06:43:38 +02:00
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2016-01-29 17:31:07 +01:00
|
|
|
*/
|
2017-12-29 09:05:35 +01:00
|
|
|
/** global: token */
|
2020-06-09 17:16:21 +02:00
|
|
|
var fixPiggyHelper = function (e, tr) {
|
2015-05-24 20:41:14 +02:00
|
|
|
"use strict";
|
2016-01-29 17:31:07 +01:00
|
|
|
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
|
|
|
});
|
2016-01-29 17:31:07 +01:00
|
|
|
return $helper;
|
2015-05-24 18:22:41 +02:00
|
|
|
};
|
|
|
|
|
2015-02-24 21:10:25 +01:00
|
|
|
$(function () {
|
2015-05-24 20:41:14 +02:00
|
|
|
"use strict";
|
2015-02-24 21:10:25 +01:00
|
|
|
$('.addMoney').on('click', addMoney);
|
|
|
|
$('.removeMoney').on('click', removeMoney);
|
|
|
|
|
2020-06-09 17:16:21 +02:00
|
|
|
$('#piggy-sortable').find('tbody').sortable(
|
2015-03-15 18:00:33 +01:00
|
|
|
{
|
2020-06-09 17:16:21 +02:00
|
|
|
helper: fixPiggyHelper,
|
2015-03-15 18:00:33 +01:00
|
|
|
stop: stopSorting,
|
2020-06-09 17:16:21 +02:00
|
|
|
connectWith: '.piggy-connected-list',
|
|
|
|
items: 'tr.piggy-sortable',
|
|
|
|
handle: '.piggy-handle',
|
2015-04-28 20:17:31 +02:00
|
|
|
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 + '"> </td>');
|
|
|
|
}
|
2015-03-15 18:00:33 +01:00
|
|
|
}
|
|
|
|
);
|
2015-02-24 21:10:25 +01:00
|
|
|
});
|
|
|
|
|
2015-05-24 18:22:41 +02:00
|
|
|
|
2015-02-24 21:10:25 +01:00
|
|
|
function addMoney(e) {
|
2015-05-24 20:41:14 +02:00
|
|
|
"use strict";
|
2015-02-24 21:10:25 +01:00
|
|
|
var pigID = parseInt($(e.target).data('id'));
|
2015-05-31 20:23:49 +02:00
|
|
|
$('#defaultModal').empty().load('piggy-banks/add/' + pigID, function () {
|
|
|
|
$('#defaultModal').modal('show');
|
2015-03-15 18:00:33 +01:00
|
|
|
});
|
2015-02-24 21:10:25 +01:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
function removeMoney(e) {
|
2015-05-24 20:41:14 +02:00
|
|
|
"use strict";
|
2015-02-24 21:10:25 +01:00
|
|
|
var pigID = parseInt($(e.target).data('id'));
|
2015-05-31 20:24:06 +02:00
|
|
|
$('#defaultModal').empty().load('piggy-banks/remove/' + pigID, function () {
|
|
|
|
$('#defaultModal').modal('show');
|
2015-03-15 18:00:33 +01:00
|
|
|
});
|
2015-02-24 21:10:25 +01:00
|
|
|
|
|
|
|
return false;
|
2015-03-15 18:00:33 +01:00
|
|
|
}
|
2017-08-12 07:47:42 +02:00
|
|
|
|
2015-03-15 18:00:33 +01:00
|
|
|
function stopSorting() {
|
2015-05-24 20:41:14 +02:00
|
|
|
"use strict";
|
2015-03-15 18:00:33 +01:00
|
|
|
$('.loadSpin').addClass('fa fa-refresh fa-spin');
|
2018-04-28 21:54:48 +02:00
|
|
|
|
2020-06-09 17:16:21 +02:00
|
|
|
$.each($('#piggy-sortable>tbody>tr.piggy-sortable'), function (i, v) {
|
2015-03-15 18:00:33 +01:00
|
|
|
var holder = $(v);
|
2020-06-09 17:16:21 +02:00
|
|
|
var parentBody = holder.parent();
|
|
|
|
var objectGroupTitle = parentBody.data('title');
|
2018-04-28 21:54:48 +02:00
|
|
|
var position = parseInt(holder.data('position'));
|
|
|
|
var originalOrder = parseInt(holder.data('order'));
|
2018-05-21 20:04:30 +02:00
|
|
|
var name = holder.data('name');
|
2015-03-15 18:00:33 +01:00
|
|
|
var id = holder.data('id');
|
2018-04-28 21:54:48 +02:00
|
|
|
var newOrder;
|
|
|
|
if (position === i) {
|
2018-05-21 20:04:30 +02:00
|
|
|
// not changed, position is what it should be.
|
2018-04-28 21:54:48 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (position < i) {
|
2018-05-21 20:04:30 +02:00
|
|
|
// position is less.
|
2020-06-20 10:10:55 +02:00
|
|
|
console.log('"' + name + '" ("' + objectGroupTitle + '") has moved down from position ' + originalOrder + ' to ' + (i + 1));
|
2018-04-28 21:54:48 +02:00
|
|
|
}
|
|
|
|
if (position > i) {
|
2020-06-09 17:16:21 +02:00
|
|
|
console.log('"' + name + '" ("' + objectGroupTitle + '") has moved up from position ' + originalOrder + ' to ' + (i + 1));
|
2018-04-28 21:54:48 +02:00
|
|
|
}
|
2018-05-21 20:04:30 +02:00
|
|
|
// update position:
|
|
|
|
holder.data('position', i);
|
|
|
|
newOrder = i+1;
|
2018-04-28 21:54:48 +02:00
|
|
|
|
2020-06-09 17:16:21 +02:00
|
|
|
$.post('piggy-banks/set-order/' + id, {order: newOrder, objectGroupTitle: objectGroupTitle, _token: token})
|
2015-03-15 18:00:33 +01:00
|
|
|
});
|
2018-04-28 21:54:48 +02:00
|
|
|
$('.loadSpin').removeClass('fa fa-refresh fa-spin');
|
|
|
|
|
2020-06-07 11:31:01 +02:00
|
|
|
}
|