2016-12-23 07:02:45 +01:00
|
|
|
/*
|
|
|
|
* list.js
|
2017-10-21 08:40:00 +02:00
|
|
|
* Copyright (c) 2017 thegrumpydictator@gmail.com
|
2016-12-23 07:02:45 +01:00
|
|
|
*
|
2017-10-21 08:40:00 +02:00
|
|
|
* This file is part of Firefly III.
|
2016-12-23 07:02:45 +01:00
|
|
|
*
|
2017-10-21 08:40:00 +02:00
|
|
|
* Firefly III is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* Firefly III is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2017-12-17 14:43:13 +01:00
|
|
|
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
|
2016-12-23 07:02:45 +01:00
|
|
|
*/
|
2016-04-23 06:11:31 +02:00
|
|
|
|
2017-12-30 11:49:42 +01:00
|
|
|
/** global: edit_selected_txt, edit_bulk_selected_txt, delete_selected_txt, token */
|
2017-01-02 10:34:01 +01:00
|
|
|
|
2017-11-05 19:48:43 +01:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
2016-04-21 14:57:58 +02:00
|
|
|
$(document).ready(function () {
|
|
|
|
"use strict";
|
2016-04-23 06:11:31 +02:00
|
|
|
$('.mass_edit_all').show();
|
2016-04-21 14:57:58 +02:00
|
|
|
$('.mass_select').click(startMassSelect);
|
|
|
|
$('.mass_stop_select').click(stopMassSelect);
|
2016-04-23 06:11:31 +02:00
|
|
|
|
|
|
|
// top button to select all / deselect all:
|
|
|
|
$('input[name="select_all"]').change(function () {
|
|
|
|
if (this.checked) {
|
|
|
|
checkAll();
|
|
|
|
countChecked();
|
|
|
|
} else {
|
|
|
|
uncheckAll();
|
|
|
|
countChecked();
|
|
|
|
}
|
|
|
|
});
|
2017-10-26 19:57:41 +02:00
|
|
|
$('.select_all_single').unbind('change').change(function () {
|
2016-04-23 06:11:31 +02:00
|
|
|
countChecked();
|
|
|
|
});
|
|
|
|
|
|
|
|
// click the edit button:
|
|
|
|
$('.mass_edit').click(goToMassEdit);
|
2017-12-30 09:21:28 +01:00
|
|
|
// click the edit button:
|
|
|
|
$('.mass_edit_bulk').click(goToMassBulkEdit);
|
2016-04-23 06:11:31 +02:00
|
|
|
// click the delete button:
|
|
|
|
$('.mass_delete').click(goToMassDelete);
|
2017-11-05 19:48:43 +01:00
|
|
|
// click reconcile button
|
2017-11-10 15:00:24 +01:00
|
|
|
// $('.mass_reconcile').click(goToReconcile);
|
2016-04-23 06:11:31 +02:00
|
|
|
});
|
|
|
|
|
2017-11-05 19:48:43 +01:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @returns {boolean}
|
|
|
|
*/
|
|
|
|
function goToReconcile() {
|
|
|
|
|
|
|
|
var checked = $('.select_all_single:checked');
|
|
|
|
var ids = [];
|
|
|
|
$.each(checked, function (i, v) {
|
|
|
|
ids.push(parseInt($(v).data('transaction')));
|
|
|
|
});
|
|
|
|
|
|
|
|
// go to specially crafted URL:
|
|
|
|
var bases = document.getElementsByTagName('base');
|
|
|
|
var baseHref = null;
|
|
|
|
|
|
|
|
if (bases.length > 0) {
|
|
|
|
baseHref = bases[0].href;
|
|
|
|
}
|
|
|
|
|
2017-12-20 20:07:57 +01:00
|
|
|
$.post(baseHref + 'transactions/reconcile', {transactions: ids, _token: token}).done(function () {
|
2017-11-08 09:40:38 +01:00
|
|
|
window.location.reload(true);
|
2017-11-05 19:48:43 +01:00
|
|
|
}).fail(function () {
|
|
|
|
alert('Could not reconcile transactions: please check the logs and try again later.');
|
|
|
|
});
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @returns {boolean}
|
|
|
|
*/
|
2016-04-23 06:11:31 +02:00
|
|
|
function goToMassEdit() {
|
|
|
|
"use strict";
|
|
|
|
var checkedArray = getCheckboxes();
|
|
|
|
|
|
|
|
// go to specially crafted URL:
|
2017-06-28 15:52:13 +02:00
|
|
|
var bases = document.getElementsByTagName('base');
|
|
|
|
var baseHref = null;
|
|
|
|
|
|
|
|
if (bases.length > 0) {
|
|
|
|
baseHref = bases[0].href;
|
|
|
|
}
|
|
|
|
|
|
|
|
window.location.href = baseHref + '/transactions/mass/edit/' + checkedArray;
|
2016-04-23 06:11:31 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-12-30 09:21:28 +01:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @returns {boolean}
|
|
|
|
*/
|
|
|
|
function goToMassBulkEdit() {
|
|
|
|
"use strict";
|
|
|
|
var checkedArray = getCheckboxes();
|
|
|
|
|
|
|
|
// go to specially crafted URL:
|
|
|
|
var bases = document.getElementsByTagName('base');
|
|
|
|
var baseHref = null;
|
|
|
|
|
|
|
|
if (bases.length > 0) {
|
|
|
|
baseHref = bases[0].href;
|
|
|
|
}
|
|
|
|
|
|
|
|
window.location.href = baseHref + '/transactions/mass/edit/bulk/' + checkedArray;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-11-05 19:48:43 +01:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @returns {boolean}
|
|
|
|
*/
|
2016-04-23 06:11:31 +02:00
|
|
|
function goToMassDelete() {
|
|
|
|
"use strict";
|
|
|
|
var checkedArray = getCheckboxes();
|
|
|
|
|
|
|
|
// go to specially crafted URL:
|
2017-06-28 15:52:13 +02:00
|
|
|
var bases = document.getElementsByTagName('base');
|
|
|
|
var baseHref = null;
|
|
|
|
|
|
|
|
if (bases.length > 0) {
|
|
|
|
baseHref = bases[0].href;
|
|
|
|
}
|
|
|
|
window.location.href = baseHref + '/transactions/mass/delete/' + checkedArray;
|
2016-04-23 06:11:31 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-11-05 19:48:43 +01:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @returns {Array}
|
|
|
|
*/
|
2016-04-23 06:11:31 +02:00
|
|
|
function getCheckboxes() {
|
|
|
|
"use strict";
|
|
|
|
var list = [];
|
|
|
|
$.each($('.select_all_single'), function (i, v) {
|
|
|
|
var checkbox = $(v);
|
|
|
|
if (checkbox.prop('checked')) {
|
|
|
|
// add to list.
|
|
|
|
list.push(checkbox.val());
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
2017-11-05 19:48:43 +01:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
2016-04-23 06:11:31 +02:00
|
|
|
function countChecked() {
|
|
|
|
"use strict";
|
|
|
|
var checked = $('.select_all_single:checked').length;
|
|
|
|
if (checked > 0) {
|
2017-04-09 07:56:46 +02:00
|
|
|
$('.mass_edit span').text(edit_selected_txt + ' (' + checked + ')');
|
2017-12-30 09:21:28 +01:00
|
|
|
$('.mass_edit_bulk span').text(edit_bulk_selected_txt + ' (' + checked + ')');
|
2017-04-09 07:56:46 +02:00
|
|
|
$('.mass_delete span').text(delete_selected_txt + ' (' + checked + ')');
|
2017-11-05 19:48:43 +01:00
|
|
|
|
|
|
|
// get amount for the transactions:
|
2017-11-18 05:45:58 +01:00
|
|
|
//getAmounts();
|
2017-11-05 19:48:43 +01:00
|
|
|
|
2016-04-23 06:11:31 +02:00
|
|
|
$('.mass_button_options').show();
|
|
|
|
|
|
|
|
} else {
|
|
|
|
$('.mass_button_options').hide();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-05 19:48:43 +01:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
2016-04-23 06:11:31 +02:00
|
|
|
function checkAll() {
|
|
|
|
"use strict";
|
|
|
|
$('.select_all_single').prop('checked', true);
|
|
|
|
}
|
2017-08-12 07:47:42 +02:00
|
|
|
|
2017-11-05 19:48:43 +01:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
2016-04-23 06:11:31 +02:00
|
|
|
function uncheckAll() {
|
|
|
|
"use strict";
|
|
|
|
$('.select_all_single').prop('checked', false);
|
|
|
|
}
|
|
|
|
|
2017-11-05 19:48:43 +01:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @returns {boolean}
|
|
|
|
*/
|
2016-04-23 06:11:31 +02:00
|
|
|
function stopMassSelect() {
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
// uncheck all:
|
2016-04-23 09:33:54 +02:00
|
|
|
$('input[name="select_all"]').prop('checked', false);
|
2016-04-23 06:11:31 +02:00
|
|
|
uncheckAll();
|
|
|
|
countChecked();
|
|
|
|
|
2016-04-23 09:33:54 +02:00
|
|
|
|
2016-04-23 06:11:31 +02:00
|
|
|
// hide "select all" box in table header.
|
|
|
|
$('.select_boxes').hide();
|
|
|
|
|
|
|
|
// show the other header cell.
|
|
|
|
$('.no_select_boxes').show();
|
|
|
|
|
|
|
|
// show edit/delete buttons
|
|
|
|
$('.edit_buttons').show();
|
|
|
|
|
|
|
|
// hide the checkbox.
|
|
|
|
$('.select_single').hide();
|
|
|
|
|
|
|
|
// show the start button
|
|
|
|
$('.mass_select').show();
|
|
|
|
|
|
|
|
// hide the stop button
|
|
|
|
$('.mass_stop_select').hide();
|
|
|
|
|
2017-11-10 15:00:24 +01:00
|
|
|
// show reconcile account button, if present
|
|
|
|
$('.mass_reconcile').show();
|
|
|
|
|
2016-04-23 06:11:31 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-11-05 19:48:43 +01:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @returns {boolean}
|
|
|
|
*/
|
2016-04-23 06:11:31 +02:00
|
|
|
function startMassSelect() {
|
|
|
|
"use strict";
|
|
|
|
// show "select all" box in table header.
|
|
|
|
$('.select_boxes').show();
|
|
|
|
|
|
|
|
// hide the other header cell.
|
|
|
|
$('.no_select_boxes').hide();
|
|
|
|
|
|
|
|
// hide edit/delete buttons
|
|
|
|
$('.edit_buttons').hide();
|
|
|
|
|
|
|
|
// show the checkbox.
|
|
|
|
$('.select_single').show();
|
|
|
|
|
|
|
|
// hide the start button
|
|
|
|
$('.mass_select').hide();
|
|
|
|
|
|
|
|
// show the stop button
|
|
|
|
$('.mass_stop_select').show();
|
|
|
|
|
2017-11-10 15:00:24 +01:00
|
|
|
// hide reconcile account button, if present
|
|
|
|
$('.mass_reconcile').hide();
|
|
|
|
|
2016-04-23 06:11:31 +02:00
|
|
|
return false;
|
|
|
|
}
|