- {% for p in pictures %}
-
- {% if edit_mode %}
-
- {% endif %}
- {% if user.can_view(p) %}
-
-
-
-
+
+ {% if edit_mode %}
+
+ {% endif %}
+
+
+
+
- {% endfor %}
-
-
- {{ paginate(pictures, paginator) }}
-{% if edit_mode %}
-
-{% endif %}
-
-
{% trans %}Template generation time: {% endtrans %}
-{{ timezone.now() - start }}
-
+
+
+
{% trans %}Template generation time: {% endtrans %}
+ {{ timezone.now() - start }}
+
{% endblock %}
{% block script %}
{{ super() }}
-
- var errorlist;
- if((errorlist = this.querySelector('#upload_form ul.errorlist.nonfield')) === null) {
- errorlist = document.createElement('ul');
- errorlist.classList.add('errorlist', 'nonfield');
- this.insertBefore(errorlist, this.firstElementChild);
- }
+
+ while(errorList.childElementCount > 0)
+ errorList.removeChild(errorList.firstElementChild);
+
+ let progress;
+ if((progress = this.querySelector('progress')) === null) {
+ progress = document.createElement('progress');
+ progress.value = 0;
+ let p = document.createElement('p');
+ p.appendChild(progress);
+ this.insertBefore(p, this.lastElementChild);
+ }
+
+ let dataHolder;
+
+ if(formData.get('album_name')) {
+ dataHolder = new FormData();
+ dataHolder.set('csrfmiddlewaretoken', '{{ csrf_token }}');
+ dataHolder.set('album_name', formData.get('album_name'));
+ $.ajax({
+ method: 'POST',
+ url: "{{ url('sas:album_upload', album_id=object.id) }}",
+ data: dataHolder,
+ processData: false,
+ contentType: false,
+ success: onSuccess
+ });
+ }
+
+ let images = formData.getAll('images');
+ let imagesCount = images.length;
+ let completeCount = 0;
+
+ let poolSize = 1;
+ let 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',
+ url: "{{ url('sas:album_upload', album_id=object.id) }}",
+ data: dataHolder,
+ processData: false,
+ contentType: false,
+ })
+ .fail(onSuccess.bind(undefined, image))
+ .done(onSuccess.bind(undefined, image))
+ .always(next.bind(undefined, image));
+ }
+
+ function next(image, status, jqXHR) {
+ let index;
+ if(index = imagePool.indexOf(image) !== -1) {
+ imagePool.splice(index, 1);
+ }
+ let nextImage;
+ if(nextImage = images.shift()) {
+ imagePool.push(nextImage);
+
+ sendImage(nextImage);
+ }
+ }
+
+ function onSuccess(image, data, status, jqXHR) {
+ let errors = [];
+
+ if ($(data.responseText).find('.errorlist.nonfield')[0])
+ errors = Array.from($(data.responseText).find('.errorlist.nonfield')[0].children);
+
+ while(errors.length > 0)
+ errorList.appendChild(errors.shift());
+
+ progress.value = ++completeCount / imagesCount;
+ if(progress.value === 1 && errorList.children.length === 0)
+ document.location.reload(true)
+ }
+ });
+
{% endblock %}
diff --git a/sith/settings.py b/sith/settings.py
index cd85a670..28b4e730 100644
--- a/sith/settings.py
+++ b/sith/settings.py
@@ -351,7 +351,7 @@ SITH_FORUM_PAGE_LENGTH = 30
# SAS variables
SITH_SAS_ROOT_DIR_ID = 4
-SITH_SAS_IMAGES_PER_PAGE = 30
+SITH_SAS_IMAGES_PER_PAGE = 60
SITH_BOARD_SUFFIX = "-bureau"
SITH_MEMBER_SUFFIX = "-membres"