2016-12-23 00:02:45 -06:00
|
|
|
/*
|
|
|
|
* list.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.
|
|
|
|
*/
|
2016-04-22 23:11:31 -05:00
|
|
|
|
2017-01-02 03:34:01 -06:00
|
|
|
/** global: edit_selected_txt, delete_selected_txt */
|
|
|
|
|
2016-04-21 07:57:58 -05:00
|
|
|
$(document).ready(function () {
|
|
|
|
"use strict";
|
2016-04-22 23:11:31 -05:00
|
|
|
$('.mass_edit_all').show();
|
2016-04-21 07:57:58 -05:00
|
|
|
$('.mass_select').click(startMassSelect);
|
|
|
|
$('.mass_stop_select').click(stopMassSelect);
|
2016-04-22 23:11:31 -05:00
|
|
|
|
|
|
|
// top button to select all / deselect all:
|
|
|
|
$('input[name="select_all"]').change(function () {
|
|
|
|
if (this.checked) {
|
|
|
|
checkAll();
|
|
|
|
countChecked();
|
|
|
|
} else {
|
|
|
|
uncheckAll();
|
|
|
|
countChecked();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
$('.select_all_single').change(function () {
|
|
|
|
countChecked();
|
|
|
|
});
|
|
|
|
|
|
|
|
// click the edit button:
|
|
|
|
$('.mass_edit').click(goToMassEdit);
|
|
|
|
// click the delete button:
|
|
|
|
$('.mass_delete').click(goToMassDelete);
|
|
|
|
});
|
|
|
|
|
|
|
|
function goToMassEdit() {
|
|
|
|
"use strict";
|
|
|
|
var checkedArray = getCheckboxes();
|
|
|
|
|
|
|
|
// go to specially crafted URL:
|
2017-06-28 08:52:13 -05: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-22 23:11:31 -05:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
function goToMassDelete() {
|
|
|
|
"use strict";
|
|
|
|
var checkedArray = getCheckboxes();
|
|
|
|
|
|
|
|
// go to specially crafted URL:
|
2017-06-28 08:52:13 -05: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-22 23:11:31 -05:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function countChecked() {
|
|
|
|
"use strict";
|
|
|
|
var checked = $('.select_all_single:checked').length;
|
|
|
|
if (checked > 0) {
|
2017-04-09 00:56:46 -05:00
|
|
|
$('.mass_edit span').text(edit_selected_txt + ' (' + checked + ')');
|
|
|
|
$('.mass_delete span').text(delete_selected_txt + ' (' + checked + ')');
|
2016-04-22 23:11:31 -05:00
|
|
|
$('.mass_button_options').show();
|
|
|
|
|
|
|
|
} else {
|
|
|
|
$('.mass_button_options').hide();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function checkAll() {
|
|
|
|
"use strict";
|
|
|
|
$('.select_all_single').prop('checked', true);
|
|
|
|
}
|
|
|
|
function uncheckAll() {
|
|
|
|
"use strict";
|
|
|
|
$('.select_all_single').prop('checked', false);
|
|
|
|
}
|
|
|
|
|
|
|
|
function stopMassSelect() {
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
// uncheck all:
|
2016-04-23 02:33:54 -05:00
|
|
|
$('input[name="select_all"]').prop('checked', false);
|
2016-04-22 23:11:31 -05:00
|
|
|
uncheckAll();
|
|
|
|
countChecked();
|
|
|
|
|
2016-04-23 02:33:54 -05:00
|
|
|
|
2016-04-22 23:11:31 -05: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();
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|