Sith/sas/templates/sas/album.jinja

203 lines
6.4 KiB
Django/Jinja
Raw Normal View History

2016-10-26 17:21:19 +00:00
{% extends "core/base.jinja" %}
2019-09-15 23:26:20 +00:00
{% from "core/macros.jinja" import paginate %}
2016-10-26 17:21:19 +00:00
{% block title %}
{% trans %}SAS{% endtrans %}
{% endblock %}
2016-11-20 09:40:49 +00:00
{% macro print_path(file) %}
2016-11-20 13:08:10 +00:00
{% if file and file.parent %}
2016-11-20 09:40:49 +00:00
{{ print_path(file.parent) }}
<a href="{{ url('sas:album', album_id=file.id) }}">{{ file.get_display_name() }}</a> >
{% endif %}
{% endmacro %}
2016-10-26 17:21:19 +00:00
{% block content %}
2016-11-20 13:08:10 +00:00
<a href="{{ url('sas:main') }}">SAS</a> > {{ print_path(album.parent) }} {{ album.get_display_name() }}
2016-11-08 14:12:37 +00:00
<h3>{{ album.get_display_name() }}</h3>
2016-11-25 12:47:09 +00:00
<a href="{{ url('sas:album_edit', album_id=album.id) }}">{% trans %}Edit{% endtrans %}</a><br>
{% set start = timezone.now() %}
2016-11-20 22:53:41 +00:00
<hr>
2016-12-18 10:55:45 +00:00
{% set edit_mode = user.can_edit(album) %}
{% if edit_mode %}
2016-12-13 16:17:58 +00:00
<form action="" method="post" enctype="multipart/form-data" style="width: 100%;">
{% csrf_token %}
<p>
<input name="delete" type="submit" value="{% trans %}Delete{% endtrans %}"> |
<input name="clear" type="submit" value="{% trans %}Clear clipboard{% endtrans %}"> |
<input name="cut" type="submit" value="{% trans %}Cut{% endtrans %}"> |
<input name="paste" type="submit" value="{% trans %}Paste{% endtrans %}">
</p>
{% if clipboard %}
<p>{% trans %}Clipboard: {% endtrans %}
<ul>
{% for f in clipboard %}
<li>{{ f.get_full_path() }}</li>
{% endfor %}
</ul>
</p>
{% endif %}
{% endif %}
<div>
2017-02-21 13:29:58 +00:00
{% for a in album.children_albums.order_by('-date') %}
2016-12-13 16:17:58 +00:00
<div style="display: inline-block;">
2016-12-18 10:55:45 +00:00
{% if edit_mode %}
2016-12-13 16:17:58 +00:00
<input type="checkbox" name="file_list" value="{{ a.id }}">
2016-11-20 22:53:41 +00:00
{% endif %}
{% if user.can_view(a) %}
2016-12-13 16:17:58 +00:00
<a href="{{ url("sas:album", album_id=a.id) }}" style="display: inline-block">
<div class="album{% if not a.is_moderated %} not_moderated{% endif %}">
<div>
{% if a.file %}
<img src="{{ a.get_download_url() }}" alt="{% trans %}preview{% endtrans %}">
2016-12-13 16:17:58 +00:00
{% else %}
<img src="{{ static('core/img/sas.jpg') }}" alt="{% trans %}preview{% endtrans %}">
{% endif %}
</div>
{{ a.name }}
2016-11-20 22:53:41 +00:00
</div>
2016-10-26 17:21:19 +00:00
</a>
2016-12-13 16:17:58 +00:00
{% endif %}
</div>
{% endfor %}
2016-10-26 17:21:19 +00:00
</div>
2016-12-13 16:17:58 +00:00
<div>
2019-09-15 23:26:20 +00:00
{% for p in pictures %}
2016-12-13 16:17:58 +00:00
<div style="display: inline-block;">
2016-12-18 10:55:45 +00:00
{% if edit_mode %}
2016-12-13 16:17:58 +00:00
<input type="checkbox" name="file_list" value="{{ p.id }}">
{% endif %}
{% if user.can_view(p) %}
2016-12-13 16:17:58 +00:00
<div class="picture{% if not p.is_moderated %} not_moderated{% endif %}">
<a href="{{ url("sas:picture", picture_id=p.id) }}#pict">
<img src="{{ p.get_download_thumb_url() }}" alt="{{ p.get_display_name() }}" />
2016-12-13 16:17:58 +00:00
</a>
</div>
{% endif %}
</div>
{% endfor %}
</div>
2019-09-15 23:26:20 +00:00
<br>
{{ paginate(pictures, paginator) }}
2016-12-18 10:55:45 +00:00
{% if edit_mode %}
2016-12-13 16:17:58 +00:00
</form>
{% endif %}
2017-01-05 09:05:13 +00:00
<form id="upload_form" action="" method="post" enctype="multipart/form-data">
{% csrf_token %}
{{ form.as_p() }}
<p><input type="submit" value="{% trans %}Upload{% endtrans %}" /></p>
</form>
<p style="font-size: small; color: #444;">{% trans %}Template generation time: {% endtrans %}
{{ timezone.now() - start }}
</p>
2016-10-26 17:21:19 +00:00
{% endblock %}
2016-11-20 23:35:07 +00:00
{% block script %}
{{ super() }}
2016-11-22 15:58:55 +00:00
<script>
2017-01-05 09:05:13 +00:00
$("form#upload_form").submit(function (event) {
2016-11-22 15:58:55 +00:00
var formData = new FormData($(this)[0]);
2017-01-05 09:05:13 +00:00
if(!formData.get('album_name') && !formData.get('images').name)
2016-11-22 15:58:55 +00:00
return false;
2017-01-05 09:05:13 +00:00
if(!formData.get('images').name) {
2016-11-22 15:58:55 +00:00
return true;
}
event.preventDefault();
var errorlist;
2017-01-05 09:05:13 +00:00
if((errorlist = this.querySelector('#upload_form ul.errorlist.nonfield')) === null) {
2016-11-22 15:58:55 +00:00
errorlist = document.createElement('ul');
errorlist.classList.add('errorlist', 'nonfield');
this.insertBefore(errorlist, this.firstElementChild);
}
2016-11-22 17:10:24 +00:00
while(errorlist.childElementCount > 0)
2016-11-22 15:58:55 +00:00
errorlist.removeChild(errorlist.firstElementChild);
var progress;
if((progress = this.querySelector('progress')) === null) {
progress = document.createElement('progress');
progress.value = 0;
var p = document.createElement('p');
p.appendChild(progress);
this.insertBefore(p, this.lastElementChild);
}
var dataHolder;
2017-01-05 09:05:13 +00:00
if(formData.get('album_name')) {
2016-11-22 15:58:55 +00:00
dataHolder = new FormData();
dataHolder.set('csrfmiddlewaretoken', '{{ csrf_token }}');
dataHolder.set('album_name', formData.get('album_name'));
$.ajax({
method: 'POST',
2017-01-05 09:05:13 +00:00
url: "{{ url('sas:album_upload', album_id=object.id) }}",
2016-11-22 15:58:55 +00:00
data: dataHolder,
processData: false,
contentType: false,
success: onSuccess
2016-11-22 17:10:24 +00:00
});
2016-11-22 15:58:55 +00:00
}
var images = formData.getAll('images');
var imagesCount = images.length;
var completeCount = 0;
2017-01-09 12:05:24 +00:00
var poolSize = 1;
2016-11-22 15:58:55 +00:00
var imagePool = [];
while(images.length > 0 && imagePool.length < poolSize) {
var image = images.shift();
imagePool.push(image);
sendImage(image);
}
function sendImage(image) {
dataHolder = new FormData();
dataHolder.set('csrfmiddlewaretoken', '{{ csrf_token }}');
dataHolder.set('images', image);
$.ajax({
method: 'POST',
2017-01-05 09:05:13 +00:00
url: "{{ url('sas:album_upload', album_id=object.id) }}",
2016-11-22 15:58:55 +00:00
data: dataHolder,
processData: false,
contentType: false,
})
2017-01-05 09:05:13 +00:00
.fail(onSuccess.bind(undefined, image))
2016-11-22 15:58:55 +00:00
.done(onSuccess.bind(undefined, image))
.always(next.bind(undefined, image));
}
function next(image, status, jqXHR) {
var index;
if(index = imagePool.indexOf(image) !== -1) {
imagePool.splice(index, 1);
}
var nextImage;
if(nextImage = images.shift()) {
imagePool.push(nextImage);
sendImage(nextImage);
}
}
function onSuccess(image, data, status, jqXHR) {
2017-01-05 09:05:13 +00:00
if ($(data.responseText).find('.errorlist.nonfield')[0])
var errors = Array.from($(data.responseText).find('.errorlist.nonfield')[0].children);
2016-11-22 17:10:24 +00:00
else
var errors = []
2016-11-22 15:58:55 +00:00
while(errors.length > 0)
errorlist.appendChild(errors.shift());
progress.value = ++completeCount / imagesCount;
if(progress.value === 1 && errorlist.children.length === 0)
2016-12-08 14:16:42 +00:00
document.location.reload(true)
2016-11-22 15:58:55 +00:00
}
});
</script>
2016-11-20 23:35:07 +00:00
{% endblock %}