lock exported timesheets (#798)
This commit is contained in:
@@ -119,42 +119,56 @@
|
||||
{{ parent() }}
|
||||
<script type="text/javascript">
|
||||
|
||||
function confirmToggleState()
|
||||
function confirmToggleState(button)
|
||||
{
|
||||
if ($('#export-toggle-button').hasClass('export-off')) {
|
||||
if (confirm('{{ 'export.clear_all'|trans }}')) {
|
||||
$('.exportBtn').each(function () {
|
||||
if ($(this).hasClass('active')) {
|
||||
$(this).click();
|
||||
}
|
||||
});
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
if (confirm('{{ 'export.mark_all'|trans }}')) {
|
||||
$('.exportBtn').each(function () {
|
||||
if (!$(this).hasClass('active')) {
|
||||
$(this).click();
|
||||
}
|
||||
});
|
||||
return true;
|
||||
}
|
||||
var ALERT = kimai.getPlugin('alert');
|
||||
var message = '{{ 'export.clear_all'|trans }}';
|
||||
var hasActive = true;
|
||||
|
||||
if (!$('#export-toggle-button').hasClass('export-off')) {
|
||||
message = '{{ 'export.mark_all'|trans }}';
|
||||
hasActive = false;
|
||||
}
|
||||
return false;
|
||||
|
||||
ALERT.question(message, function(value) {
|
||||
var btn = $(button);
|
||||
var exportButtons = $('.exportBtn');
|
||||
// disabling does not yet work...
|
||||
if (exportButtons.length > 0) {
|
||||
btn.addClass('disabled');
|
||||
}
|
||||
|
||||
// ... as the clicks are asynchronous and the each comes back too early ...
|
||||
exportButtons.each(function () {
|
||||
if (hasActive === $(this).hasClass('active')) {
|
||||
$(this).click();
|
||||
}
|
||||
});
|
||||
|
||||
// ... so the button is re-enabled immediately - that should be fixed in a future update
|
||||
btn.removeClass('disabled');
|
||||
if (btn.hasClass('export-off')) {
|
||||
btn.removeClass('export-off');
|
||||
btn.html('<i class="fas fa-toggle-off"></i>');
|
||||
} else {
|
||||
btn.addClass('export-off');
|
||||
btn.html('<i class="fas fa-toggle-on"></i>');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function updateTimesheetExportState(button, id, exported)
|
||||
{
|
||||
// FIXME use kimai API and ALERT
|
||||
var ALERT = kimai.getPlugin('alert');
|
||||
|
||||
// FIXME use Kimai API plugin
|
||||
$.ajax({
|
||||
url: '{{ path('patch_timesheet', {id: '-s-'}) }}'.replace('-s-', id),
|
||||
url: '{{ path('export_timesheet', {id: '-s-'}) }}'.replace('-s-', id),
|
||||
headers: {
|
||||
'X-AUTH-SESSION': true,
|
||||
'Content-Type':'application/json'
|
||||
},
|
||||
method: 'PATCH',
|
||||
dataType: 'json',
|
||||
data: JSON.stringify({'exported': exported}),
|
||||
success: function(data) {
|
||||
if (exported) {
|
||||
button.button('exported');
|
||||
@@ -181,13 +195,12 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
alert('{{ 'action.update.error'|trans({}, 'flashmessages') }}'.replace('%reason%', message));
|
||||
ALERT.error('{{ 'action.update.error'|trans({}, 'flashmessages') }}', message);
|
||||
button.button('reset');
|
||||
if (exported) {
|
||||
button.removeClass('active');
|
||||
} else {
|
||||
button.addClass('active');
|
||||
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -197,25 +210,11 @@
|
||||
$('body').on('click', '.exportBtn', function() {
|
||||
var button = $(this);
|
||||
var id = button.attr('data-timesheet');
|
||||
|
||||
if (button.hasClass('active')) {
|
||||
updateTimesheetExportState(button, id, false);
|
||||
} else {
|
||||
updateTimesheetExportState(button, id, true);
|
||||
}
|
||||
updateTimesheetExportState(button, id, !button.hasClass('active'));
|
||||
});
|
||||
|
||||
$('#export-toggle-button').on('click', function () {
|
||||
if (!confirmToggleState()) {
|
||||
return;
|
||||
}
|
||||
if ($(this).hasClass('export-off')) {
|
||||
$(this).removeClass('export-off');
|
||||
$(this).html('<i class="fas fa-toggle-off"></i>');
|
||||
} else {
|
||||
$(this).addClass('export-off');
|
||||
$(this).html('<i class="fas fa-toggle-on"></i>');
|
||||
}
|
||||
confirmToggleState(this);
|
||||
});
|
||||
|
||||
$('body').on('click', '#export-buttons .startExportBtn', function() {
|
||||
|
||||
Reference in New Issue
Block a user