Simple mass edit JS complete. Fallback for when the list.js is not included. #241

This commit is contained in:
James Cole 2016-04-23 06:11:31 +02:00
parent 8c8bb7a930
commit f43938726a
4 changed files with 158 additions and 13 deletions

View File

@ -1,7 +1,137 @@
/* globals $ */
/* globals $, edit_selected_txt, delete_selected_txt */
$(document).ready(function () {
"use strict";
$('.mass_edit_all').show();
$('.mass_select').click(startMassSelect);
$('.mass_stop_select').click(stopMassSelect);
});
// 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();
console.log('Journals: ' + checkedArray);
// go to specially crafted URL:
window.location.href = 'transactions/mass-edit/' + checkedArray;
return false;
}
function goToMassDelete() {
"use strict";
var checkedArray = getCheckboxes();
console.log('Journals: ' + checkedArray);
// go to specially crafted URL:
window.location.href = 'transactions/mass-delete/' + checkedArray;
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;
console.log("Now " + checked + " selected.");
if (checked > 0) {
$('.mass_edit span').text(edit_selected_txt + ' (' + checked + ')')
$('.mass_delete span').text(delete_selected_txt + ' (' + checked + ')')
$('.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:
uncheckAll();
countChecked();
// 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;
}

View File

@ -318,6 +318,7 @@ return [
'title_transfer' => 'Transfers',
'title_transfers' => 'Transfers',
// csv import:
'csv_import' => 'Import CSV file',
'csv' => 'CSV',
@ -555,7 +556,10 @@ return [
'deleted_deposit' => 'Successfully deleted deposit ":description"',
'deleted_transfer' => 'Successfully deleted transfer ":description"',
'stored_journal' => 'Successfully created new transaction ":description"',
'select_transactions' => 'Select transactions',
'stop_selection' => 'Stop selecting transactions',
'edit_selected' => 'Edit selected',
'delete_selected' => 'Delete selected',
// new user:
'welcome' => 'Welcome to Firefly!',
'createNewAsset' => 'Create a new asset account to get started. ' .

View File

@ -3,8 +3,8 @@
<table class="table table-hover table-compressed {% if sorting %}sortable-table{% endif %}">
<thead>
<tr class="ignore">
<!--<th class="hidden-xs no_select_boxes" colspan="2">&nbsp;</th>-->
<th class="hidden-xs select_boxes" colspan="2" style="display: xnone;"><input name="select_all" class=""</th>
<th class="hidden-xs no_select_boxes" colspan="2">&nbsp;</th>
<th class="hidden-xs select_boxes" colspan="2" style="display: none;"><input name="select_all" class="select_all" type="checkbox"/></th>
<th>{{ trans('list.description') }}</th>
<th>{{ trans('list.amount') }}</th>
<th class="hidden-sm hidden-xs">{{ trans('list.date') }}</th>
@ -30,7 +30,10 @@
{% for journal in journals %}
<tr class="drag" data-date="{{ journal.date.format('Y-m-d') }}" data-id="{{ journal.id }}">
<td class="hidden-xs">
<div class="btn-group btn-group-xs">
<div class="select_single" style="display:none;">
<input name="select_all_single[]" class="select_all_single" value="{{ journal.id }}" type="checkbox"/>
</div>
<div class="btn-group btn-group-xs edit_buttons">
{% if sorting %}
<a href="#" class="handle btn btn-default btn-xs"><i class="fa fa-fw fa-arrows-v"></i></a>
{% endif %}
@ -101,18 +104,19 @@
{% endfor %}
</tbody>
</table>
<div class="row">
<div class="row mass_edit_all" style="display: none;">
<div class="col-lg-6 col-md-12 col-sm-12 col-xs-12">
<div class="mass_button_options btn-group btn-group" style="display:none;">
<a href="#" class="btn btn-default mass_edit" style="display:none;"><i class="fa fa-fw fa-pencil"></i> Edit selected (5)</a>
<a href="#" class="btn btn-danger mass_delete" style="display:none;"><i class="fa fa-fw fa-trash"></i> Delete selected (6)</a>
<a href="#" class="btn btn-default mass_edit"><i class="fa fa-fw fa-pencil"></i> <span>{{ 'edit_selected'|_ }}</span></a>
<a href="#" class="btn btn-danger mass_delete"><i class="fa fa-fw fa-trash"></i> <span>{{ 'delete_selected'|_ }}</span></a>
</div>
</div>
<div class="col-lg-6 col-md-12 col-sm-12 col-xs-12">
<div class="mass_buttons btn-group btn-group pull-right">
<a href="#" class="btn btn-default mass_select"><i class="fa fa-fw fa-check-square-o"></i> Select transactions</a>
<a href="#" class="btn btn-default mass_stop_select" style="display:none;"><i class="fa faw-fw fa-square-o" aria-hidden="true"></i> Stop selecting transactions</a>
<a href="#" class="btn btn-default mass_select"><i class="fa fa-fw fa-check-square-o"></i> {{ 'select_transactions'|_ }}</a>
<a href="#" class="btn btn-default mass_stop_select" style="display:none;"><i class="fa faw-fw fa-square-o"
aria-hidden="true"></i> {{ 'stop_selection'|_ }}</a>
</div>
</div>
</div>
@ -120,4 +124,8 @@
<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
{{ journals.render|raw }}
</div>
</div>
</div>
<script type="text/javascript">
var edit_selected_txt = "{{ 'edit_selected'|_ }}";
var delete_selected_txt = "{{ 'delete_selected'|_ }}";
</script>

View File

@ -18,3 +18,6 @@
</div>
</div>
{% endblock %}
{% block scripts %}
<script type="text/javascript" src="js/ff/transactions/list.js"></script>
{% endblock %}