mirror of
https://github.com/pretix/pretix.git
synced 2026-05-08 15:44:02 +00:00
Improve file download UX
This commit is contained in:
@@ -25,6 +25,7 @@
|
|||||||
<script type="text/javascript" src="{% static "bootstrap/js/bootstrap.js" %}"></script>
|
<script type="text/javascript" src="{% static "bootstrap/js/bootstrap.js" %}"></script>
|
||||||
<script type="text/javascript" src="{% static "pretixpresale/js/ui/main.js" %}"></script>
|
<script type="text/javascript" src="{% static "pretixpresale/js/ui/main.js" %}"></script>
|
||||||
<script type="text/javascript" src="{% static "pretixpresale/js/ui/asynctask.js" %}"></script>
|
<script type="text/javascript" src="{% static "pretixpresale/js/ui/asynctask.js" %}"></script>
|
||||||
|
<script type="text/javascript" src="{% static "pretixpresale/js/ui/asyncdownload.js" %}"></script>
|
||||||
<script type="text/javascript" src="{% static "pretixpresale/js/ui/cart.js" %}"></script>
|
<script type="text/javascript" src="{% static "pretixpresale/js/ui/cart.js" %}"></script>
|
||||||
<script type="text/javascript" src="{% static "lightbox/js/lightbox.min.js" %}"></script>
|
<script type="text/javascript" src="{% static "lightbox/js/lightbox.min.js" %}"></script>
|
||||||
{% endcompress %}
|
{% endcompress %}
|
||||||
|
|||||||
@@ -30,7 +30,7 @@
|
|||||||
<div class="download-desktop">
|
<div class="download-desktop">
|
||||||
{% for b in download_buttons %}
|
{% for b in download_buttons %}
|
||||||
<a href="{% eventurl event "presale:event.order.download" secret=order.secret order=order.code output=b.identifier position=line.id %}"
|
<a href="{% eventurl event "presale:event.order.download" secret=order.secret order=order.code output=b.identifier position=line.id %}"
|
||||||
class="btn btn-default btn-sm">
|
class="btn btn-default btn-sm" data-asyncdownload>
|
||||||
<span class="fa fa-download"></span> {{ b.text }}
|
<span class="fa fa-download"></span> {{ b.text }}
|
||||||
</a>
|
</a>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
@@ -92,7 +92,7 @@
|
|||||||
<div class="download-mobile">
|
<div class="download-mobile">
|
||||||
{% for b in download_buttons %}
|
{% for b in download_buttons %}
|
||||||
<a href="{% eventurl event "presale:event.order.download" secret=order.secret order=order.code output=b.identifier position=line.id %}"
|
<a href="{% eventurl event "presale:event.order.download" secret=order.secret order=order.code output=b.identifier position=line.id %}"
|
||||||
class="btn btn-default btn-sm">
|
class="btn btn-default btn-sm" data-asyncdownload>
|
||||||
<span class="fa fa-download"></span> {{ b.text }}
|
<span class="fa fa-download"></span> {{ b.text }}
|
||||||
</a>
|
</a>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|||||||
@@ -532,11 +532,14 @@ class OrderDownload(EventViewMixin, OrderDetailMixin, View):
|
|||||||
except CachedTicket.DoesNotExist:
|
except CachedTicket.DoesNotExist:
|
||||||
ct = None
|
ct = None
|
||||||
|
|
||||||
|
if not ct:
|
||||||
|
ct = CachedTicket.objects.create(
|
||||||
|
order_position=self.order_position, provider=self.output.identifier,
|
||||||
|
extension='', type='', file=None)
|
||||||
|
generate.apply_async(args=(self.order_position.id, self.output.identifier))
|
||||||
|
|
||||||
if 'ajax' in request.GET:
|
if 'ajax' in request.GET:
|
||||||
return HttpResponse('1' if ct and ct.file else '0')
|
return HttpResponse('1' if ct and ct.file else '0')
|
||||||
elif not ct:
|
|
||||||
generate.apply_async(args=(self.order_position.id, self.output.identifier))
|
|
||||||
return render(request, "pretixbase/cachedfiles/pending.html", {})
|
|
||||||
elif not ct.file:
|
elif not ct.file:
|
||||||
return render(request, "pretixbase/cachedfiles/pending.html", {})
|
return render(request, "pretixbase/cachedfiles/pending.html", {})
|
||||||
else:
|
else:
|
||||||
|
|||||||
60
src/static/pretixpresale/js/ui/asyncdownload.js
Normal file
60
src/static/pretixpresale/js/ui/asyncdownload.js
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
/*global $, waitingDialog, gettext */
|
||||||
|
var async_dl_url = null;
|
||||||
|
var async_dl_timeout = null;
|
||||||
|
|
||||||
|
function async_dl_check() {
|
||||||
|
"use strict";
|
||||||
|
$.ajax(
|
||||||
|
{
|
||||||
|
'type': 'GET',
|
||||||
|
'url': async_dl_url + '?ajax=1',
|
||||||
|
'success': async_dl_check_callback,
|
||||||
|
'error': async_dl_check_error,
|
||||||
|
'context': this,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function async_dl_check_callback(data, jqXHR, status) {
|
||||||
|
"use strict";
|
||||||
|
if (data == 1) {
|
||||||
|
$("body").data('ajaxing', false);
|
||||||
|
location.href = async_dl_url;
|
||||||
|
waitingDialog.hide();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
async_dl_timeout = window.setTimeout(async_dl_check, 250);
|
||||||
|
$("#loadingmodal p").text(gettext('Your request has been queued on the server and will now be ' +
|
||||||
|
'processed. If this takes longer than two minutes, please contact us or go ' +
|
||||||
|
'back in your browser and try again.'));
|
||||||
|
}
|
||||||
|
|
||||||
|
function async_dl_check_error(jqXHR, textStatus, errorThrown) {
|
||||||
|
"use strict";
|
||||||
|
$("body").data('ajaxing', false);
|
||||||
|
waitingDialog.hide();
|
||||||
|
var c = $(jqXHR.responseText).filter('.container');
|
||||||
|
if (c.length > 0) {
|
||||||
|
ajaxErrDialog.show(c.first().html());
|
||||||
|
} else if (jqXHR.status >= 400) {
|
||||||
|
alert(gettext('An error of type {code} occured.').replace(/\{code\}/, jqXHR.status));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$(function () {
|
||||||
|
"use strict";
|
||||||
|
$("body").on('click', 'a[data-asyncdownload]', function (e) {
|
||||||
|
e.preventDefault();
|
||||||
|
if ($("body").data('ajaxing')) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
async_dl_url = $(this).attr("href");
|
||||||
|
$("body").data('ajaxing', true);
|
||||||
|
waitingDialog.show(gettext('We are processing your request …'));
|
||||||
|
$("#loadingmodal p").text(gettext('We are currently sending your request to the server. If this takes longer ' +
|
||||||
|
'than one minute, please check your internet connection and then reload ' +
|
||||||
|
'this page and try again.'));
|
||||||
|
|
||||||
|
async_dl_check();
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -33,10 +33,12 @@ function async_task_check_error(jqXHR, textStatus, errorThrown) {
|
|||||||
"use strict";
|
"use strict";
|
||||||
var c = $(jqXHR.responseText).filter('.container');
|
var c = $(jqXHR.responseText).filter('.container');
|
||||||
if (c.length > 0) {
|
if (c.length > 0) {
|
||||||
|
$("body").data('ajaxing', false);
|
||||||
waitingDialog.hide();
|
waitingDialog.hide();
|
||||||
ajaxErrDialog.show(c.first().html());
|
ajaxErrDialog.show(c.first().html());
|
||||||
} else {
|
} else {
|
||||||
if (jqXHR.status >= 400 && jqXHR.status < 500) {
|
if (jqXHR.status >= 400 && jqXHR.status < 500) {
|
||||||
|
$("body").data('ajaxing', false);
|
||||||
waitingDialog.hide();
|
waitingDialog.hide();
|
||||||
alert(gettext('An error of type {code} occured.').replace(/\{code\}/, jqXHR.status));
|
alert(gettext('An error of type {code} occured.').replace(/\{code\}/, jqXHR.status));
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user