Some housekeeping
[redakcja.git] / src / fileupload / templatetags / upload_tags.py
1 # This file is part of FNP-Redakcja, licensed under GNU Affero GPLv3 or later.
2 # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
3 #
4 from django import template
5 from django.utils.safestring import mark_safe
6
7 register = template.Library()
8
9 @register.simple_tag
10 def upload_js():
11     return mark_safe("""
12 <!-- The template to display files available for upload -->
13 <script id="template-upload" type="text/x-tmpl">
14 {% for (var i=0, file; file=o.files[i]; i++) { %}
15     <tr class="template-upload fade">
16         <td class="preview"><span class="fade"></span></td>
17         <td class="name"><span>{%=file.name%}</span></td>
18         <td class="size"><span>{%=o.formatFileSize(file.size)%}</span></td>
19         {% if (file.error) { %}
20             <td class="error" colspan="2"><span class="label label-important">{%=locale.fileupload.error%}</span> {%=locale.fileupload.errors[file.error] || file.error%}</td>
21         {% } else if (o.files.valid && !i) { %}
22             <td>
23                 <div class="progress progress-success progress-striped active"><div class="bar" style="width:0%;"></div></div>
24             </td>
25             <td class="start">{% if (!o.options.autoUpload) { %}
26                 <button class="btn btn-success">
27                     <i class="icon-upload icon-white"></i>
28                     <span>{%=locale.fileupload.start%}</span>
29                 </button>
30             {% } %}</td>
31         {% } else { %}
32             <td colspan="2"></td>
33         {% } %}
34         <td class="cancel">{% if (!i) { %}
35             <button class="btn btn-warning">
36                 <i class="icon-ban-circle icon-white"></i>
37                 <span>{%=locale.fileupload.cancel%}</span>
38             </button>
39         {% } %}</td>
40     </tr>
41 {% } %}
42 </script>
43 <!-- The template to display files available for download -->
44 <script id="template-download" type="text/x-tmpl">
45 {% for (var i=0, file; file=o.files[i]; i++) { %}
46     <tr class="template-download fade">
47         {% if (file.error) { %}
48             <td></td>
49             <td class="name"><span>{%=file.name%}</span></td>
50             <td class="size"><span>{%=o.formatFileSize(file.size)%}</span></td>
51             <td class="error" colspan="2"><span class="label label-important">{%=locale.fileupload.error%}</span> {%=locale.fileupload.errors[file.error] || file.error%}</td>
52         {% } else { %}
53             <td class="preview">{% if (file.thumbnail_url) { %}
54                 <a href="{%=file.url%}" title="{%=file.name%}" rel="gallery" download="{%=file.name%}"><img src="{%=file.thumbnail_url%}"></a>
55             {% } %}</td>
56             <td class="name">
57                 <a href="{%=file.url%}" title="{%=file.name%}" rel="{%=file.thumbnail_url&&'gallery'%}" download="{%=file.name%}">{%=file.name%}</a>
58             </td>
59             <td class="size"><span>{%=o.formatFileSize(file.size)%}</span></td>
60             <td colspan="2"></td>
61         {% } %}
62         <td class="delete">
63             <button class="btn btn-danger" data-type="{%=file.delete_type%}" data-url="{%=file.delete_url%}">
64                 <i class="icon-trash icon-white"></i>
65                 <span>{%=locale.fileupload.destroy%}</span>
66             </button>
67             <input type="checkbox" name="delete" value="1">
68         </td>
69     </tr>
70 {% } %}
71 </script>
72 """)