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() {
|
||||
|
||||
@@ -116,8 +116,14 @@
|
||||
{% macro alert(type, description, title, icon) %}
|
||||
<div class="alert alert-{{ type|default('danger') }} alert-dismissible">
|
||||
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
|
||||
{% if title %}<h4><i class="icon {{ icon|icon(icon) }}"></i> {{ title|trans }}</h4>{% endif %}
|
||||
{{ description|trans }}
|
||||
{% if title and icon %}
|
||||
<h4><i class="icon {{ icon|icon(icon) }}"></i> {{ title|trans }}</h4>
|
||||
{{ description|trans }}
|
||||
{% elseif icon %}
|
||||
<h4><i class="icon {{ icon|icon(icon) }}"></i> {{ description|trans }}</h4>
|
||||
{% else %}
|
||||
{{ description|trans }}
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endmacro %}
|
||||
|
||||
|
||||
@@ -7,6 +7,9 @@
|
||||
{% block page_actions %}{{ actions.timesheet_team(timesheet, 'edit') }}{% endblock %}
|
||||
|
||||
{% block main %}
|
||||
{% if timesheet.exported %}
|
||||
{{ widgets.alert('warning', ('timesheet.locked.warning'|trans({}, 'flashmessages')), ('warning'|trans({}, 'flashmessages')), 'warning') }}
|
||||
{% endif %}
|
||||
{{ include(app.request.xmlHttpRequest ? 'default/_form_modal.html.twig' : 'default/_form.html.twig', {
|
||||
'title': (timesheet.id ? 'timesheet.edit'|trans : 'create'|trans),
|
||||
'form': form,
|
||||
|
||||
@@ -7,6 +7,9 @@
|
||||
{% block page_actions %}{{ actions.timesheet(timesheet, 'edit') }}{% endblock %}
|
||||
|
||||
{% block main %}
|
||||
{% if timesheet.exported %}
|
||||
{{ widgets.alert('warning', ('timesheet.locked.warning'|trans({}, 'flashmessages')), ('warning'|trans({}, 'flashmessages')), 'warning') }}
|
||||
{% endif %}
|
||||
{{ include(app.request.xmlHttpRequest ? 'default/_form_modal.html.twig' : 'default/_form.html.twig', {
|
||||
'title': (timesheet.id ? 'timesheet.edit'|trans : 'create'|trans),
|
||||
'form': form,
|
||||
|
||||
Reference in New Issue
Block a user